From 0f951dcf029d4af284467543a3afdf5bf6581a20 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 23 Apr 2024 11:16:38 +0100 Subject: switched to Django --- core/__init__.py | 0 core/admin.py | 3 + core/apps.py | 6 ++ core/migrations/__init__.py | 0 core/models.py | 3 + core/static/css/styles.css | 53 +++++++++++ core/templates/core/base.html | 58 ++++++++++++ core/templates/core/index.html | 100 +++++++++++++++++++++ core/templates/core/profile.html | 13 +++ core/templates/registration/logged_out.html | 9 ++ core/templates/registration/login.html | 43 +++++++++ .../registration/password_change_done.html | 15 ++++ .../registration/password_change_form.html | 59 ++++++++++++ .../registration/password_reset_complete.html | 20 +++++ .../registration/password_reset_confirm.html | 42 +++++++++ .../registration/password_reset_done.html | 19 ++++ .../registration/password_reset_email.html | 14 +++ .../registration/password_reset_form.html | 29 ++++++ core/templates/registration/register.html | 22 +++++ core/templatetags/__init__.py | 0 core/templatetags/table_extras.py | 31 +++++++ core/tests.py | 3 + core/urls.py | 11 +++ core/views.py | 24 +++++ 24 files changed, 577 insertions(+) create mode 100644 core/__init__.py create mode 100644 core/admin.py create mode 100644 core/apps.py create mode 100644 core/migrations/__init__.py create mode 100644 core/models.py create mode 100644 core/static/css/styles.css create mode 100644 core/templates/core/base.html create mode 100644 core/templates/core/index.html create mode 100644 core/templates/core/profile.html create mode 100644 core/templates/registration/logged_out.html create mode 100644 core/templates/registration/login.html create mode 100644 core/templates/registration/password_change_done.html create mode 100644 core/templates/registration/password_change_form.html create mode 100644 core/templates/registration/password_reset_complete.html create mode 100644 core/templates/registration/password_reset_confirm.html create mode 100644 core/templates/registration/password_reset_done.html create mode 100644 core/templates/registration/password_reset_email.html create mode 100644 core/templates/registration/password_reset_form.html create mode 100644 core/templates/registration/register.html create mode 100644 core/templatetags/__init__.py create mode 100644 core/templatetags/table_extras.py create mode 100644 core/tests.py create mode 100644 core/urls.py create mode 100644 core/views.py (limited to 'core') diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/admin.py b/core/admin.py new file mode 100644 index 0000000..4185d36 --- /dev/null +++ b/core/admin.py @@ -0,0 +1,3 @@ +# from django.contrib import admin + +# Register your models here. diff --git a/core/apps.py b/core/apps.py new file mode 100644 index 0000000..c0ce093 --- /dev/null +++ b/core/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class CoreConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "core" diff --git a/core/migrations/__init__.py b/core/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/models.py b/core/models.py new file mode 100644 index 0000000..0b4331b --- /dev/null +++ b/core/models.py @@ -0,0 +1,3 @@ +# from django.db import models + +# Create your models here. diff --git a/core/static/css/styles.css b/core/static/css/styles.css new file mode 100644 index 0000000..23064c6 --- /dev/null +++ b/core/static/css/styles.css @@ -0,0 +1,53 @@ +.format-container { + margin: 20px; + display: flex; + justify-content: space-evenly; + align-items: flex-start; + height: 300px; + gap: 1em; +} + +.form-thing { + width: 50%; + border-style: solid; + border-width: 5px 2px; + border-color: black; + padding: 20px; + background-color: #dbefff; + margin: auto; +} + +.ep-table { + font-size: small; + border: 1px solid; + border-collapse: collapse; + color: black; + border-spacing: 0; +} + +.summary-table { + font-size: small; + border: 1px solid; + border-collapse: collapse; + color: black; + border-spacing: 0; +} + +.summary-table > tbody > tr > td { + border: 1px solid; +} + + +.ep-table > thead > tr > th { + padding: 10px; + border: 1px solid; +} + +.ep-table > tbody > tr > td { + border: 1px solid; + padding: 3px; +} + +.ep-table > tbody > tr > td > ul > li > a { + color: green; +} diff --git a/core/templates/core/base.html b/core/templates/core/base.html new file mode 100644 index 0000000..1c2bfe0 --- /dev/null +++ b/core/templates/core/base.html @@ -0,0 +1,58 @@ +{% load static i18n %} + + + + + + + + + + + + + {% block title %}{% endblock title %} + {% block extra_head_tags %}{% endblock extra_head_tags %} + + + +{% block navbar %} +
+ + Home + Engagement Plans + Regulated Entities + Reporting + Dashboards + + {% if request.user.is_authenticated %} + {{ user }} + Log Out + {% else %} + Log In + {% endif %} + Help +
+{% endblock navbar %} + +
+ {% block content %} + {% endblock content %} +
+ + diff --git a/core/templates/core/index.html b/core/templates/core/index.html new file mode 100644 index 0000000..d279479 --- /dev/null +++ b/core/templates/core/index.html @@ -0,0 +1,100 @@ +{% extends "core/base.html" %} +{% load table_extras %} + +{% block title %}ComplyIQ - Information Management for DefNucSyR{% endblock title %} + +{% block content %} + +
+

