diff --git a/webapp/api/api/admin/models.py b/webapp/api/api/admin/models.py index a5c4eb0..76f7c8a 100644 --- a/webapp/api/api/admin/models.py +++ b/webapp/api/api/admin/models.py @@ -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: @@ -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): diff --git a/webapp/api/api/migrations/0077_projectgroup_create_associated_projects.py b/webapp/api/api/migrations/0077_projectgroup_create_associated_projects.py new file mode 100644 index 0000000..0905d55 --- /dev/null +++ b/webapp/api/api/migrations/0077_projectgroup_create_associated_projects.py @@ -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.'), + ), + ] diff --git a/webapp/api/api/models.py b/webapp/api/api/models.py index 2b2dbe3..96f385a 100644 --- a/webapp/api/api/models.py +++ b/webapp/api/api/models.py @@ -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 diff --git a/webapp/frontend/src/views/Home.vue b/webapp/frontend/src/views/Home.vue index 395cd73..e9169ce 100644 --- a/webapp/frontend/src/views/Home.vue +++ b/webapp/frontend/src/views/Home.vue @@ -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 } ] @@ -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) + } }, } }