Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions admin/cedar/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.forms import ModelForm, CharField, JSONField
from django.forms import ModelForm, CharField, JSONField, BooleanField

from osf.models import CedarMetadataTemplate


class CedarMetadataTemplateForm(ModelForm):
schema_name = CharField(
disabled=True,
Expand All @@ -18,7 +19,8 @@ class CedarMetadataTemplateForm(ModelForm):
template = JSONField(
disabled=True
)
is_for_collections = BooleanField(label='For collections only:', required=False)

class Meta:
model = CedarMetadataTemplate
fields = ['schema_name', 'cedar_id', 'template_version', 'template', 'active', 'should_index_for_search']
fields = ['schema_name', 'cedar_id', 'template_version', 'template', 'is_for_collections', 'active', 'should_index_for_search']
4 changes: 4 additions & 0 deletions admin/templates/cedar/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ <h2>List of Cedar Metadata Templates</h2>
<th>Name</th>
<th>Version</th>
<th>Active</th>
<th>For Collections only</th>
</tr>
</thead>
<tbody>
Expand All @@ -33,6 +34,9 @@ <h2>List of Cedar Metadata Templates</h2>
<td>
{{ template.active }}
</td>
<td>
{{ template.is_for_collections }}
</td>
</tr>
{% endfor %}
</tbody>
Expand Down
3 changes: 2 additions & 1 deletion api/cedar_metadata_templates/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ class CedarMetadataTemplateSerializer(JSONAPISerializer):
class Meta:
type_ = 'cedar-metadata-templates'

filterable_fields = frozenset(['schema_name', 'cedar_id', 'active'])
filterable_fields = frozenset(['schema_name', 'cedar_id', 'active', 'is_for_collections'])

id = ser.CharField(source='_id', read_only=True)
schema_name = ser.CharField(read_only=True)
cedar_id = ser.CharField(read_only=True)
template = ser.DictField(read_only=True)
active = ser.BooleanField(read_only=True)
template_version = ser.IntegerField(read_only=True)
is_for_collections = ser.BooleanField(read_only=True)

links = LinksField({'self': 'get_absolute_url'})

Expand Down
15 changes: 13 additions & 2 deletions api_tests/cedar_metadata_templates/views/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,19 @@ def active_template_alt(self):
)

@pytest.fixture()
def active_template_ids(self, active_template, active_template_alt):
return [active_template._id, active_template_alt._id]
def active_template_for_collections(self):
return CedarMetadataTemplate.objects.create(
schema_name=fake.bs(),
cedar_id=fake.md5(),
template_version=1,
template={},
active=True,
is_for_collections=True
)

@pytest.fixture()
def active_template_ids(self, active_template, active_template_alt, active_template_for_collections):
return [active_template._id, active_template_alt._id, active_template_for_collections._id]

@pytest.fixture()
def inactive_template(self):
Expand Down
16 changes: 15 additions & 1 deletion api_tests/cedar_metadata_templates/views/test_template_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,19 @@ def test_template_list(self, app, active_template_ids):
resp = app.get('/_/cedar_metadata_templates/')
assert resp.status_code == 200
data = resp.json['data']
assert len(data) == 2
assert len(data) == 3
assert set(active_template_ids) == {datum['id'] for datum in data}

def test_filter_templates_for_collections_only(self, app, active_template_for_collections, active_template_ids):
resp = app.get('/_/cedar_metadata_templates/?filter[is_for_collections]=true')
assert resp.status_code == 200
data = resp.json['data']
assert len(data) == 1
assert data[0]['id'] == active_template_for_collections._id

resp = app.get('/_/cedar_metadata_templates/?filter[is_for_collections]=false')
assert resp.status_code == 200
data = resp.json['data']
assert len(data) == 2
for template in data:
assert template['id'] != active_template_for_collections._id
18 changes: 18 additions & 0 deletions osf/migrations/0042_cedarmetadatatemplate_is_for_collections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.26 on 2026-05-28 07:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('osf', '0041_cedarmetadatatemplate_should_index_for_search'),
]

operations = [
migrations.AddField(
model_name='cedarmetadatatemplate',
name='is_for_collections',
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions osf/models/cedar_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CedarMetadataTemplate(ObjectIDMixin, BaseModel):
active = models.BooleanField(default=True)
template_version = models.PositiveIntegerField()
should_index_for_search = models.BooleanField(default=False)
is_for_collections = models.BooleanField(default=False)

class Meta:
unique_together = ('cedar_id', 'template_version')
Expand Down