diff --git a/.gitattributes b/.gitattributes index ea294607443b584ec74e3bdb4966587e08d7c44b..6bb6a031208d4c7ebcfc7c139b80a07adf1f8dc5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4246,8 +4246,8 @@ SAS/LSMR/src/lsmr/lsmrapp/apps.py -text SAS/LSMR/src/lsmr/lsmrapp/migrations/0001_initial.py -text SAS/LSMR/src/lsmr/lsmrapp/migrations/__init__.py -text SAS/LSMR/src/lsmr/lsmrapp/models.py -text -SAS/LSMR/src/lsmr/lsmrapp/tests.py -text -SAS/LSMR/src/lsmr/lsmrapp/views.py -text +SAS/LSMR/src/lsmr/lsmrapp/serializers.py -text +SAS/LSMR/src/lsmr/lsmrapp/viewsets.py -text SAS/LSMR/src/lsmr/settings.py -text SAS/LSMR/src/lsmr/urls.py -text SAS/LSMR/src/lsmr/wsgi.py -text diff --git a/SAS/LSMR/src/lsmr/lsmrapp/models.py b/SAS/LSMR/src/lsmr/lsmrapp/models.py index 71a836239075aa6e6e4ecb700e9c42c95c022d91..b4d225b739374b8e70c0fc08ac33823c396a5060 100644 --- a/SAS/LSMR/src/lsmr/lsmrapp/models.py +++ b/SAS/LSMR/src/lsmr/lsmrapp/models.py @@ -1,3 +1,124 @@ -from django.db import models +""" +This file contains the database models +""" -# Create your models here. +from django.db.models import Model, CharField, DateTimeField, BooleanField, ForeignKey, CASCADE, TextField +#from django.contrib.postgres.fields import ArrayField, JSONField # todo: use postgres by default, then comment in +#from django.contrib.postgres.indexes import GinIndex # todo: use postgres by default, then comment in +from enum import Enum + + +# +# Common +# + +class Tags(Model): + name = CharField(max_length=30) + description = CharField(max_length=255) + + +class BasicCommon(Model): + # tags = ArrayField(CharField(max_length=30), size=8, blank=True, null=True) # todo: use postgres by default, then comment in + creation = DateTimeField(auto_now_add=True) + # update = DateTimeField(auto_now=True) # todo: maybe useful too? + + class Meta: + abstract = True + # indexes = [GinIndex(fields=['tags'])] # todo: use postgres by default, then comment in + + +class UserDefinedCommon(BasicCommon): + name = CharField(max_length=30) + + class Meta: + abstract = True + + +class SystemDefinedCommon(BasicCommon): + + class Meta: + abstract = True + + +# +# I/O +# + +class RoleChoice(Enum): + CORRELATOR = "correlator" + BEAMFORMER = "beamformer" + INSPECTION_PLOTS = "inspection plots" + CALIBRATOR = "calibrator" + TARGET = "target" + INPUT_OUTPUT = "input, output" + + +class DatatypeChoice(Enum): + VISIBILITIES = "visibilities" + TIME_SERIES = "time series" + INSTRUMENT_MODEL = "instrument model" + IMAGE = "image" + QUALITY = "quality" + + +# todo: where is this supposed to be used?! +class DataformatChoice(Enum): + MEASUREMENTSET = "MeasurementSet" + HDF5 = "HDF5" + + +class WorkIORoles(Model): + # todo: Choices does not seem to translate to a a Postgres ENUM type + # todo: If we are not happy with this as is, I see two options: + # todo: 1. Wait to see if they implement that EnumField in the meantime (https://code.djangoproject.com/ticket/24342) + # todo: 2. Do that in raw SQL outside Django + role = CharField( + max_length=30, + choices=[(tag, tag.value) for tag in RoleChoice] + ) + datatype = CharField( + max_length=30, + choices=[(tag, tag.value) for tag in DatatypeChoice] + ) + + +# +# Templates +# + +class Template(SystemDefinedCommon): + default_version = BooleanField() + version = CharField(max_length=30) + schema = TextField(default=None) # JSONField() + + class Meta: + abstract = True + + +class GeneratorTemplate(Template): + create_func = CharField(max_length=30) + + +class RunTemplate(Template): + pass + + +class WorkRequestTemplate(Template): + validation_code_js = CharField(max_length=30) + outputs = ForeignKey("WorkIORoles", related_name='role_output', on_delete=CASCADE) + inputs = ForeignKey("WorkIORoles", related_name='role_input', on_delete=CASCADE) + + +class WorkRelationTemplate(Template): + pass + + + + +# +# Instance Objects +# + +# todo: the blue stuff +# run / work request / work request relation -> SystemDefinedCommon +# others -> UserDefinedCommon \ No newline at end of file diff --git a/SAS/LSMR/src/lsmr/lsmrapp/serializers.py b/SAS/LSMR/src/lsmr/lsmrapp/serializers.py new file mode 100644 index 0000000000000000000000000000000000000000..059d3d3c5498eadf6d47130a954c3d1f8c5e339a --- /dev/null +++ b/SAS/LSMR/src/lsmr/lsmrapp/serializers.py @@ -0,0 +1,13 @@ +""" +This file contains the serializers (for the elsewhere defined data models) +""" + +from rest_framework import serializers +from lsmr.lsmrapp import models + +class GeneratorTemplateSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = models.GeneratorTemplate + fields = '__all__' + + diff --git a/SAS/LSMR/src/lsmr/lsmrapp/tests.py b/SAS/LSMR/src/lsmr/lsmrapp/tests.py deleted file mode 100644 index 7ce503c2dd97ba78597f6ff6e4393132753573f6..0000000000000000000000000000000000000000 --- a/SAS/LSMR/src/lsmr/lsmrapp/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/SAS/LSMR/src/lsmr/lsmrapp/views.py b/SAS/LSMR/src/lsmr/lsmrapp/views.py deleted file mode 100644 index 91ea44a218fbd2f408430959283f0419c921093e..0000000000000000000000000000000000000000 --- a/SAS/LSMR/src/lsmr/lsmrapp/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/SAS/LSMR/src/lsmr/lsmrapp/viewsets.py b/SAS/LSMR/src/lsmr/lsmrapp/viewsets.py new file mode 100644 index 0000000000000000000000000000000000000000..83e23086b9cc47c7b53747c385cdab230a6f210c --- /dev/null +++ b/SAS/LSMR/src/lsmr/lsmrapp/viewsets.py @@ -0,0 +1,11 @@ +""" +This file contains the viewsets (based on the elsewhere defined data models and serializers) +""" + +from rest_framework import viewsets +from lsmr.lsmrapp import models, serializers + +class GeneratorTemplateViewSet(viewsets.ModelViewSet): + queryset = models.GeneratorTemplate.objects.all() + serializer_class = serializers.GeneratorTemplateSerializer + diff --git a/SAS/LSMR/src/lsmr/settings.py b/SAS/LSMR/src/lsmr/settings.py index 9f7b5c2a176b61578ac0b133f1185a3db8936b61..651ffbf3e5c6159c417e5ef7f8a3ae521589e4a4 100644 --- a/SAS/LSMR/src/lsmr/settings.py +++ b/SAS/LSMR/src/lsmr/settings.py @@ -20,7 +20,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '-&$!kx$_0)u1x#zk9w^^81hfssaover2(8wdq_8n8n3u(8=-9n' +SECRET_KEY = '-&$!kx$_0)u1x#zk9w^^81hfssaover2(8wdq_8n8n3u(8=-9n' # todo: set something new here for production !!! # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -90,6 +90,17 @@ DATABASES = { } } + +REST_FRAMEWORK = { + # Use Django's standard `django.contrib.auth` permissions, + # or allow read-only access for unauthenticated users. + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.AllowAny', # todo: only for testing, restrict access once we got authentication running !!! + #'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' + ] +} + + # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators diff --git a/SAS/LSMR/src/lsmr/urls.py b/SAS/LSMR/src/lsmr/urls.py index 49601674fd6f8e0dd57711fa0d18fb83ac1a8c35..1722a8fa860f2f281b9376bd71cce2c7252275d7 100644 --- a/SAS/LSMR/src/lsmr/urls.py +++ b/SAS/LSMR/src/lsmr/urls.py @@ -13,9 +13,29 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from django.contrib import admin from django.urls import path +from django.views.generic.base import TemplateView + +from rest_framework import routers +from lsmr.lsmrapp.viewsets import GeneratorTemplateViewSet + + +# +# Django style patterns +# urlpatterns = [ path('admin/', admin.site.urls), ] + + +# +# REST Router +# + +router = routers.SimpleRouter() +router.register(r'generator_template', GeneratorTemplateViewSet) + +urlpatterns.extend(router.urls) diff --git a/SAS/LSMR/test/t_lsmrapp_models.py b/SAS/LSMR/test/t_lsmrapp_models.py index 661ada60b5d67c0b432eaccc392d7f597ed7f2e3..5a496996b30f596754f367fc4b33cb9176aac134 100755 --- a/SAS/LSMR/test/t_lsmrapp_models.py +++ b/SAS/LSMR/test/t_lsmrapp_models.py @@ -20,7 +20,7 @@ # $Id: $ import rest_framework.test -from lofar.sas.lsmr.lsmr.lsmrapp.models import * +from lsmr.lsmrapp.models import * client = rest_framework.test.APIClient()