Skip to content
Snippets Groups Projects
Commit e5ef8b39 authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

Task LSMR-13: Implemented template models and added a basic rest viewset for...

Task LSMR-13: Implemented template models and added a basic rest viewset for GeneratorTemplate. Postgres-specifics are commented out until the test setup can handle that.
parent e06a54d5
Branches
Tags
1 merge request!87Lsmr epic
...@@ -4246,8 +4246,8 @@ SAS/LSMR/src/lsmr/lsmrapp/apps.py -text ...@@ -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/0001_initial.py -text
SAS/LSMR/src/lsmr/lsmrapp/migrations/__init__.py -text SAS/LSMR/src/lsmr/lsmrapp/migrations/__init__.py -text
SAS/LSMR/src/lsmr/lsmrapp/models.py -text SAS/LSMR/src/lsmr/lsmrapp/models.py -text
SAS/LSMR/src/lsmr/lsmrapp/tests.py -text SAS/LSMR/src/lsmr/lsmrapp/serializers.py -text
SAS/LSMR/src/lsmr/lsmrapp/views.py -text SAS/LSMR/src/lsmr/lsmrapp/viewsets.py -text
SAS/LSMR/src/lsmr/settings.py -text SAS/LSMR/src/lsmr/settings.py -text
SAS/LSMR/src/lsmr/urls.py -text SAS/LSMR/src/lsmr/urls.py -text
SAS/LSMR/src/lsmr/wsgi.py -text SAS/LSMR/src/lsmr/wsgi.py -text
......
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
"""
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__'
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
"""
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
...@@ -20,7 +20,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) ...@@ -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/ # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # 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! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
...@@ -90,6 +90,17 @@ DATABASES = { ...@@ -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 # Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
......
...@@ -13,9 +13,29 @@ Including another URLconf ...@@ -13,9 +13,29 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path 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 = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
#
# REST Router
#
router = routers.SimpleRouter()
router.register(r'generator_template', GeneratorTemplateViewSet)
urlpatterns.extend(router.urls)
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
# $Id: $ # $Id: $
import rest_framework.test import rest_framework.test
from lofar.sas.lsmr.lsmr.lsmrapp.models import * from lsmr.lsmrapp.models import *
client = rest_framework.test.APIClient() client = rest_framework.test.APIClient()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment