From 13f0df75cc16f16b4b08a9161fe267464ed074fb Mon Sep 17 00:00:00 2001 From: Nico Vermaas <vermaas@astron.nl> Date: Tue, 12 Jul 2022 10:38:15 +0200 Subject: [PATCH] add templates, config, static, settings --- ldvspec/ldvspec/settings/docker_sdc.py | 38 ++++++++++++ ldvspec/ldvspec/wsgi_docker_sdc.py | 16 +++++ ldvspec/lofardata/admin.py | 2 + .../lofardata/templates/lofardata/base.html | 61 +++++++++++++++++++ .../lofardata/templates/lofardata/index.html | 16 +++++ ldvspec/lofardata/urls.py | 3 + ldvspec/lofardata/views.py | 15 +++-- 7 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 ldvspec/ldvspec/settings/docker_sdc.py create mode 100644 ldvspec/ldvspec/wsgi_docker_sdc.py create mode 100644 ldvspec/lofardata/templates/lofardata/base.html create mode 100644 ldvspec/lofardata/templates/lofardata/index.html diff --git a/ldvspec/ldvspec/settings/docker_sdc.py b/ldvspec/ldvspec/settings/docker_sdc.py new file mode 100644 index 00000000..f507dcbc --- /dev/null +++ b/ldvspec/ldvspec/settings/docker_sdc.py @@ -0,0 +1,38 @@ +from atdb.settings.base import * +import os + +# Import production setting must remain False. +DEV = False +try: + DEBUG = os.environ['DEBUG'] +except: + DEBUG = False + +ALLOWED_HOSTS = ["*"] + +# True: Enables a header that tells the UA to switch on the XSS filter. +# http://django-secure.readthedocs.io/en/latest/middleware.html#x-xss-protection-1-mode-block +SECURE_BROWSER_XSS_FILTER = True + +# Prevents the site from being deployed within a iframe. +# This prevent click-jacking attacks. +# See; https://docs.djangoproject.com/en/1.11/ref/clickjacking/ +X_FRAME_OPTIONS = 'DENY' +##################################################### + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': os.environ['DATABASE_NAME'], + 'HOST': os.environ['DATABASE_HOST'], + 'PORT': os.environ['DATABASE_PORT'], + 'USER' : os.environ['DATABASE_USER'], + 'PASSWORD' : os.environ['DATABASE_PASSWORD'], + }, +} + +# Password validation +# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [] + diff --git a/ldvspec/ldvspec/wsgi_docker_sdc.py b/ldvspec/ldvspec/wsgi_docker_sdc.py new file mode 100644 index 00000000..b65461a4 --- /dev/null +++ b/ldvspec/ldvspec/wsgi_docker_sdc.py @@ -0,0 +1,16 @@ +""" +WSGI config for atdb project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ldvspec.settings.docker_sdc") + +application = get_wsgi_application() diff --git a/ldvspec/lofardata/admin.py b/ldvspec/lofardata/admin.py index 8c38f3f3..cf044d64 100644 --- a/ldvspec/lofardata/admin.py +++ b/ldvspec/lofardata/admin.py @@ -1,3 +1,5 @@ from django.contrib import admin # Register your models here. +from .models import LofarData +admin.site.register(LofarData) \ No newline at end of file diff --git a/ldvspec/lofardata/templates/lofardata/base.html b/ldvspec/lofardata/templates/lofardata/base.html new file mode 100644 index 00000000..cb1761f5 --- /dev/null +++ b/ldvspec/lofardata/templates/lofardata/base.html @@ -0,0 +1,61 @@ + +<!DOCTYPE html> +{% load static %} + +<html lang="en"> +<head> + + <!-- Required meta tags --> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> + + <title>{% block myBlockTitle %}LDV Specification{% endblock %}</title> + + <!-- loads the path to static files --> + <script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> + <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script> + + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> + <link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'> + <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.2/css/all.css" integrity="sha384-/rXc/GQVaYpyDdyxK+ecHPVYJSN9bmVFBvjA/9eOB+pb3F2w2N6fc5qB9Ew5yIns" crossorigin="anonymous"> + <link href="{% static 'fontawesome_free/css/all.min.css' %}" rel="stylesheet" type="text/css"> + + <link rel="stylesheet" type="text/css" href="{% static 'ldvspec/style.css' %}"/> + <link rel="icon" href="{% static 'favicon.ico' %}"> + + {% block extra_js %}{% endblock %} + + +</head> +<body onload="readFromLocalStorage('search_box')"> + <nav class="navbar navbar-expand-lg navbar-light bg-light"> + <div class="container-fluid"> + <ul class="nav navbar-nav"> + <!-- Header --> + <li><a class="navbar-brand" href="{% url 'index' %}"> + <img src="{% static 'lofardata/ldvspec_logo.png' %}" height="30" alt=""> + LDV Specification</a> + </li> + + <li><a class="nav-link" href="{% url 'index' %}">Home</a></li> + <li><a class="nav-link" href="{% url 'lofardata' %}">LOFAR Data</a></li> + + {% if user.is_authenticated %} + <a class="nav-link" href="{% url 'logout' %}" target="_blank">Logout {{ user.get_username }}</a> + {% endif %} + {% if not user.is_authenticated %} + <a class="nav-link" href="{% url 'login' %}" target="_blank">Login</a> + {% endif %} + </div> + + </nav> + + <!-- to add blocks of code --> + {% block myBlock %} + {% endblock %} + +</body> + + +</html> diff --git a/ldvspec/lofardata/templates/lofardata/index.html b/ldvspec/lofardata/templates/lofardata/index.html new file mode 100644 index 00000000..0a9229d1 --- /dev/null +++ b/ldvspec/lofardata/templates/lofardata/index.html @@ -0,0 +1,16 @@ +{% extends 'lofardata/base.html' %} +{% load static %} + +{% block myBlock %} + +<div class="container-fluid details-container"> + + <div class="row"> + + </div> + <p class="footer"> Version 1.0.0 (12 jul 2022 - 10:00) + +</div> + +{% endblock %} + diff --git a/ldvspec/lofardata/urls.py b/ldvspec/lofardata/urls.py index 18cc4479..3d831832 100644 --- a/ldvspec/lofardata/urls.py +++ b/ldvspec/lofardata/urls.py @@ -14,4 +14,7 @@ urlpatterns = [ # REST API path('lofardata/', views.LofarDataView.as_view(), name='lofardata'), + + # GUI + path('', views.IndexView.as_view(), name='index'), ] \ No newline at end of file diff --git a/ldvspec/lofardata/views.py b/ldvspec/lofardata/views.py index 1e04c3e9..0464a1b8 100644 --- a/ldvspec/lofardata/views.py +++ b/ldvspec/lofardata/views.py @@ -1,5 +1,5 @@ -from django.http import HttpResponse +from django.views.generic import ListView from rest_framework import generics, pagination from rest_framework.views import APIView @@ -19,13 +19,18 @@ class LofarDataFilter(filters.FilterSet): 'sas_id': ['exact', 'icontains'], } -# --- GUI --- +# ---------- GUI Views ----------- -def index(request): - return HttpResponse("Welcome to LDV-specification.") +class IndexView(ListView): + """ + This is the main view of LDV Specification GUI. + """ + template_name = 'lofardata/index.html' + model = LofarData + queryset = LofarData.objects.all().order_by('sas_id') -# --- REST API views --- +# ---------- REST API views ---------- class LofarDataView(generics.ListCreateAPIView): model = LofarData -- GitLab