diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/migrations/0001_initial.py b/SAS/TMSS/backend/src/tmss/tmssapp/migrations/0001_initial.py index c9b1b0d50f4a4bec1eca066c40d86fb3b992d56a..97e17b9d3d22b21f1f3ead469c0508152a8630f8 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/migrations/0001_initial.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.9 on 2021-07-09 07:33 +# Generated by Django 3.0.9 on 2021-08-05 10:16 from django.conf import settings import django.contrib.auth.models @@ -631,6 +631,15 @@ class Migration(migrations.Migration): }, bases=(models.Model, lofar.sas.tmss.tmss.tmssapp.models.common.TemplateSchemaMixin), ), + migrations.CreateModel( + name='SchedulingState', + fields=[ + ('value', models.CharField(max_length=128, primary_key=True, serialize=False, unique=True)), + ], + options={ + 'abstract': False, + }, + ), migrations.CreateModel( name='SchedulingUnitBlueprint', fields=[ @@ -1415,6 +1424,11 @@ class Migration(migrations.Migration): name='project_category', field=models.ForeignKey(help_text='Category this project falls under.', null=True, on_delete=django.db.models.deletion.PROTECT, to='tmssapp.ProjectCategory'), ), + migrations.AddField( + model_name='project', + name='scheduling_state', + field=models.ForeignKey(default='opened', help_text='The scheduling state this project is in.', on_delete=django.db.models.deletion.PROTECT, to='tmssapp.SchedulingState'), + ), migrations.AddConstraint( model_name='generatortemplate', constraint=models.UniqueConstraint(fields=('name', 'version'), name='generatortemplate_unique_name_version'), diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py index c443bfb04340fb77de7c54ba3cfca6b493456438..429db7b5e6374308f0c53ed92e1577e0541d3b4a 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py @@ -157,6 +157,18 @@ class PriorityQueueType(AbstractChoice): A = "A" B = "B" + +class SchedulingState(AbstractChoice): + """Defines the model and predefined list of possible SchedulingState's of a Project. + The items in the Choices class below are automagically populated into the database via a data migration.""" + class Choices(Enum): + OPENED = "opened" + ACTIVE = "active" + FINISHED = "finished" + CANCELLED = "cancelled" + SUSPENDED = "suspended" + + # concrete models class Setting(BasicCommon): @@ -364,6 +376,7 @@ class Project(RefreshFromDbInvalidatesCachedPropertiesMixin, NamedCommonPK): piggyback_allowed_tbb = BooleanField(default=True, help_text='Piggyback key for TBB.') piggyback_allowed_aartfaac = BooleanField(default=True, help_text='Piggyback key for AARTFAAC.') path_to_project = "project" + scheduling_state = ForeignKey('SchedulingState', default=SchedulingState.Choices.OPENED.value, on_delete=PROTECT, null=False, help_text='The scheduling state this project is in.') @cached_property def duration(self) -> datetime.timedelta: diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py index fad946748e363bc4c1e25a5c1b15b15df86419e9..221e5455b06bf149da57dba3d81f710bd0f8cf7e 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py @@ -122,7 +122,8 @@ def populate_choices(apps, schema_editor): ''' choice_classes = [Role, IOType, Datatype, Dataformat, CopyReason, SubtaskState, SubtaskType, StationType, HashAlgorithm, SchedulingRelationPlacement, - SystemSettingFlag, ProjectCategory, PeriodCategory, Quantity, TaskType, ProjectRole, PriorityQueueType] + SystemSettingFlag, ProjectCategory, PeriodCategory, Quantity, TaskType, ProjectRole, + PriorityQueueType, SchedulingState] # upload choices in parallel with ThreadPoolExecutor() as executor: diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/serializers/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/serializers/specification.py index 0e081ba8296b54e329bbc268d870ae689c7337d6..b7a8b57615862950c0a4b9a01406364fd1b34bf7 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/serializers/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/serializers/specification.py @@ -449,3 +449,9 @@ class SchedulingUnitBlueprintExtendedSerializer(SchedulingUnitBlueprintSerialize are expanded into the json response for a single API call (for convenience/optimization). """ task_blueprints = TaskBlueprintExtendedSerializer(many=True) + + +class SchedulingStateSerializer(DynamicRelationalHyperlinkedModelSerializer): + class Meta: + model = models.SchedulingState + fields = '__all__' diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py index 3d85e66c8d5cca2d9adeaf4400c4b7be1b9fd7e0..66cd1f570ce71b457868cc41aa8b9505a5a14eda 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py @@ -1289,3 +1289,7 @@ class PriorityQueueTypeViewSet(LOFARViewSet): queryset = models.PriorityQueueType.objects.all() serializer_class = serializers.PriorityQueueTypeSerializer + +class SchedulingStateViewSet(LOFARViewSet): + queryset = models.SchedulingState.objects.all() + serializer_class = serializers.SchedulingStateSerializer diff --git a/SAS/TMSS/backend/src/tmss/urls.py b/SAS/TMSS/backend/src/tmss/urls.py index 409fcec7002c5bf2954bb8382471c7f08d289cb6..62b9edd25c4da8e373f9863e4a4c912559426958 100644 --- a/SAS/TMSS/backend/src/tmss/urls.py +++ b/SAS/TMSS/backend/src/tmss/urls.py @@ -132,6 +132,7 @@ router.register(r'project_category', viewsets.ProjectCategoryViewSet) router.register(r'quantity', viewsets.QuantityViewSet) router.register(r'task_type', viewsets.TaskTypeViewSet) router.register(r'priority_queue_type', viewsets.PriorityQueueTypeViewSet) +router.register(r'scheduling_state', viewsets.SchedulingStateViewSet) # templates router.register(r'common_schema_template', viewsets.CommonSchemaTemplateViewSet)