diff options
author | Matthew Lemon <y@yulqen.org> | 2024-04-23 11:16:38 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-04-23 11:16:38 +0100 |
commit | 0f951dcf029d4af284467543a3afdf5bf6581a20 (patch) | |
tree | a48384210cdc168e3bd3ccff6d6d516eeed9e748 /core | |
parent | 8b084e9fe7a5f3a04c32daf9a24f7f2cf67300f9 (diff) |
switched to Django
Diffstat (limited to 'core')
24 files changed, 577 insertions, 0 deletions
diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/core/__init__.py 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 --- /dev/null +++ b/core/migrations/__init__.py 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 %} + +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"/> + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> + <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> + <link rel="preconnect" href="https://fonts.gstatic.com"> + <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700' rel='stylesheet' type='text/css'/> + <link rel="stylesheet" href="{% static 'css/styles.css' %}"/> + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> + <script src="https://unpkg.com/htmx.org@1.9.0" integrity="sha384-aOxz9UdWG0yBiyrTwPeMibmaoq07/d3a96GCbb9x60f3mOt5zwkjdbcHFnKH8qls" crossorigin="anonymous"></script> + <title>{% block title %}{% endblock title %}</title> + {% block extra_head_tags %}{% endblock extra_head_tags %} + <style type="text/css" media="screen"> + + * { + font-family: "Roboto Slab"; + } + + body, h1, h2, h3, h4, h5, h6 { + font-family: "Roboto Slab", sans-serif; +} + </style> +</head> +<body> +{% block navbar %} +<div class="w3-bar w3-border w3-blue w3-padding-16"> + <!-- <a href="/" class="w3-bar-item w3-button w3-dark-gray w3-xxlarge"><i class="fa fa-home"></i></a> --> + <a href="#" class="w3-bar-item w3-button w3-large">Home</a> + <a href="{% url 'engagements:home' %}" class="w3-bar-item w3-button w3-large">Engagement Plans</a> + <a href="{% url 'engagements:regulatedentities' %}" class="w3-bar-item w3-button w3-large">Regulated Entities</a> + <a href="#" class="w3-bar-item w3-button w3-large">Reporting</a> + <a href="#" class="w3-bar-item w3-button w3-large">Dashboards</a> + <div class="w3-dropdown-hover"> + <button class="w3-button w3-large">Teams</button> + <div class="w3-dropdown-content w3-bar-block w3-card-4"> + <a href="#" class="w3-bar-item w3-button">Submarines and Propulsion</a> + <a href="#" class="w3-bar-item w3-button">Transport</a> + </div> + </div> + {% if request.user.is_authenticated %} + <a class="w3-bar-item w3-right w3-button w3-large" href="#">{{ user }}</a> + <a class="w3-bar-item w3-right w3-button w3-large" href="{% url 'logout' %}">Log Out</a> + {% else %} + <a class="w3-bar-item w3-right w3-button w3-large" href="{% url 'login' %}">Log In</a> + {% endif %} + <a href="#" class="w3-right w3-bar-item w3-button w3-large">Help</a> +</div> +{% endblock navbar %} + + <div class="w3-container"> + {% block content %} + {% endblock content %} + </div> +</body> +</html> 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 %} + +<div class="w3-container"> + <h2>ComplyIQ - Information Management for DefNucSyR</h2> + <div class="w3-panel w3-leftbar w3-sand w3-xlarge w3-serif w3-display-container"> + <span onclick="this.parentElement.style.display='none'" + class="w3-button w3-display-topright">×</span> + <h3>Quote of the day</h3> + <p>This is a placeholder for some interesting test. Use of lose.</p> + </div> + + <p>{% lorem %}</p> + + <div class="w3-card-2 w3-margin-top"> + <header class="w3-container w3-light-blue"> + <h3>Submarines and Propulsion</h3> + </header> + <div class="w3-container"> + + <h3>Assessments & Inspections:</h3> + <table class="w3-table w3-bordered w3-margin-bottom"> + <tr class="w3-light-blue"> + <th>Start Date</th> + <th>End Date</th> + <th>Event</th> + <th>Site</th> + <th>Inspectors</th> + </tr> + {% for s in subs_regulatory %} + <tr> + <td>{{ s.proposed_start_date|date:'j M y' }}</td> + <td>{{ s.proposed_end_date|date:'j M y' }}</td> + <td><a href="{% url 'engagements:engagement_detail' s.pk %}">{{ s }}</a></td> + <td>{{ s.external_party }}</td> + <td> + {% if s.officers.all %} + {{ s.officers.all|commalist }} + {% endif %} + </td> + </tr> + {% endfor %} + </table> + <div class="w3-cell-row"> + <div class="w3-cell w3-left"> + <a href="{% url 'engagements:create' 'reg' %}" class="w3-button w3-round w3-blue">Add New</a> + </div> + <div class="w3-cell w3-right"> + <small>See <a href="#">Enagements</a> for full list</small> + </div> + </div> + <hr> + <h4>Non-regulatory events:</h4> + <table class="w3-table w3-bordered w3-margin-bottom"> + <tr class="w3-light-blue"> + <th>Start Date</th> + <th>End Date</th> + <th>Summary</th> + </tr> + {% if not subs %} + <tr> + <td>None</td> + <td>None</td> + <td>None</td> + </tr> + {% else %} + {% for s in subs %} + <tr> + <td>{{ s.proposed_start_date|date:'j M y' }}</td> + <td>{{ s.proposed_end_date|date:'j M y' }}</td> + <td><a href="#">{{ s }}</a></td> + </tr> + {% endfor %} + {% endif %} + </table> + <div> + <button class="w3-button w3-round w3-blue">Add New</button> + </div> + + <p>{% lorem %}</p> + + </div> + </div> + + <div class="w3-card-2 w3-margin-top"> + <header class="w3-container w3-light-blue"> + <h3>Transport</h3> + </header> + <div class="w3-container"> + <p>{% lorem %}</p> + </div> + </div> + +</div> + +{% 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 %} + +<div class="container"> + {% block body %} + <h1>Profile for {{ user }} ({{ user.first_name }} {{ user.last_name }})</h1> + <p>Email: <a href="mailto:{{ user.email }}">{{ user.email }}</a></p> + {% endblock body %} +{% endblock content %} +</div> 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 %} + + <p>You've logged out. Bye.</p> + +{% 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 %} + +<div class="w3-container"> + {% if form.errors %} + <p>Your username and password didn't match. Please try again.</p> + {% endif %} + + {% if next %} + {% if user.is_authenticated %} + <p>Your account doesn't have access to this page. To proceed, + please login with an account that has access.</p> + {% else %} + <p>Please login to see this page.</p> + {% endif %} + {% endif %} + + <form method="post" action="{% url 'login' %}"> + {% csrf_token %} + <div class="form-group"> + {{ form.username.label_tag }} + {{ form.username }} + </div> + + <div class="form-group"> + {{ form.password.label_tag }} + {{ form.password }} + </div> + + <div class="form-group"> + <button type="submit" class="btn btn-primary" value="login">Log In</button> + </div> + <input type="hidden" name="next" value="{{ next }}"> + </form> + + <div class="form-group"> + {# Assumes you set up the password_reset view in your URLconf #} + <a href="{% url 'password_reset' %}">Lost password?</a> + </div> + + {% endblock content %} +</div> 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 %}<a href="{{ docsroot }}">{% trans "Documentation" %}</a> / {% endif %}{% trans "Change password" %} / <a href="{% url 'admin:logout' %}">{% trans "Log out" %}</a>{% endblock userlinks %} +{% block breadcrumbs %} +<div class="breadcrumbs"> +<a href="{% url 'admin:index' %}">{% trans "Home" %}</a> +› {% trans "Password change" %} +</div> +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}<h1>{{ title }}</h1>{% endblock content_title %} +{% block content %} +<p>{% trans "Your password was changed." %}</p> +{% 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 }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock extrastyle %} +{% block userlinks %}{% url "django-admindocs-docroot" as docsroot %}{% if docsroot %}<a href="{{ docsroot }}">{% trans "Documentation" %}</a> / {% endif %} {% trans "Change password" %} / <a href="{% url 'admin:logout' %}">{% trans "Log out" %}</a>{% endblock userlinks %} +{% block breadcrumbs %} +<div class="breadcrumbs"> +<a href="{% url "admin:index" %}">{% trans "Home" %}</a> +› {% trans "Password change" %} +</div> +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}<h1>{{ title }}</h1>{% endblock content_title %} + +{% block content %}<div id="content-main"> + +<form method="post">{% csrf_token %} +<div> +{% if form.errors %} + <p class="errornote"> + {% if form.errors.items|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %} + </p> +{% endif %} + +<p>{% 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." %}</p> + +<fieldset class="module aligned wide"> + +<div class="form-row"> + {{ form.old_password.errors }} + {{ form.old_password.label_tag }} {{ form.old_password }} +</div> + +<div class="form-row"> + {{ form.new_password1.errors }} + {{ form.new_password1.label_tag }} {{ form.new_password1 }} + {% if form.new_password1.help_text %} + <div class="help">{{ form.new_password1.help_text|safe }}</div> + {% endif %} +</div> + +<div class="form-row"> +{{ form.new_password2.errors }} + {{ form.new_password2.label_tag }} {{ form.new_password2 }} + {% if form.new_password2.help_text %} + <div class="help">{{ form.new_password2.help_text|safe }}</div> + {% endif %} +</div> + +</fieldset> + +<div class="submit-row"> + <input type="submit" value="{% trans "Change my password" %}" class="default" /> +</div> + +</div> +</form></div> + +{% 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 %} +<div class="breadcrumbs"> +<a href="{% url 'admin:index' %}">{% trans "Home" %}</a> +› {% trans "Password reset" %} +</div> +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}<h1>{{ title }}</h1>{% endblock content_title %} + +{% block content %} + +<p>{% trans "Your password has been set. You may go ahead and log in now." %}</p> + +<p><a href="{{ login_url }}">{% trans "Log in" %}</a></p> + +{% 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 }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock extrastyle %} +{% block breadcrumbs %} +<div class="breadcrumbs"> +<a href="{% url 'admin:index' %}">{% trans "Home" %}</a> +› {% trans "Password reset confirmation" %} +</div> +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}<h1>{{ title }}</h1>{% endblock content_title %} +{% block content %} + +{% if validlink %} + +<p>{% trans "Please enter your new password twice so we can verify you typed it in correctly." %}</p> + +<form method="post">{% csrf_token %} +<fieldset class="module aligned"> + <div class="form-row field-password1"> + {{ form.new_password1.errors }} + <label for="id_new_password1">{% trans "New password:" %}</label> + {{ form.new_password1 }} + </div> + <div class="form-row field-password2"> + {{ form.new_password2.errors }} + <label for="id_new_password2">{% trans "Confirm password:" %}</label> + {{ form.new_password2 }} + </div> + <input type="submit" value="{% trans "Change my password" %}" /> +</fieldset> +</form> + +{% else %} + +<p>{% trans "The password reset link was invalid, possibly because it has already been used. Please request a new password reset." %}</p> + +{% 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 %} +<div class="breadcrumbs"> +<a href="{% url 'admin:index' %}">{% trans "Home" %}</a> +› {% trans "Password reset" %} +</div> +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}<h1>{{ title }}</h1>{% endblock content_title %} +{% block content %} + +<p>{% trans "We've emailed you instructions for setting your password, if an account exists with the email you entered. You should receive them shortly." %}</p> + +<p>{% trans "If you don't receive an email, please make sure you've entered the address you registered with, and check your spam folder." %}</p> + +{% 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 }}<link rel="stylesheet" type="text/css" href="{% static "admin/css/forms.css" %}" />{% endblock extrastyle %} +{% block breadcrumbs %} +<div class="breadcrumbs"> +<a href="{% url 'admin:index' %}">{% trans "Home" %}</a> +› {% trans "Password reset" %} +</div> +{% endblock breadcrumbs %} + +{% block title %}{{ title }}{% endblock title %} +{% block content_title %}<h1>{{ title }}</h1>{% endblock content_title %} +{% block content %} + +<p>{% trans "Forgotten your password? Enter your email address below, and we'll email instructions for setting a new one." %}</p> + +<form method="post">{% csrf_token %} +<fieldset class="module aligned"> + <div class="form-row field-email"> + {{ form.email.errors }} + <label for="id_email">{% trans "Email address:" %}</label> + {{ form.email }} + </div> + <input type="submit" value="{% trans "Reset my password" %}" /> +</fieldset> +</form> + +{% 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 %} + <h1>Register a new user</h1> + <form action="{% url 'register' %}" method="post" accept-charset="utf-8"> + {% csrf_token %} + {% if messages %} + <ul> + {% for message in messages %} + <li>{{ message }}</li> + {% endfor %} + </ul> + {% endif %} + {{ form }} + + <input type="submit" name="submit" id="submit" value="Register" /> + + </form> + +{% endblock content %} diff --git a/core/templatetags/__init__.py b/core/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/core/templatetags/__init__.py 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) |