ComplyIQ - Information Management for DefNucSyR

+
+ × +

Quote of the day

+

This is a placeholder for some interesting test. Use of lose.

+
+ +

{% lorem %}

+ +
+
+

Submarines and Propulsion

+
+
+ +

Assessments & Inspections:

+ + + + + + + + + {% for s in subs_regulatory %} + + + + + + + + {% endfor %} +
Start DateEnd DateEventSiteInspectors
{{ s.proposed_start_date|date:'j M y' }}{{ s.proposed_end_date|date:'j M y' }}{{ s }}{{ s.external_party }} + {% if s.officers.all %} + {{ s.officers.all|commalist }} + {% endif %} +
+
+
+ Add New +
+
+ See Enagements for full list +
+
+
+

Non-regulatory events:

+ + + + + + + {% if not subs %} + + + + + + {% else %} + {% for s in subs %} + + + + + + {% endfor %} + {% endif %} +
Start DateEnd DateSummary
NoneNoneNone
{{ s.proposed_start_date|date:'j M y' }}{{ s.proposed_end_date|date:'j M y' }}{{ s }}
+
+ +
+ +

{% lorem %}

+ +
+
+ +
+
+

Transport

+
+
+

{% lorem %}

+
+
+ +
+ +{% endblock content %} diff --git a/core/templates/core/profile.html b/core/templates/core/profile.html new file mode 100644 index 0000000..8171379 --- /dev/null +++ b/core/templates/core/profile.html @@ -0,0 +1,13 @@ +{% extends "core/base.html" %} + +{% block title %}Profile - {{ user }}{% endblock title %} + +{% block content %} + +
+ {% block body %} +

Profile for {{ user }} ({{ user.first_name }} {{ user.last_name }})

+

Email: {{ user.email }}

+ {% endblock body %} +{% endblock content %} +
diff --git a/core/templates/registration/logged_out.html b/core/templates/registration/logged_out.html new file mode 100644 index 0000000..61e6831 --- /dev/null +++ b/core/templates/registration/logged_out.html @@ -0,0 +1,9 @@ +{% extends "core/base.html" %} + +{% block title %}Logged out{% endblock title %} + +{% block content %} + +

You've logged out. Bye.

+ +{% endblock content %} diff --git a/core/templates/registration/login.html b/core/templates/registration/login.html new file mode 100644 index 0000000..9e00087 --- /dev/null +++ b/core/templates/registration/login.html @@ -0,0 +1,43 @@ +{% extends "core/base.html" %} + +{% block content %} + +
+ {% if form.errors %} +

Your username and password didn't match. Please try again.

+ {% endif %} + + {% if next %} + {% if user.is_authenticated %} +

Your account doesn't have access to this page. To proceed, + please login with an account that has access.

+ {% else %} +

Please login to see this page.

+ {% endif %} + {% endif %} + +
+ {% csrf_token %} +
+ {{ form.username.label_tag }} + {{ form.username }} +
+ +
+ {{ form.password.label_tag }} + {{ form.password }} +
+ +
+ +
+ +
+ +
+ {# Assumes you set up the password_reset view in your URLconf #} + Lost password? +
+ + {% endblock content %} +
diff --git a/core/templates/registration/password_change_done.html b/core/templates/registration/password_change_done.html new file mode 100644 index 0000000..20fac71 --- /dev/null +++ b/core/templates/registration/password_change_done.html @@ -0,0 +1,15 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} +{% block userlinks %}{% url 'django-admindocs-docroot' as docsroot %}{% if docsroot %}{% trans "Documentation" %} / {% endif %}{% trans "Change password" %} / {% trans "Log out" %}{% endblock userlinks %} +{% block breadcrumbs %} + +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}

