Skip to content

Commit

Permalink
CU-8693xmupv: setting to not create associated projects from a new pr…
Browse files Browse the repository at this point in the history
…oject group or edit them
  • Loading branch information
tomolopolis committed May 14, 2024
1 parent 8dc553a commit 4824a41
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
38 changes: 20 additions & 18 deletions webapp/api/api/admin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def formfield_for_manytomany(self, db_field, request, **kwargs):
class ProjectGroupAdmin(admin.ModelAdmin):
model = ProjectGroup
list_display = ('name', 'description')
fields = (('name', 'description', 'annotation_guideline_link', 'administrators', 'annotators', 'dataset') +
fields = (('name', 'description', 'create_associated_projects', 'annotation_guideline_link', 'administrators',
'annotators', 'dataset') +
_PROJECT_FIELDS_ORDER + _PROJECT_ANNO_ENTS_SETTINGS_FIELD_ORDER)

class Meta:
Expand Down Expand Up @@ -120,24 +121,25 @@ def save_model(self, request, obj, form, change):
tasks = [get_object_or_404(MetaTask, pk=id) for id in request.POST.getlist('tasks')]
relations = [get_object_or_404(Relation, pk=id) for id in request.POST.getlist('relations')]

# create the underlying ProjectAnnotateEntities models
if not change:
# new ProjectGroup being created
for annotator in annotators:
self._set_proj_from_group(ProjectAnnotateEntities(), obj, annotator,
admins, cdb_search_filters, tasks, relations)
else:
# applying these settings to all previously created projects within this group
projs = ProjectAnnotateEntities.objects.filter(group=obj)
if len(projs) == len(obj.annotators.all()):
for proj, annotator in zip(projs, obj.annotators.all()):
self._set_proj_from_group(proj, obj, annotator, admins, cdb_search_filters,
tasks, relations)
# create the underlying ProjectAnnotateEntities models or edit them
if obj.create_associated_projects:
if not change:
# new ProjectGroup being created
for annotator in annotators:
self._set_proj_from_group(ProjectAnnotateEntities(), obj, annotator,
admins, cdb_search_filters, tasks, relations)
else:
raise ValueError("Attempting to update a ProjectGroup but one or more "
"of underlying ProjectAnnotateEntities have been removed / or added "
"manually. To fix, go into each project seperately, or create new projects "
"and link to the ProjectGroup within ProjectAnnotateEntites page.")
# applying these settings to all previously created projects within this group
projs = ProjectAnnotateEntities.objects.filter(group=obj)
if len(projs) == len(obj.annotators.all()):
for proj, annotator in zip(projs, obj.annotators.all()):
self._set_proj_from_group(proj, obj, annotator, admins, cdb_search_filters,
tasks, relations)
else:
raise ValueError("Attempting to update a ProjectGroup but one or more "
"of underlying ProjectAnnotateEntities have been removed / or added "
"manually. To fix, go into each project separately, or create new projects "
"and link to the ProjectGroup within ProjectAnnotateEntities page.")


class AnnotatedEntityAdmin(admin.ModelAdmin):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.28 on 2024-05-14 12:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0076_auto_20240510_1451'),
]

operations = [
migrations.AddField(
model_name='projectgroup',
name='create_associated_projects',
field=models.BooleanField(default=True, help_text='This only functions on new Project Group entries. If creating a new Project Group and this is checked, it will create a ProjectAnnotateEntities for each annotator. If unchecked it will not create associated ProjectAnnotateEntities instead, leaving the admin to manually configure groups of projects.'),
),
]
7 changes: 7 additions & 0 deletions webapp/api/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ class ProjectGroup(ProjectFields, ProjectAnnotateEntitiesFields):
'This specific CDB should have been "imported" '
'via the CDB admin screen',
related_name='project_group_concept_source')
create_associated_projects = models.BooleanField(default=True,
help_text='This only functions on new Project Group entries. '
' If creating a new Project Group and this is checked, '
'it will create a ProjectAnnotateEntities for each'
' annotator. If unchecked it will not create associated'
' ProjectAnnotateEntities instead, leaving the admin to '
' manually configure groups of projects.')

def __str__(self):
return self.name
Expand Down
8 changes: 5 additions & 3 deletions webapp/frontend/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default {
projectGroups: {
items: [],
fields: [
{ key: 'name', label: 'Name' },
{ key: 'name', label: 'Name', sortable: true },
{ key: 'description', label: 'Description' },
{ key: 'last_modified', label: 'Last Modified', sortable: true }
]
Expand Down Expand Up @@ -169,8 +169,10 @@ export default {
})
},
selectProjectGroup(projectGroups) {
this.selectedProjectGroup = projectGroups[0]
this.selectedProjectGroup.items = this.projects.items.filter(p => p.group === this.selectedProjectGroup.id)
if (projectGroups.length > 0 && projectGroups[0]) {
this.selectedProjectGroup = projectGroups[0]
this.selectedProjectGroup.items = this.projects.items.filter(p => p.group === this.selectedProjectGroup.id)
}
},
}
}
Expand Down

0 comments on commit 4824a41

Please sign in to comment.