From c04d9410e98f0071ef86092e2d3d7da13880fc22 Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 16 Sep 2022 15:18:04 +0000 Subject: [PATCH] Preparation for DataTables More sidebar items Restructuring --- academon/settings.py | 7 +++- academon/urls.py | 2 +- api/urls.py | 4 ++ api/views.py | 3 -- api/views/__init__.py | 0 api/views/urls.py | 9 ++++ core/templatetags/__init__.py | 0 core/templatetags/admin.py | 13 ++++++ core/urls/__init__.py | 1 + core/urls/admin.py | 11 +++++ core/urls/frontend.py | 2 - core/views/admin.py | 7 ---- core/views/admin/__init__.py | 1 + core/views/admin/vessels.py | 26 ++++++++++++ requirements.txt | 1 + settings.dist.ini | 2 + static/core/js/admin/vessels_datatable.js | 9 ++++ templates/core/admin/vessels_list.html | 22 ++++++++++ templates/core/base.html | 49 +--------------------- templates/core/navbar.html | 47 +++++++++++++++++++++ templates/core/{frontend => }/sidebar.html | 24 +++++++++++ 21 files changed, 178 insertions(+), 62 deletions(-) delete mode 100644 api/views.py create mode 100644 api/views/__init__.py create mode 100644 api/views/urls.py create mode 100644 core/templatetags/__init__.py create mode 100644 core/templatetags/admin.py create mode 100644 core/urls/admin.py delete mode 100644 core/views/admin.py create mode 100644 core/views/admin/__init__.py create mode 100644 core/views/admin/vessels.py create mode 100644 static/core/js/admin/vessels_datatable.js create mode 100644 templates/core/admin/vessels_list.html create mode 100644 templates/core/navbar.html rename templates/core/{frontend => }/sidebar.html (83%) diff --git a/academon/settings.py b/academon/settings.py index 0d67162..9c29fc8 100644 --- a/academon/settings.py +++ b/academon/settings.py @@ -17,7 +17,9 @@ MONSTERCONFIG = MonsterConfig(CONFIG_PATH) SECRET_KEY = ASK.secret_key # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = ASK.config.getboolean("ACADEMON", "Debug", fallback=False) + +ADMINS = [(ASK.config.get("ACADEMON", "AdminName"), ASK.config.get("ACADEMON", "AdminEmail"))] ALLOWED_HOSTS = [ASK.config["ACADEMON"]["Host"]] CSRF_TRUSTED_ORIGINS = [f"https://{host}" for host in ALLOWED_HOSTS] @@ -31,6 +33,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'ajax_datatable', 'dbsettings', 'core', ] @@ -127,7 +130,7 @@ USE_TZ = True STATIC_URL = '/static/' STATIC_ROOT = None if DEBUG else ASK.config.get( - "ACADEMON", "StaticRoot", fallback=BASE_DIR / "static") + "ACADEMON", "StaticRoot", fallback=None) STATICFILES_DIRS = [ BASE_DIR / "static", diff --git a/academon/urls.py b/academon/urls.py index cece570..55d4f05 100644 --- a/academon/urls.py +++ b/academon/urls.py @@ -2,7 +2,7 @@ from django.contrib import admin from django.urls import path, include urlpatterns = [ - path('admin/', admin.site.urls), + # path('django-admin/', admin.site.urls), path('api/', include(("api.urls", "api"))), path('', include(("core.urls", "core"))), ] diff --git a/api/urls.py b/api/urls.py index ad783e1..3d736ad 100644 --- a/api/urls.py +++ b/api/urls.py @@ -1,4 +1,8 @@ from django.urls import path, include +from .views.urls import VesselsDataTableURLView + + urlpatterns = [ + path("urls/datatable/vessels/", VesselsDataTableURLView.as_view(), name=""), ] diff --git a/api/views.py b/api/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/api/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/api/views/__init__.py b/api/views/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/views/urls.py b/api/views/urls.py new file mode 100644 index 0000000..f7d2e24 --- /dev/null +++ b/api/views/urls.py @@ -0,0 +1,9 @@ +from django.views import View +from django.http import JsonResponse +from django.contrib.auth.mixins import LoginRequiredMixin +from django.urls import reverse_lazy + + +class VesselsDataTableURLView(LoginRequiredMixin, View): + def get(self, request, *args, **kwargs): + return JsonResponse(reverse_lazy("core:admin_vessels_datatable"), safe=False) \ No newline at end of file diff --git a/core/templatetags/__init__.py b/core/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/templatetags/admin.py b/core/templatetags/admin.py new file mode 100644 index 0000000..5ddbdf5 --- /dev/null +++ b/core/templatetags/admin.py @@ -0,0 +1,13 @@ +from django import template +from django.conf import settings + + +register = template.Library() + +@register.simple_tag +def admin_email(): + return settings.ADMINS[0][1] + +@register.simple_tag +def admin_name(): + return settings.ADMINS[0][0] \ No newline at end of file diff --git a/core/urls/__init__.py b/core/urls/__init__.py index a1d540a..57665ab 100644 --- a/core/urls/__init__.py +++ b/core/urls/__init__.py @@ -3,6 +3,7 @@ from django.conf import settings urlpatterns = [ + path('admin/', include('core.urls.admin')), path('auth/', include("core.urls.auth")), path('', include("core.urls.frontend")), ] diff --git a/core/urls/admin.py b/core/urls/admin.py new file mode 100644 index 0000000..d2c59fe --- /dev/null +++ b/core/urls/admin.py @@ -0,0 +1,11 @@ +from django.urls import path + +from ..views.frontend import NotImplementedView +from ..views.admin.vessels import AdminVesselsListView, AdminVesselsListDataTableView + + +urlpatterns = [ + path("admin/", NotImplementedView.as_view(), name="admin"), + path("vessels/", AdminVesselsListView.as_view(), name="admin_vessels"), + path("vessels/datatable/", AdminVesselsListDataTableView.as_view(), name="admin_vessels_datatable"), +] \ No newline at end of file diff --git a/core/urls/frontend.py b/core/urls/frontend.py index 9b0e1bd..50593e4 100644 --- a/core/urls/frontend.py +++ b/core/urls/frontend.py @@ -5,8 +5,6 @@ from ..views.frontend import DashboardView, NotImplementedView urlpatterns = [ - path("admin/", NotImplementedView.as_view(), name="admin"), - path("admin/vessels/", NotImplementedView.as_view(), name="admin_vessels"), path("dashboard/", DashboardView.as_view(), name="dashboard"), path("", RedirectView.as_view(url=reverse_lazy("core:dashboard"))), ] \ No newline at end of file diff --git a/core/views/admin.py b/core/views/admin.py deleted file mode 100644 index 1045c50..0000000 --- a/core/views/admin.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.views.generic import ListView - -from ..mixins.auth import SuperuserRequiredMixin - - -class AdminVesselsListView(TemplateView, SuperuserRequiredMixin): - template_name = "core/base.html" diff --git a/core/views/admin/__init__.py b/core/views/admin/__init__.py new file mode 100644 index 0000000..0b5741a --- /dev/null +++ b/core/views/admin/__init__.py @@ -0,0 +1 @@ +from .vessels import AdminVesselsListView, AdminVesselsListDataTableView \ No newline at end of file diff --git a/core/views/admin/vessels.py b/core/views/admin/vessels.py new file mode 100644 index 0000000..52f1bb8 --- /dev/null +++ b/core/views/admin/vessels.py @@ -0,0 +1,26 @@ +from django.views.generic import ListView, TemplateView + +from ajax_datatable.views import AjaxDatatableView + +from ...models.vessel import Vessel +from ...mixins.auth import SuperuserRequiredMixin + + +class AdminVesselsListView(SuperuserRequiredMixin, TemplateView): + template_name = "core/admin/vessels_list.html" + + +class AdminVesselsListDataTableView(AjaxDatatableView): + model = Vessel + title = 'Vessels' + initial_order = [["name", "asc"], ] + length_menu = [[10, 20, 50, 100, -1], [10, 20, 50, 100, 'all']] + search_values_separator = '+' + + column_defs = [ + AjaxDatatableView.render_row_tools_column_def(), + {'name': 'id', 'visible': False, }, + {'name': 'name', 'visible': True, }, + {'name': 'imo', 'visible': True, }, + {'name': 'mmsi', 'visible': True, }, + ] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8ec3531..eb720af 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ certifi django-storages boto3 django-ajax-datatable +pytz dbsettings django-autosecretkey diff --git a/settings.dist.ini b/settings.dist.ini index 9749dca..ab7c2e0 100644 --- a/settings.dist.ini +++ b/settings.dist.ini @@ -1,5 +1,7 @@ [ACADEMON] Host = academon.example.com +AdminName = Admin Person +AdminEmail = admin@example.com [ADONIS] CrewPortalBaseURL=http://adonis/AdonisWebServices/CrewPortalWebService.svc/ diff --git a/static/core/js/admin/vessels_datatable.js b/static/core/js/admin/vessels_datatable.js new file mode 100644 index 0000000..afef215 --- /dev/null +++ b/static/core/js/admin/vessels_datatable.js @@ -0,0 +1,9 @@ +$(document).ready(function () { + $.getJSON("/api/urls/datatable/vessels/") + .done(function (data) { + AjaxDatatableViewUtils.initialize_table( + $('#datatable_vessels'), + data, + ); + }); +}); \ No newline at end of file diff --git a/templates/core/admin/vessels_list.html b/templates/core/admin/vessels_list.html new file mode 100644 index 0000000..e61d71b --- /dev/null +++ b/templates/core/admin/vessels_list.html @@ -0,0 +1,22 @@ +{% extends "core/base.html"%} +{% load static %} + +{% block styles %} + + + +{% endblock %} + +{% block scripts %} + + + + + + + + + + + +{% endblock %} \ No newline at end of file diff --git a/templates/core/base.html b/templates/core/base.html index d432c28..103852b 100644 --- a/templates/core/base.html +++ b/templates/core/base.html @@ -16,53 +16,8 @@
- - -{% include "core/frontend/sidebar.html" %} +{% include "core/navbar.html" %} +{% include "core/sidebar.html" %}
diff --git a/templates/core/navbar.html b/templates/core/navbar.html new file mode 100644 index 0000000..44ebcdd --- /dev/null +++ b/templates/core/navbar.html @@ -0,0 +1,47 @@ +{% load admin %} + \ No newline at end of file diff --git a/templates/core/frontend/sidebar.html b/templates/core/sidebar.html similarity index 83% rename from templates/core/frontend/sidebar.html rename to templates/core/sidebar.html index 195d5f5..b6865ed 100644 --- a/templates/core/frontend/sidebar.html +++ b/templates/core/sidebar.html @@ -131,6 +131,30 @@

+ + + {% endif %}