{{ title }}

{% endblock content_title %} +{% block content %} +

{% trans "Your password was changed." %}

+{% endblock content %} diff --git a/core/templates/registration/password_change_form.html b/core/templates/registration/password_change_form.html new file mode 100644 index 0000000..4ed12d4 --- /dev/null +++ b/core/templates/registration/password_change_form.html @@ -0,0 +1,59 @@ +{% extends "admin/base_site.html" %} +{% load i18n static %} +{% block extrastyle %}{{ block.super }}{% endblock extrastyle %} +{% block userlinks %}{% url "django-admindocs-docroot" as docsroot %}{% if docsroot %}{% trans "Documentation" %} / {% endif %} {% trans "Change password" %} / {% trans "Log out" %}{% endblock userlinks %} +{% block breadcrumbs %} + +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}

{{ title }}

{% endblock content_title %} + +{% block content %}
+ +
{% csrf_token %} +
+{% if form.errors %} +

+ {% if form.errors.items|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %} +

+{% endif %} + +

{% trans "Please enter your old password, for security's sake, and then enter your new password twice so we can verify you typed it in correctly." %}

+ +
+ +
+ {{ form.old_password.errors }} + {{ form.old_password.label_tag }} {{ form.old_password }} +
+ +
+ {{ form.new_password1.errors }} + {{ form.new_password1.label_tag }} {{ form.new_password1 }} + {% if form.new_password1.help_text %} +
{{ form.new_password1.help_text|safe }}
+ {% endif %} +
+ +
+{{ form.new_password2.errors }} + {{ form.new_password2.label_tag }} {{ form.new_password2 }} + {% if form.new_password2.help_text %} +
{{ form.new_password2.help_text|safe }}
+ {% endif %} +
+ +
+ +
+ +
+ +
+
+ +{% endblock content %} diff --git a/core/templates/registration/password_reset_complete.html b/core/templates/registration/password_reset_complete.html new file mode 100644 index 0000000..0e60645 --- /dev/null +++ b/core/templates/registration/password_reset_complete.html @@ -0,0 +1,20 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} + +{% block breadcrumbs %} + +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}

{{ title }}

{% endblock content_title %} + +{% block content %} + +

{% trans "Your password has been set. You may go ahead and log in now." %}

+ +

{% trans "Log in" %}

+ +{% endblock content %} diff --git a/core/templates/registration/password_reset_confirm.html b/core/templates/registration/password_reset_confirm.html new file mode 100644 index 0000000..e493f5a --- /dev/null +++ b/core/templates/registration/password_reset_confirm.html @@ -0,0 +1,42 @@ +{% extends "admin/base_site.html" %} +{% load i18n static %} + +{% block extrastyle %}{{ block.super }}{% endblock extrastyle %} +{% block breadcrumbs %} + +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}

{{ title }}

{% endblock content_title %} +{% block content %} + +{% if validlink %} + +

{% trans "Please enter your new password twice so we can verify you typed it in correctly." %}

+ +
{% csrf_token %} +
+
+ {{ form.new_password1.errors }} + + {{ form.new_password1 }} +
+
+ {{ form.new_password2.errors }} + + {{ form.new_password2 }} +
+ +
+
+ +{% else %} + +

{% trans "The password reset link was invalid, possibly because it has already been used. Please request a new password reset." %}

+ +{% endif %} + +{% endblock content %} diff --git a/core/templates/registration/password_reset_done.html b/core/templates/registration/password_reset_done.html new file mode 100644 index 0000000..a29461d --- /dev/null +++ b/core/templates/registration/password_reset_done.html @@ -0,0 +1,19 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} + +{% block breadcrumbs %} + +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}

{{ title }}

{% endblock content_title %} +{% block content %} + +

{% trans "We've emailed you instructions for setting your password, if an account exists with the email you entered. You should receive them shortly." %}

+ +

{% trans "If you don't receive an email, please make sure you've entered the address you registered with, and check your spam folder." %}

+ +{% endblock content %} diff --git a/core/templates/registration/password_reset_email.html b/core/templates/registration/password_reset_email.html new file mode 100644 index 0000000..0cd2e51 --- /dev/null +++ b/core/templates/registration/password_reset_email.html @@ -0,0 +1,14 @@ +{% load i18n %}{% autoescape off %} +{% blocktrans %}You're receiving this email because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %} + +{% trans "Please go to the following page and choose a new password:" %} +{% block reset_link %} +{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} +{% endblock reset_link %} +{% trans "Your username, in case you've forgotten:" %} {{ user.get_username }} + +{% trans "Thanks for using our site!" %} + +{% blocktrans %}The {{ site_name }} team{% endblocktrans %} + +{% endautoescape %} diff --git a/core/templates/registration/password_reset_form.html b/core/templates/registration/password_reset_form.html new file mode 100644 index 0000000..921fb8e --- /dev/null +++ b/core/templates/registration/password_reset_form.html @@ -0,0 +1,29 @@ +{% extends "admin/base_site.html" %} +{% load i18n static %} + +{% block extrastyle %}{{ block.super }}{% endblock extrastyle %} +{% block breadcrumbs %} + +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}

{{ title }}

{% endblock content_title %} +{% block content %} + +

{% trans "Forgotten your password? Enter your email address below, and we'll email instructions for setting a new one." %}

+ +
{% csrf_token %} +
+
+ {{ form.email.errors }} + + {{ form.email }} +
+ +
+
+ +{% endblock content %} diff --git a/core/templates/registration/register.html b/core/templates/registration/register.html new file mode 100644 index 0000000..98615fd --- /dev/null +++ b/core/templates/registration/register.html @@ -0,0 +1,22 @@ +{% extends "core/base.html" %} + +{% block title %}Register new user{% endblock title %} + +{% block content %} +

Register a new user

+
+ {% csrf_token %} + {% if messages %} + + {% endif %} + {{ form }} + + + +
+ +{% endblock content %} diff --git a/core/templatetags/__init__.py b/core/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/templatetags/table_extras.py b/core/templatetags/table_extras.py new file mode 100644 index 0000000..53185d2 --- /dev/null +++ b/core/templatetags/table_extras.py @@ -0,0 +1,31 @@ +from django import template + +from engagements import models + +register = template.Library() + + +def commalist(value): + "Value is a list of TeamUsers - insert commas!" + names = [p.fullname() for p in value] + out = ", ".join(names) + return out + + +def dsc_bar_list(value): + items = [v.title for v in value] + return " | ".join(items) + + +def effort_for_org(value, org): + eff = ( + models.EngagementEffort.objects.filter(engagement__external_party=org) + .filter(effort_type="REGULATION") + .filter(sub_instruments=value) + ) + return sum(e.effort_total_hours() for e in eff) + + +register.filter("commalist", commalist) +register.filter("dsc_bar_list", dsc_bar_list) +register.filter("effort_for_org", effort_for_org) diff --git a/core/tests.py b/core/tests.py new file mode 100644 index 0000000..a79ca8b --- /dev/null +++ b/core/tests.py @@ -0,0 +1,3 @@ +# from django.test import TestCase + +# Create your tests here. diff --git a/core/urls.py b/core/urls.py new file mode 100644 index 0000000..b45430b --- /dev/null +++ b/core/urls.py @@ -0,0 +1,11 @@ +from django.contrib.auth.views import logout_then_login +from django.urls import path + +from . import views + +urlpatterns = [ + path("", views.index, name="index"), + path("dashboard/", views.dashboard, name="dashboard"), + path("logout-then-login/", logout_then_login, name="logout-the-login"), + path("profile/", views.profile, name="profile"), +] diff --git a/core/views.py b/core/views.py new file mode 100644 index 0000000..4e7cd41 --- /dev/null +++ b/core/views.py @@ -0,0 +1,24 @@ +from django.contrib.auth.decorators import login_required +from django.shortcuts import render + +from engagements.models import Engagement + + +@login_required +def index(request): + subs = Engagement.objects.sp().order_by("proposed_start_date")[:4] + subs_regulatory = Engagement.objects.sp_regulatory()[:4] + trans = Engagement.objects.tr()[:4] + context = dict(subs=subs, trans=trans, subs_regulatory=subs_regulatory) + return render(request, "core/index.html", context) + + +@login_required +def dashboard(request): + return render(request, "core/dashboard.html", {"section": "dashboard"}) + + +@login_required +def profile(request): + args = {"user": request.user} + return render(request, "core/profile.html", args) -- cgit v1.2.3