mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-26 01:42:16 +00:00
Compare commits
81 Commits
subgrid
...
f0b3a6daf3
| Author | SHA1 | Date | |
|---|---|---|---|
| f0b3a6daf3 | |||
| 3c5f6da363 | |||
| ee9be86465 | |||
| 5554edf977 | |||
| 14b73f6f50 | |||
| 732affa0b2 | |||
| 7c830ee7e5 | |||
| d47d00d79b | |||
| 3b5b3b84d4 | |||
| aa8be6a6d0 | |||
| 640362c203 | |||
| 71a8823ac2 | |||
| c6de3dc9e2 | |||
| 8696bf5d94 | |||
| 0d9bf89180 | |||
| f4f2fbdc03 | |||
| 67aaada9e8 | |||
| fcae39c93c | |||
| d1970edfb3 | |||
| ce5efff268 | |||
|
522837c64e
|
|||
| e78decdf92 | |||
| 84a3c9db24 | |||
|
280a1d9604
|
|||
|
a184bbfa26
|
|||
|
4416e5bfcb
|
|||
|
21276bcca0
|
|||
|
bc465d67e9
|
|||
|
a644735cd6
|
|||
|
10326f884f
|
|||
|
0a0c9f15af
|
|||
|
dbb9e3e530
|
|||
|
55558d1a4a
|
|||
| 081c33ebc8 | |||
| 75410db752 | |||
| 06c6b9a36e | |||
| 13b1cea28b | |||
|
cddb76bf7e
|
|||
|
f4f1fb66a2
|
|||
|
d80aeca01f
|
|||
|
45dfe2db51
|
|||
|
de5997b9da
|
|||
|
4a121964dc
|
|||
|
df5e4c8e0a
|
|||
|
3601c14ab7
|
|||
|
adde6496f5
|
|||
|
ad734d94b2
|
|||
|
7d3ada822d
|
|||
|
732af53fda
|
|||
|
4fb0529cc0
|
|||
|
aa23b1cd09
|
|||
|
0c4228da57
|
|||
|
246a52d19e
|
|||
|
8b10aaf700
|
|||
|
4d0d4f02aa
|
|||
|
af987c1ebb
|
|||
|
d406a911bb
|
|||
|
63c5a68933
|
|||
|
66f7f830db
|
|||
|
9590c2066d
|
|||
|
8b48b02ca7
|
|||
|
68e7ec2a0d
|
|||
|
5779ebdf7e
|
|||
| be648c20d5 | |||
| b6ef7c1d89 | |||
| 85f40b358a | |||
| 2698798035 | |||
| dbaab5cf8c | |||
| 0a9f82e480 | |||
| 54f2bd36bd | |||
| e836195fef | |||
| 68a424d62b | |||
| 5e15b8bb59 | |||
| d26c1b535e | |||
| dff5ac2308 | |||
| a3729fa930 | |||
| 458a734331 | |||
| b1646d556c | |||
| f8624d3b7a | |||
| f6836fdab6 | |||
| b3949f2903 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -26,6 +26,7 @@ var/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
node_modules/
|
||||
data/
|
||||
|
||||
# Continer extras
|
||||
.vagrant
|
||||
|
||||
12
Pipfile
12
Pipfile
@@ -19,7 +19,7 @@ cssselect = "~=1.1.0"
|
||||
cssutils = "~=1.0.2"
|
||||
dj-database-url = "~=0.5.0"
|
||||
dj-static = "~=0.0.6"
|
||||
Django = "~=3.1.12"
|
||||
Django = "~=3.2"
|
||||
django-debug-toolbar = "~=3.2"
|
||||
django-filter = "~=2.4.0"
|
||||
django-ical = "~=1.7.1"
|
||||
@@ -89,14 +89,8 @@ pytest-django = "*"
|
||||
pluggy = "*"
|
||||
pytest-splinter = "*"
|
||||
pytest = "*"
|
||||
pytest-xdist = {extras = [ "psutil",], version = "*"}
|
||||
PyPOM = {extras = [ "splinter",], version = "*"}
|
||||
|
||||
[requires]
|
||||
python_version = "3.9"
|
||||
|
||||
[dev-packages.pytest-xdist]
|
||||
extras = [ "psutil",]
|
||||
version = "*"
|
||||
|
||||
[dev-packages.PyPOM]
|
||||
extras = [ "splinter",]
|
||||
version = "*"
|
||||
|
||||
@@ -61,6 +61,7 @@ INSTALLED_APPS = (
|
||||
'users',
|
||||
'RIGS',
|
||||
'assets',
|
||||
'training',
|
||||
|
||||
'debug_toolbar',
|
||||
'registration',
|
||||
@@ -259,3 +260,5 @@ USE_GRAVATAR = True
|
||||
|
||||
TERMS_OF_HIRE_URL = "http://www.nottinghamtec.co.uk/terms.pdf"
|
||||
AUTHORISATION_NOTIFICATION_ADDRESS = 'productions@nottinghamtec.co.uk'
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
|
||||
|
||||
@@ -12,6 +12,7 @@ urlpatterns = [
|
||||
path('', include('versioning.urls')),
|
||||
path('', include('RIGS.urls')),
|
||||
path('assets/', include('assets.urls')),
|
||||
path('training/', include('training.urls')),
|
||||
|
||||
path('', login_required(views.Index.as_view()), name='index'),
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from django.views.decorators.clickjacking import xframe_options_exempt
|
||||
|
||||
from RIGS import models
|
||||
from assets import models as asset_models
|
||||
from training import models as training_models
|
||||
|
||||
|
||||
def is_ajax(request):
|
||||
@@ -38,7 +39,8 @@ class SecureAPIRequest(generic.View):
|
||||
'organisation': models.Organisation,
|
||||
'profile': models.Profile,
|
||||
'event': models.Event,
|
||||
'supplier': asset_models.Supplier
|
||||
'supplier': asset_models.Supplier,
|
||||
'training_item': training_models.TrainingItem,
|
||||
}
|
||||
|
||||
perms = {
|
||||
@@ -47,7 +49,8 @@ class SecureAPIRequest(generic.View):
|
||||
'organisation': 'RIGS.view_organisation',
|
||||
'profile': 'RIGS.view_profile',
|
||||
'event': None,
|
||||
'supplier': None
|
||||
'supplier': None,
|
||||
'training_item': None, # TODO
|
||||
}
|
||||
|
||||
'''
|
||||
@@ -75,6 +78,9 @@ class SecureAPIRequest(generic.View):
|
||||
fields = request.GET.get('fields', None)
|
||||
if fields:
|
||||
fields = fields.split(",")
|
||||
filters = request.GET.get('filters', [])
|
||||
if filters:
|
||||
filters = filters.split(",")
|
||||
|
||||
# Supply data for one record
|
||||
if pk:
|
||||
@@ -95,6 +101,9 @@ class SecureAPIRequest(generic.View):
|
||||
for field in fields:
|
||||
q = Q(**{field + "__icontains": part})
|
||||
qs.append(q)
|
||||
for filter in filters:
|
||||
q = Q(**{field: True})
|
||||
qs.append(q)
|
||||
queries.append(reduce(operator.or_, qs))
|
||||
|
||||
# Build the data response list
|
||||
|
||||
@@ -14,7 +14,7 @@ from reversion.admin import VersionAdmin
|
||||
from RIGS import models
|
||||
from users import forms as user_forms
|
||||
|
||||
# Register your models here.
|
||||
|
||||
admin.site.register(models.VatRate, VersionAdmin)
|
||||
admin.site.register(models.Event, VersionAdmin)
|
||||
admin.site.register(models.EventItem, VersionAdmin)
|
||||
|
||||
@@ -3,6 +3,7 @@ from django.core.management.base import BaseCommand, CommandError
|
||||
from django.contrib.auth.models import Group
|
||||
from assets import models
|
||||
from RIGS import models as rigsmodels
|
||||
from training import models as tmodels
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
@@ -31,6 +32,9 @@ class Command(BaseCommand):
|
||||
self.delete_objects(rigsmodels.Payment)
|
||||
self.delete_objects(rigsmodels.RiskAssessment)
|
||||
self.delete_objects(rigsmodels.EventChecklist)
|
||||
self.delete_objects(tmodels.TrainingCategory)
|
||||
self.delete_objects(tmodels.TrainingItem)
|
||||
self.delete_objects(tmodels.TrainingLevel)
|
||||
|
||||
def delete_objects(self, model):
|
||||
for obj in model.objects.all():
|
||||
|
||||
@@ -12,3 +12,4 @@ class Command(BaseCommand):
|
||||
call_command('generateSampleUserData')
|
||||
call_command('generateSampleRIGSData')
|
||||
call_command('generateSampleAssetsData')
|
||||
call_command('generateSampleTrainingData')
|
||||
|
||||
@@ -21,6 +21,7 @@ class Command(BaseCommand):
|
||||
profiles = models.Profile.objects.all()
|
||||
|
||||
def handle(self, *args, **options):
|
||||
print("Generating rigboard data")
|
||||
from django.conf import settings
|
||||
|
||||
if not (settings.DEBUG or settings.STAGING):
|
||||
@@ -35,6 +36,7 @@ class Command(BaseCommand):
|
||||
self.setup_organisations()
|
||||
self.setup_venues()
|
||||
self.setup_events()
|
||||
print("Done generating rigboard data")
|
||||
|
||||
def setup_people(self):
|
||||
names = ["Regulus Black", "Sirius Black", "Lavender Brown", "Cho Chang", "Vincent Crabbe", "Vincent Crabbe",
|
||||
|
||||
18
RIGS/migrations/0043_auto_20211027_1519.py
Normal file
18
RIGS/migrations/0043_auto_20211027_1519.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.1.13 on 2021-10-27 14:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('RIGS', '0042_auto_20211007_2338'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='profile',
|
||||
name='initials',
|
||||
field=models.CharField(max_length=5, null=True),
|
||||
),
|
||||
]
|
||||
@@ -19,8 +19,9 @@ from reversion import revisions as reversion
|
||||
from reversion.models import Version
|
||||
|
||||
|
||||
class Profile(AbstractUser):
|
||||
initials = models.CharField(max_length=5, unique=True, null=True, blank=False)
|
||||
@reversion.register
|
||||
class Profile(AbstractUser): # TODO move to versioning - currently get import errors with that
|
||||
initials = models.CharField(max_length=5, null=True, blank=False)
|
||||
phone = models.CharField(max_length=13, blank=True, default='')
|
||||
api_key = models.CharField(max_length=40, blank=True, editable=False, default='')
|
||||
is_approved = models.BooleanField(default=False)
|
||||
@@ -65,7 +66,10 @@ class Profile(AbstractUser):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
# TODO move to versioning - currently get import errors with that
|
||||
@property
|
||||
def as_trainee(self):
|
||||
from training.models import Trainee
|
||||
return Trainee.objects.get(pk=self.pk)
|
||||
|
||||
|
||||
class RevisionMixin(object):
|
||||
|
||||
BIN
RIGS/static/imgs/assets.jpg
Normal file
BIN
RIGS/static/imgs/assets.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
BIN
RIGS/static/imgs/rigs.jpg
Normal file
BIN
RIGS/static/imgs/rigs.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 278 KiB |
BIN
RIGS/static/imgs/tappytaptap.gif
Normal file
BIN
RIGS/static/imgs/tappytaptap.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.3 MiB |
BIN
RIGS/static/imgs/training.jpg
Normal file
BIN
RIGS/static/imgs/training.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 852 KiB |
@@ -79,12 +79,12 @@
|
||||
});
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
})
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% include 'item_modal.html' %}
|
||||
{% include 'partials/item_modal.html' %}
|
||||
<form class="itemised_form" role="form" method="POST">
|
||||
{% csrf_token %}
|
||||
<div class="row">
|
||||
@@ -338,7 +338,7 @@
|
||||
|
||||
<div class="form-group" data-toggle="tooltip" title="The purchase order number (for external clients)">
|
||||
<label for="{{ form.purchase_order.id_for_label }}"
|
||||
class="col-sm-4 col-form-label">{{ form.purchase_order.label }}</label>
|
||||
class="col-sm-4 col-fitem_tableorm-label">{{ form.purchase_order.label }}</label>
|
||||
|
||||
<div class="col-sm-8">
|
||||
{% render_field form.purchase_order class+="form-control" %}
|
||||
|
||||
@@ -5,18 +5,16 @@
|
||||
{% load nice_errors from filters %}
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" href="{% static 'css/selects.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/selects.js' %}"></script>
|
||||
<script src="{% static 'js/selects.js' %}" async></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
|
||||
<script>
|
||||
function parseBool(str) {
|
||||
|
||||
@@ -45,7 +45,7 @@ class CableTypeForm(forms.ModelForm):
|
||||
model = models.CableType
|
||||
fields = '__all__'
|
||||
|
||||
def clean(self):
|
||||
def clean(self): # TODO Does unique_together work better than this?
|
||||
form_data = self.cleaned_data
|
||||
queryset = models.CableType.objects.filter(Q(plug=form_data['plug']) & Q(socket=form_data['socket']) & Q(circuits=form_data['circuits']) & Q(cores=form_data['cores']))
|
||||
# Being identical to itself shouldn't count...
|
||||
|
||||
@@ -20,6 +20,7 @@ class Command(BaseCommand):
|
||||
assets = []
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
print("Generating sample assets data")
|
||||
from django.conf import settings
|
||||
|
||||
if not (settings.DEBUG or settings.STAGING):
|
||||
@@ -34,6 +35,7 @@ class Command(BaseCommand):
|
||||
self.create_assets()
|
||||
self.create_connectors()
|
||||
self.create_cables()
|
||||
print("Done generating sample assets data")
|
||||
|
||||
def create_categories(self):
|
||||
choices = ['Case', 'Video', 'General', 'Sound', 'Lighting', 'Rigging']
|
||||
|
||||
@@ -64,16 +64,16 @@
|
||||
<div class="form-group form-row">
|
||||
{% include 'partials/form_field.html' with field=form.length append=form.length.help_text col="col-6" %}
|
||||
<div class="col-4">
|
||||
<button class="btn btn-danger" onclick="setFieldValue('{{ form.length.id_for_label }}','5');" tabindex="-1">5{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-success" onclick="setFieldValue('{{ form.length.id_for_label }}','10');" tabindex="-1">10{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-info" onclick="setFieldValue('{{ form.length.id_for_label }}','20');" tabindex="-1">20{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-danger" onclick="setFieldValue('{{ form.length.id_for_label }}','5');" tabindex="-1" type="button">5{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-success" onclick="setFieldValue('{{ form.length.id_for_label }}','10');" tabindex="-1" type="button">10{{ form.length.help_text }}</button>
|
||||
<button class="btn btn-info" onclick="setFieldValue('{{ form.length.id_for_label }}','20');" tabindex="-1" type="button">20{{ form.length.help_text }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
{% include 'partials/form_field.html' with field=form.csa append=form.csa.help_text title='CSA' col="col-6" %}
|
||||
<div class="col-4">
|
||||
<button class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '1.5');" tabindex="-1">1.5{{ form.csa.help_text }}</button>
|
||||
<button class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '2.5');" tabindex="-1">2.5{{ form.csa.help_text }}</button>
|
||||
<button class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '1.5');" tabindex="-1" type="button">1.5{{ form.csa.help_text }}</button>
|
||||
<button class="btn btn-secondary" onclick="setFieldValue('{{ form.csa.id_for_label }}', '2.5');" tabindex="-1" type="button">2.5{{ form.csa.help_text }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -12,9 +12,7 @@
|
||||
});
|
||||
$('#searchButton').click(function (e) {
|
||||
e.preventDefault();
|
||||
var url = "{% url 'asset_audit' None %}";
|
||||
var id = $("#{{form.q.id_for_label}}").val();
|
||||
url = url.replace('None', id);
|
||||
var url = "{% url 'asset_audit' None %}".replace('None', $("#{{form.q.id_for_label}}").val();
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: function(){
|
||||
|
||||
@@ -84,7 +84,7 @@ function browserSync(done) {
|
||||
notify: false,
|
||||
open: false,
|
||||
port: 8001,
|
||||
proxy: 'localhost:8000'
|
||||
proxy: '127.0.0.1:8000'
|
||||
});
|
||||
done();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
color: $gray-100 !important;
|
||||
border-color: $darktheme;
|
||||
}
|
||||
.btn-link {
|
||||
color: white;
|
||||
}
|
||||
.bs-popover-right > .arrow::after {
|
||||
border-right-color: $darktheme;
|
||||
}
|
||||
|
||||
@@ -33,24 +33,24 @@
|
||||
{% block navbar %}
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark" role="navigation">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" style="position: absolute; left:0.5em; top: 2px;" href="{% if request.user.is_authenticated %}https://rigs.nottinghamtec.co.uk{%else%}https://nottinghamtec.co.uk{%endif%}">
|
||||
<img src="{% static 'imgs/logo.webp' %}" width="40" height="40" alt="TEC's Logo: Serif 'TEC' vertically next to a blue box with the words 'PA and Lighting', surrounded by graduated rings" id="logo">
|
||||
</a>
|
||||
{% block titleheader %}
|
||||
{% endblock %}
|
||||
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation" onclick="document.getElementById('logo').classList.toggle('d-none');">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse justify-content-between" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav">
|
||||
{% block titleelements %}
|
||||
{% endblock %}
|
||||
</ul>
|
||||
<ul class="navbar-nav align-self-end">
|
||||
{% block titleelements_right %}
|
||||
{% endblock %}
|
||||
</ul>
|
||||
</div>
|
||||
<a class="navbar-brand" style="position: absolute; left:0.5em; top: 2px;" href="{% if request.user.is_authenticated %}https://rigs.nottinghamtec.co.uk{%else%}https://nottinghamtec.co.uk{%endif%}">
|
||||
<img src="{% static 'imgs/logo.webp' %}" width="40" height="40" alt="TEC's Logo: Serif 'TEC' vertically next to a blue box with the words 'PA and Lighting', surrounded by graduated rings" id="logo">
|
||||
</a>
|
||||
{% block titleheader %}
|
||||
{% endblock %}
|
||||
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation" onclick="document.getElementById('logo').classList.toggle('d-none');">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse justify-content-between" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav">
|
||||
{% block titleelements %}
|
||||
{% endblock %}
|
||||
</ul>
|
||||
<ul class="navbar-nav align-self-end">
|
||||
{% block titleelements_right %}
|
||||
{% endblock %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{% extends 'base_rigs.html' %}
|
||||
{% load humanize %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}RIGS{% endblock %}
|
||||
|
||||
@@ -7,8 +8,9 @@
|
||||
<div class="row">
|
||||
<h1 class="col-sm-12 pb-3">R<small class="text-muted">ig</small> I<small class="text-muted">nformation</small> G<small class="text-muted">athering</small> S<small class="text-muted">ystem</small></h1>
|
||||
<h2 class="col-sm-12 pb-3">Welcome back {{ user.get_full_name }}, there {%if rig_count == 1 %}is one rig coming up{%else%}are {{ rig_count|apnumber }} rigs coming up.{%endif%}</h2>
|
||||
<div class="col-sm mb-3">
|
||||
<div class="col-sm-4 mb-3">
|
||||
<div class="card">
|
||||
<img class="card-img-top" src="{% static 'imgs/rigs.jpg' %}" alt="" style="height: 150px; object-fit: cover;">
|
||||
<h4 class="card-header">Rigboard</h4>
|
||||
<div class="list-group list-group-flush">
|
||||
<a class="list-group-item list-group-item-action" href="{% url 'rigboard' %}"><span class="fas fa-list align-middle"></span><span class="align-middle"> Rigboard</span></a>
|
||||
@@ -17,6 +19,12 @@
|
||||
<a class="list-group-item list-group-item-action" href="{% url 'event_create' %}"><span class="fas fa-plus align-middle"></span><span class="align-middle"> New Event</span></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-4 mb-3">
|
||||
<div class="card">
|
||||
{% now "m-d" as todays_date %}
|
||||
<img class="card-img-top" src="{% if todays_date == '04-01' %}{% static 'imgs/tappytaptap.gif' %}{%else%}{% static 'imgs/assets.jpg' %}{%endif%}" alt="" style="height: 150px; object-fit: cover;">
|
||||
<h4 class="card-header">Asset Database</h4>
|
||||
<div class="list-group list-group-flush">
|
||||
<a class="list-group-item list-group-item-action" href="{% url 'asset_index' %}"><span class="fas fa-tag align-middle"></span><span class="align-middle"> Asset List</span></a>
|
||||
@@ -28,11 +36,28 @@
|
||||
<a class="list-group-item list-group-item-action" href="{% url 'supplier_create' %}"><span class="fas fa-plus align-middle"></span><span class="align-middle"> New Supplier</span></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-4 mb-3">
|
||||
<div class="card">
|
||||
<img class="card-img-top" src="{% static 'imgs/training.jpg' %}" alt="" style="height: 150px; object-fit: cover;">
|
||||
<h4 class="card-header">Training Database</h4>
|
||||
<div class="list-group list-group-flush">
|
||||
<a class="list-group-item list-group-item-action text-info" href="{% url 'trainee_detail' %}"><span class="fas fa-file-signature align-middle"></span><span class="align-middle"> My Training Record</span></a>
|
||||
<a class="list-group-item list-group-item-action" href="{% url 'trainee_list' %}"><span class="fas fa-users"></span> Trainee List</a>
|
||||
<a class="list-group-item list-group-item-action" href="{% url 'level_list' %}"><span class="fas fa-layer-group"></span> Level List</a></a>
|
||||
<a class="list-group-item list-group-item-action" href="{% url 'item_list' %}"><span class="fas fa-sitemap"></span> Item List</a></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm mb-3">
|
||||
<div class="card">
|
||||
<h4 class="card-header">Quick Links</h4>
|
||||
<div class="list-group list-group-flush">
|
||||
<a class="list-group-item list-group-item-action" href="https://forum.nottinghamtec.co.uk" target="_blank" rel="noopener noreferrer"><span class="fas fa-comment-alt text-info align-middle"></span><span class="align-middle"> TEC Forum</span></a>
|
||||
<a class="list-group-item list-group-item-action" href="https://forum.nottinghamtec.co.uk" target="_blank" rel="noopener noreferrer"><span class="fas fa-comment-alt text-primary align-middle"></span><span class="align-middle"> TEC Forum</span></a>
|
||||
<a class="list-group-item list-group-item-action" href="//nottinghamtec.sharepoint.com" target="_blank" rel="noopener noreferrer"><span class="fas fa-folder text-info align-middle"></span><span class="align-middle"> TEC Sharepoint</span></a>
|
||||
<a class="list-group-item list-group-item-action" href="//wiki.nottinghamtec.co.uk" target="_blank" rel="noopener noreferrer"><span class="fas fa-pen-square align-middle"></span><span class="align-middle"> TEC Wiki</span></a>
|
||||
{% if perms.RIGS.view_event %}
|
||||
{% if perms.RIGS.change_event %}
|
||||
<a class="list-group-item list-group-item-action" href="//members.nottinghamtec.co.uk/price" target="_blank" rel="noopener noreferrer"><span class="fas fa-pound-sign text-warning align-middle"></span><span class="align-middle"> Price List</span></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
0
training/__init__.py
Normal file
0
training/__init__.py
Normal file
8
training/admin.py
Normal file
8
training/admin.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.contrib import admin
|
||||
from training import models
|
||||
from reversion.admin import VersionAdmin
|
||||
|
||||
# admin.site.register(models.Trainee, VersionAdmin)
|
||||
admin.site.register(models.TrainingCategory, VersionAdmin)
|
||||
admin.site.register(models.TrainingItem, VersionAdmin)
|
||||
admin.site.register(models.TrainingLevel, VersionAdmin)
|
||||
5
training/apps.py
Normal file
5
training/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class TrainingConfig(AppConfig):
|
||||
name = 'training'
|
||||
49
training/forms.py
Normal file
49
training/forms.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from django import forms
|
||||
|
||||
from datetime import date
|
||||
|
||||
from training import models
|
||||
from RIGS.models import Profile
|
||||
|
||||
|
||||
class SessionLogForm(forms.Form):
|
||||
pass
|
||||
|
||||
|
||||
class QualificationForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = models.TrainingItemQualification
|
||||
fields = '__all__'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
pk = kwargs.pop('pk', None)
|
||||
super(QualificationForm, self).__init__(*args, **kwargs)
|
||||
self.fields['trainee'].initial = Profile.objects.get(pk=pk)
|
||||
self.fields['date'].initial = date.today()
|
||||
|
||||
def clean_date(self):
|
||||
date = self.cleaned_data['date']
|
||||
if date > date.today():
|
||||
raise forms.ValidationError('Qualification date may not be in the future')
|
||||
return date
|
||||
|
||||
def clean_supervisor(self):
|
||||
supervisor = self.cleaned_data['supervisor']
|
||||
if supervisor.pk == self.cleaned_data['trainee'].pk:
|
||||
raise forms.ValidationError('One may not supervise oneself...')
|
||||
if not supervisor.is_supervisor:
|
||||
raise forms.ValidationError('Selected supervisor must actually *be* a supervisor...')
|
||||
return supervisor
|
||||
|
||||
|
||||
class RequirementForm(forms.ModelForm):
|
||||
depth = forms.ChoiceField(choices=models.TrainingItemQualification.CHOICES)
|
||||
|
||||
class Meta:
|
||||
model = models.TrainingLevelRequirement
|
||||
fields = '__all__'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
pk = kwargs.pop('pk', None)
|
||||
super(RequirementForm, self).__init__(*args, **kwargs)
|
||||
self.fields['level'].initial = models.TrainingLevel.objects.get(pk=pk)
|
||||
0
training/management/commands/__init__.py
Normal file
0
training/management/commands/__init__.py
Normal file
211
training/management/commands/generateSampleTrainingData.py
Normal file
211
training/management/commands/generateSampleTrainingData.py
Normal file
@@ -0,0 +1,211 @@
|
||||
import datetime
|
||||
import random
|
||||
|
||||
from django.contrib.auth.models import Group, Permission
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import transaction
|
||||
from django.utils import timezone
|
||||
from reversion import revisions as reversion
|
||||
|
||||
from training import models
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Adds sample data to use for testing'
|
||||
can_import_settings = True
|
||||
|
||||
categories = []
|
||||
items = []
|
||||
levels = []
|
||||
|
||||
def handle(self, *args, **options):
|
||||
print("Generating training data")
|
||||
from django.conf import settings
|
||||
|
||||
if not (settings.DEBUG or settings.STAGING):
|
||||
raise CommandError('You cannot run this command in production')
|
||||
|
||||
random.seed('otherwise it is done by time, which could lead to inconsistant tests')
|
||||
|
||||
with transaction.atomic():
|
||||
self.setup_categories()
|
||||
self.setup_items()
|
||||
self.setup_levels()
|
||||
self.setup_supervisor()
|
||||
print("Done generating training data")
|
||||
|
||||
def setup_categories(self):
|
||||
names = [(1, "Basic"), (2, "Sound"), (3, "Lighting"), (4, "Rigging"), (5, "Power"), (6, "Haulage")]
|
||||
|
||||
for i, name in names:
|
||||
category = models.TrainingCategory.objects.create(reference_number=i, name=name)
|
||||
category.save()
|
||||
self.categories.append(category)
|
||||
|
||||
def setup_items(self):
|
||||
names = [
|
||||
"Motorised Power Towers",
|
||||
"Catering",
|
||||
"Forgetting Cables",
|
||||
"Gazebo Construction",
|
||||
"Balanced Audio",
|
||||
"Unbalanced Audio",
|
||||
"BBQ/Bin Interactions",
|
||||
"Pushing Boxes",
|
||||
"How Not To Die",
|
||||
"Setting up projectors",
|
||||
"Basketing truss",
|
||||
"First Aid",
|
||||
"Digging Trenches",
|
||||
"Avoiding Bin Lorries",
|
||||
"Getting cherry pickers stuck in mud",
|
||||
"Crashing the Van",
|
||||
"Getting pigs to fly",
|
||||
"Basketing picnics",
|
||||
"Python programming",
|
||||
"Building Cables",
|
||||
"Unbuilding Cables",
|
||||
"Cat Herding",
|
||||
"Pancake making",
|
||||
"Tidying up",
|
||||
"Reading Manuals",
|
||||
"Bikeshedding",
|
||||
"DJing",
|
||||
"Partying",
|
||||
"Teccie Gym",
|
||||
"Putting dust covers on",
|
||||
"Cleaning Lights",
|
||||
"Water Skiing",
|
||||
"Drinking",
|
||||
"Fundamentals of Audio",
|
||||
"Fundamentals of Photons",
|
||||
"Social Interaction",
|
||||
"Discourse Searching",
|
||||
"Discord Searching",
|
||||
"Coiling Cables",
|
||||
"Kit Amnesties",
|
||||
"Van Insurance",
|
||||
"Subhire Insurance",
|
||||
"Paperwork",
|
||||
"More Paperwork",
|
||||
"Second Aid",
|
||||
"Being Old",
|
||||
"Maxihoists",
|
||||
"Sleazyhoists",
|
||||
"Telehoists",
|
||||
"Prolyte",
|
||||
"Prolights",
|
||||
"Making Phonecalls",
|
||||
"Quoting For A Rig",
|
||||
"Basic MIC",
|
||||
"Advanced MIC",
|
||||
"Avoiding MIC",
|
||||
"Washing Cables",
|
||||
"Cable Ramp",
|
||||
"Van Loading",
|
||||
"Trailer Loading",
|
||||
"Storeroom Loading",
|
||||
"Welding",
|
||||
"Fire Extinguishers",
|
||||
"Boring Conference AV",
|
||||
"Flyaway",
|
||||
"Short Leads",
|
||||
"RF Systems",
|
||||
"QLab",
|
||||
"Use of Ladders",
|
||||
"Working at Height",
|
||||
"Organising Training",
|
||||
"Organising Organising Training Training",
|
||||
"Mental Health First Aid",
|
||||
"Writing RAMS",
|
||||
"Makros Runs",
|
||||
"PAT",
|
||||
"Kit Fixing",
|
||||
"Kit Breaking",
|
||||
"Replacing Lamps",
|
||||
"Flying Pig Systems",
|
||||
"Procrastination",
|
||||
"Drinking Beer",
|
||||
"Sending Emails",
|
||||
"Email Signatures",
|
||||
"Digital Sound Desks",
|
||||
"Digital Lighting Desks",
|
||||
"Painting PS10s",
|
||||
"Chain Lubrication",
|
||||
"Big Power",
|
||||
"BIGGER POWER",
|
||||
"Pixel Mapping",
|
||||
"RDM",
|
||||
"Ladder Inspections",
|
||||
"Losing Crimpaz",
|
||||
"Scrapping Trilite",
|
||||
"Bin Diving",
|
||||
"Wiki Editing"]
|
||||
|
||||
for i, name in enumerate(names):
|
||||
item = models.TrainingItem.objects.create(category=random.choice(self.categories), reference_number=random.randint(0, 100), name=name)
|
||||
self.items.append(item)
|
||||
|
||||
def setup_levels(self):
|
||||
items = self.items.copy()
|
||||
ta = models.TrainingLevel.objects.create(
|
||||
level=models.TrainingLevel.TA,
|
||||
description="Passion will hatred faithful evil suicide noble battle. Truth aversion gains grandeur noble. Dead play gains prejudice god ascetic grandeur zarathustra dead good. Faithful ultimate justice overcome love will mountains inexpedient.",
|
||||
icon="address-card")
|
||||
self.levels.append(ta)
|
||||
tech_ccs = models.TrainingLevel.objects.create(
|
||||
level=models.TrainingLevel.TECHNICIAN,
|
||||
description="Technician Common Competencies. Spirit abstract endless insofar horror sexuality depths war decrepit against strong aversion revaluation free. Christianity reason joy sea law mountains transvaluation. Sea battle aversion dead ultimate morality self. Faithful morality.",
|
||||
icon="book-reader")
|
||||
tech_ccs.prerequisite_levels.add(ta)
|
||||
super_ccs = models.TrainingLevel.objects.create(level=models.TrainingLevel.SUPERVISOR, description="Depths disgust hope faith of against hatred will victorious. Law...", icon="user-graduate")
|
||||
for i in range(0, 5):
|
||||
if len(items) == 0:
|
||||
break
|
||||
item = random.choice(items)
|
||||
items.remove(item)
|
||||
if i % 3 == 0:
|
||||
models.TrainingLevelRequirement.objects.create(level=tech_ccs, item=item, depth=random.choice(models.TrainingItemQualification.CHOICES)[0])
|
||||
else:
|
||||
models.TrainingLevelRequirement.objects.create(level=super_ccs, item=item, depth=random.choice(models.TrainingItemQualification.CHOICES)[0])
|
||||
icons = {
|
||||
models.TrainingLevel.SOUND: ('microphone', 'microphone-alt'),
|
||||
models.TrainingLevel.LIGHTING: ('lightbulb', 'traffic-light'),
|
||||
models.TrainingLevel.POWER: ('plug', 'bolt'),
|
||||
models.TrainingLevel.RIGGING: ('link', 'pallet'),
|
||||
models.TrainingLevel.HAULAGE: ('truck', 'route'),
|
||||
}
|
||||
for i, name in models.TrainingLevel.DEPARTMENTS:
|
||||
technician = models.TrainingLevel.objects.create(level=models.TrainingLevel.TECHNICIAN, department=i, description="Moral pinnacle derive ultimate war dead. Strong fearful joy contradict battle christian faithful enlightenment prejudice zarathustra moral.", icon=icons[i][0])
|
||||
technician.prerequisite_levels.add(tech_ccs)
|
||||
supervisor = models.TrainingLevel.objects.create(level=models.TrainingLevel.SUPERVISOR, department=i, description="Spirit holiest merciful mountains inexpedient reason value. Suicide ultimate hope.", icon=icons[i][1])
|
||||
supervisor.prerequisite_levels.add(super_ccs, technician)
|
||||
|
||||
for i in range(0, 30):
|
||||
if len(items) == 0:
|
||||
break
|
||||
item = random.choice(items)
|
||||
items.remove(item)
|
||||
if i % 3 == 0:
|
||||
models.TrainingLevelRequirement.objects.create(level=technician, item=item, depth=random.choice(models.TrainingItemQualification.CHOICES)[0])
|
||||
else:
|
||||
models.TrainingLevelRequirement.objects.create(level=supervisor, item=item, depth=random.choice(models.TrainingItemQualification.CHOICES)[0])
|
||||
self.levels.append(technician)
|
||||
self.levels.append(supervisor)
|
||||
|
||||
def setup_supervisor(self):
|
||||
supervisor = models.Profile.objects.create(username="supervisor", first_name="Super", last_name="Visor",
|
||||
initials="SV",
|
||||
email="supervisor@example.com", is_active=True,
|
||||
is_staff=True, is_approved=True)
|
||||
supervisor.set_password('supervisor')
|
||||
supervisor.groups.add(Group.objects.get(name="Keyholders"))
|
||||
supervisor.save()
|
||||
models.TrainingLevelQualification.objects.create(
|
||||
trainee=supervisor,
|
||||
level=models.TrainingLevel.objects.filter(
|
||||
level__gte=models.TrainingLevel.SUPERVISOR).exclude(
|
||||
department=models.TrainingLevel.HAULAGE).exclude(
|
||||
department__isnull=True).first(),
|
||||
confirmed_on=timezone.now(),
|
||||
confirmed_by=models.Trainee.objects.first())
|
||||
280
training/management/commands/import_old_db.py
Normal file
280
training/management/commands/import_old_db.py
Normal file
@@ -0,0 +1,280 @@
|
||||
import os
|
||||
import datetime
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
from django.db.utils import IntegrityError
|
||||
from django.utils.timezone import make_aware
|
||||
|
||||
from training import models
|
||||
from RIGS.models import Profile
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
epoch = datetime.date(1970, 1, 1)
|
||||
id_map = {}
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.import_Trainees()
|
||||
self.import_TrainingCatagory()
|
||||
self.import_TrainingItem()
|
||||
self.import_TrainingItemQualification()
|
||||
self.import_TrainingLevel()
|
||||
self.import_TrainingLevelQualification()
|
||||
self.import_TrainingLevelRequirements()
|
||||
|
||||
@staticmethod
|
||||
def xml_path(file):
|
||||
return os.path.join(settings.BASE_DIR, 'data/{}'.format(file))
|
||||
|
||||
@staticmethod
|
||||
def parse_xml(file):
|
||||
tree = ET.parse(file)
|
||||
|
||||
return tree.getroot()
|
||||
|
||||
def import_Trainees(self):
|
||||
tally = [0, 0]
|
||||
|
||||
root = self.parse_xml(self.xml_path('Members.xml'))
|
||||
|
||||
for child in root:
|
||||
try:
|
||||
name = child.find('Member_x0020_Name').text
|
||||
first_name = name.split()[0]
|
||||
last_name = " ".join(name.split()[1:])
|
||||
profile = Profile.objects.filter(first_name=first_name, last_name=last_name).first()
|
||||
|
||||
if profile:
|
||||
self.id_map[child.find('ID').text] = profile.pk
|
||||
tally[0] += 1
|
||||
else:
|
||||
# PYTHONIC, BABY
|
||||
initials = first_name[0] + "".join([name_section[0] for name_section in re.split("\\s*-", last_name.replace("(", ""))])
|
||||
# print(initials)
|
||||
new_profile = Profile.objects.create(username=name.replace(" ", ""),
|
||||
first_name=first_name,
|
||||
last_name=last_name,
|
||||
initials=initials)
|
||||
self.id_map[child.find('ID').text] = new_profile.pk
|
||||
tally[1] += 1
|
||||
except AttributeError: # W.T.F
|
||||
print("Trainee #{} is FUBAR".format(child.find('ID').text))
|
||||
|
||||
print('Trainees - Updated: {}, Created: {}'.format(tally[0], tally[1]))
|
||||
|
||||
def import_TrainingCatagory(self):
|
||||
tally = [0, 0]
|
||||
|
||||
root = self.parse_xml(self.xml_path('Categories.xml'))
|
||||
|
||||
for child in root:
|
||||
obj, created = models.TrainingCategory.objects.update_or_create(
|
||||
pk=int(child.find('ID').text),
|
||||
reference_number=int(child.find('Category_x0020_Number').text),
|
||||
name=child.find('Category_x0020_Name').text
|
||||
)
|
||||
|
||||
if created:
|
||||
tally[1] += 1
|
||||
else:
|
||||
tally[0] += 1
|
||||
|
||||
print('Categories - Updated: {}, Created: {}'.format(tally[0], tally[1]))
|
||||
|
||||
def import_TrainingItem(self):
|
||||
tally = [0, 0]
|
||||
|
||||
root = self.parse_xml(self.xml_path('Training Items.xml'))
|
||||
|
||||
for child in root:
|
||||
if child.find('active').text == '0':
|
||||
active = False
|
||||
else:
|
||||
active = True
|
||||
|
||||
number = int(child.find('Item_x0020_Number').text)
|
||||
name = child.find('Item_x0020_Name').text
|
||||
category = models.TrainingCategory.objects.get(pk=int(child.find('Category_x0020_ID').text))
|
||||
|
||||
try:
|
||||
obj, created = models.TrainingItem.objects.update_or_create(
|
||||
pk=int(child.find('ID').text),
|
||||
reference_number=number,
|
||||
name=name,
|
||||
category=category,
|
||||
active=active
|
||||
)
|
||||
except IntegrityError:
|
||||
print("Training Item {}.{} {} has a duplicate reference number".format(category.reference_number, number, name))
|
||||
|
||||
if created:
|
||||
tally[1] += 1
|
||||
else:
|
||||
tally[0] += 1
|
||||
|
||||
print('Training Items - Updated: {}, Created: {}'.format(tally[0], tally[1]))
|
||||
|
||||
def import_TrainingItemQualification(self):
|
||||
tally = [0, 0, 0]
|
||||
|
||||
root = self.parse_xml(self.xml_path('Training Records.xml'))
|
||||
|
||||
for child in root:
|
||||
depths = [("Training_Started", models.TrainingItemQualification.STARTED),
|
||||
("Training_Complete", models.TrainingItemQualification.COMPLETE),
|
||||
("Competency_Assessed", models.TrainingItemQualification.PASSED_OUT)]
|
||||
for depth, depth_index in depths:
|
||||
if child.find('{}_Date'.format(depth)) is not None:
|
||||
if child.find('{}_Assessor_ID'.format(depth)) is None:
|
||||
print("Training Record #{} had no supervisor. Hmm.".format(child.find('ID').text))
|
||||
tally[2] += 1
|
||||
# TODO Assign God/Satan/Unknown here.
|
||||
continue
|
||||
supervisor = Profile.objects.get(pk=self.id_map[child.find('{}_Assessor_ID'.format(depth)).text])
|
||||
if child.find('Member_ID') is None:
|
||||
print("Training Record #{} didn't train anybody and has been ignored. Dammit {}".format(child.find('ID').text, supervisor.name))
|
||||
tally[2] += 1
|
||||
continue
|
||||
try:
|
||||
obj, created = models.TrainingItemQualification.objects.update_or_create(
|
||||
pk=int(child.find('ID').text),
|
||||
item=models.TrainingItem.objects.get(pk=int(child.find('Training_Item_ID').text)),
|
||||
trainee=Profile.objects.get(pk=self.id_map[child.find('Member_ID').text]),
|
||||
depth=depth_index,
|
||||
date=child.find('{}_Date'.format(depth)).text[:-9], # Stored as datetime with time as midnight because fuck you I guess
|
||||
supervisor=supervisor
|
||||
)
|
||||
notes = child.find('{}_Notes'.format(depth))
|
||||
if notes:
|
||||
obj.notes = notes.text
|
||||
obj.save()
|
||||
if created:
|
||||
tally[1] += 1
|
||||
else:
|
||||
tally[0] += 1
|
||||
except IntegrityError: # Eh?
|
||||
print("Training Record #{} is duplicate. ಠ_ಠ".format(child.find('ID').text))
|
||||
except AttributeError:
|
||||
print(child.find('ID').text)
|
||||
|
||||
print('Training Item Qualifications - Updated: {}, Created: {}, Broken: {}'.format(tally[0], tally[1], tally[2]))
|
||||
|
||||
def import_TrainingLevel(self):
|
||||
tally = [0, 0]
|
||||
|
||||
root = self.parse_xml(self.xml_path('Training Levels.xml'))
|
||||
|
||||
for child in root:
|
||||
name = child.find('Level_x0020_Name').text
|
||||
if name == "Technical Assistant":
|
||||
level = models.TrainingLevel.TA
|
||||
depString = None
|
||||
elif "Common" in name:
|
||||
levelString = name.split()[0]
|
||||
if levelString == "Technician":
|
||||
level = models.TrainingLevel.TECHNICIAN
|
||||
elif levelString == "Supervisor":
|
||||
level = models.TrainingLevel.SUPERVISOR
|
||||
depString = None
|
||||
else:
|
||||
depString = name.split()[-1]
|
||||
levelString = name.split()[0]
|
||||
if levelString == "Technician":
|
||||
level = models.TrainingLevel.TECHNICIAN
|
||||
elif levelString == "Supervisor":
|
||||
level = models.TrainingLevel.SUPERVISOR
|
||||
else:
|
||||
print(levelString)
|
||||
continue
|
||||
for dep in models.TrainingLevel.DEPARTMENTS:
|
||||
if dep[1] == depString:
|
||||
department = dep[0]
|
||||
|
||||
desc = ""
|
||||
if child.find('Desc') is not None:
|
||||
desc = child.find('Desc').text
|
||||
|
||||
obj, created = models.TrainingLevel.objects.update_or_create(
|
||||
pk=int(child.find('ID').text),
|
||||
description=desc,
|
||||
level=level
|
||||
)
|
||||
if depString is not None:
|
||||
obj.department = department
|
||||
obj.save()
|
||||
|
||||
if created:
|
||||
tally[1] += 1
|
||||
else:
|
||||
tally[0] += 1
|
||||
|
||||
for level in models.TrainingLevel.objects.all():
|
||||
if level.department is not None:
|
||||
if level.level == models.TrainingLevel.TECHNICIAN:
|
||||
level.prerequisite_levels.add(models.TrainingLevel.objects.get(level=models.TrainingLevel.TA), models.TrainingLevel.objects.get(level=models.TrainingLevel.TECHNICIAN, department=None))
|
||||
elif level.level == models.TrainingLevel.SUPERVISOR:
|
||||
level.prerequisite_levels.add(models.TrainingLevel.objects.get(level=models.TrainingLevel.TECHNICIAN, department=level.department), models.TrainingLevel.objects.get(level=models.TrainingLevel.SUPERVISOR, department=None))
|
||||
|
||||
print('Training Levels - Updated: {}, Created: {}'.format(tally[0], tally[1]))
|
||||
|
||||
def import_TrainingLevelQualification(self):
|
||||
tally = [0, 0]
|
||||
|
||||
root = self.parse_xml(self.xml_path('Training Level Records.xml'))
|
||||
|
||||
for child in root:
|
||||
try:
|
||||
if child.find('Training_x0020_Level_x0020_ID') is None:
|
||||
print('Training Level Qualification #{} does not qualify in any level. How?'.format(child.find('ID').text))
|
||||
continue
|
||||
if child.find('Member_x0020_ID') is None:
|
||||
print('Training Level Qualification #{} does not qualify anyone. How?!'.format(child.find('ID').text))
|
||||
continue
|
||||
obj, created = models.TrainingLevelQualification.objects.update_or_create(
|
||||
pk=int(child.find('ID').text),
|
||||
trainee=Profile.objects.get(pk=self.id_map[child.find('Member_x0020_ID').text]),
|
||||
level=models.TrainingLevel.objects.get(pk=int(child.find('Training_x0020_Level_x0020_ID').text))
|
||||
)
|
||||
|
||||
if child.find('Date_x0020_Level_x0020_Awarded') is not None:
|
||||
obj.confirmed_on = make_aware(datetime.datetime.strptime(child.find('Date_x0020_Level_x0020_Awarded').text.split('T')[0], "%Y-%m-%d"))
|
||||
obj.save()
|
||||
# confirmed by?
|
||||
|
||||
if created:
|
||||
tally[1] += 1
|
||||
else:
|
||||
tally[0] += 1
|
||||
except IntegrityError: # Eh?
|
||||
print("Training Level Qualification #{} is duplicate. ಠ_ಠ".format(child.find('ID').text))
|
||||
|
||||
print('TrainingLevelQualifications - Updated: {}, Created: {}'.format(tally[0], tally[1]))
|
||||
|
||||
def import_TrainingLevelRequirements(self):
|
||||
tally = [0, 0]
|
||||
|
||||
root = self.parse_xml(self.xml_path('Training Level Requirements.xml'))
|
||||
|
||||
for child in root:
|
||||
try:
|
||||
item = child.find('Item').text.split(".")
|
||||
obj, created = models.TrainingLevelRequirement.objects.update_or_create(
|
||||
level=models.TrainingLevel.objects.get(
|
||||
pk=int(
|
||||
child.find('Level').text)), item=models.TrainingItem.objects.get(
|
||||
active=True, reference_number=item[1], category=models.TrainingCategory.objects.get(
|
||||
reference_number=item[0])), depth=int(
|
||||
child.find('Depth').text))
|
||||
|
||||
if created:
|
||||
tally[1] += 1
|
||||
else:
|
||||
tally[0] += 1
|
||||
except models.TrainingItem.DoesNotExist:
|
||||
print("Item with number {} does not exist".format(item))
|
||||
except models.TrainingItem.MultipleObjectsReturned:
|
||||
print(models.TrainingItem.objects.filter(reference_number=item[1], category=models.TrainingCategory.objects.get(reference_number=item[0])))
|
||||
|
||||
print('TrainingLevelRequirements - Updated: {}, Created: {}'.format(tally[0], tally[1]))
|
||||
80
training/migrations/0001_initial.py
Normal file
80
training/migrations/0001_initial.py
Normal file
@@ -0,0 +1,80 @@
|
||||
# Generated by Django 3.1.5 on 2021-07-05 22:01
|
||||
|
||||
import RIGS.models
|
||||
import django.contrib.auth.models
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('RIGS', '0041_auto_20210302_1204'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='TrainingCategory',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('reference_number', models.CharField(max_length=3)),
|
||||
('name', models.CharField(max_length=50)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TrainingItem',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('reference_number', models.CharField(max_length=3)),
|
||||
('name', models.CharField(max_length=50)),
|
||||
('category', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='items', to='training.trainingcategory')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TrainingLevel',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('department', models.CharField(max_length=50, null=True)),
|
||||
('level', models.IntegerField(choices=[(0, 'Technical Assistant'), (1, 'Technician'), (2, 'Supervisor')])),
|
||||
],
|
||||
bases=(models.Model, RIGS.models.RevisionMixin),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Trainee',
|
||||
fields=[
|
||||
],
|
||||
options={
|
||||
'proxy': True,
|
||||
'indexes': [],
|
||||
'constraints': [],
|
||||
},
|
||||
bases=('RIGS.profile',),
|
||||
managers=[
|
||||
('objects', django.contrib.auth.models.UserManager()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TrainingLevelQualification',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('confirmed_on', models.DateTimeField()),
|
||||
('confirmed_by', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='confirmer', to='training.trainee')),
|
||||
('level', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='training.traininglevel')),
|
||||
('trainee', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='levels', to='training.trainee')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TrainingItemQualification',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('depth', models.IntegerField(choices=[(0, 'Training Started'), (1, 'Training Complete'), (2, 'Passed Out')])),
|
||||
('date', models.DateField()),
|
||||
('notes', models.TextField(blank=True)),
|
||||
('item', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='training.trainingitem')),
|
||||
('supervisor', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='qualifications_granted', to='training.trainee')),
|
||||
('trainee', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='qualifications_obtained', to='training.trainee')),
|
||||
],
|
||||
),
|
||||
]
|
||||
42
training/migrations/0002_auto_20210706_0053.py
Normal file
42
training/migrations/0002_auto_20210706_0053.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# Generated by Django 3.1.5 on 2021-07-05 23:53
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('training', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='trainingcategory',
|
||||
options={'verbose_name_plural': 'Training Categories'},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='traininglevel',
|
||||
name='description',
|
||||
field=models.CharField(blank=True, max_length=120),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='traininglevel',
|
||||
name='prerequisite_levels',
|
||||
field=models.ManyToManyField(blank=True, related_name='prerequisites', to='training.TrainingLevel'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='traininglevel',
|
||||
name='department',
|
||||
field=models.IntegerField(choices=[(0, 'Sound'), (1, 'Lighting'), (2, 'Power'), (3, 'Rigging'), (4, 'Haulage')], null=True),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TrainingLevelRequirement',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('depth', models.IntegerField(verbose_name=((0, 'Training Started'), (1, 'Training Complete'), (2, 'Passed Out')))),
|
||||
('item', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='training.trainingitem')),
|
||||
('level', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, related_name='requirements', to='training.traininglevel')),
|
||||
],
|
||||
),
|
||||
]
|
||||
24
training/migrations/0003_auto_20210716_0150.py
Normal file
24
training/migrations/0003_auto_20210716_0150.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Generated by Django 3.1.5 on 2021-07-16 00:50
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('training', '0002_auto_20210706_0053'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='traininglevelqualification',
|
||||
name='confirmed_by',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.RESTRICT, related_name='confirmer', to='training.trainee'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='traininglevelqualification',
|
||||
name='confirmed_on',
|
||||
field=models.DateTimeField(null=True),
|
||||
),
|
||||
]
|
||||
21
training/migrations/0004_auto_20210819_1808.py
Normal file
21
training/migrations/0004_auto_20210819_1808.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 3.1.7 on 2021-08-19 17:08
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('training', '0003_auto_20210716_0150'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name='trainingitemqualification',
|
||||
unique_together={('trainee', 'item', 'depth')},
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='traininglevelqualification',
|
||||
unique_together={('trainee', 'level')},
|
||||
),
|
||||
]
|
||||
17
training/migrations/0005_auto_20210819_1833.py
Normal file
17
training/migrations/0005_auto_20210819_1833.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 3.1.7 on 2021-08-19 17:33
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('training', '0004_auto_20210819_1808'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name='traininglevelrequirement',
|
||||
unique_together={('level', 'item')},
|
||||
),
|
||||
]
|
||||
23
training/migrations/0006_auto_20210903_2158.py
Normal file
23
training/migrations/0006_auto_20210903_2158.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.1.7 on 2021-09-03 20:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('training', '0005_auto_20210819_1833'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='traininglevel',
|
||||
name='icon',
|
||||
field=models.CharField(blank=True, max_length=20, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='traininglevelrequirement',
|
||||
name='depth',
|
||||
field=models.IntegerField(choices=[(0, 'Training Started'), (1, 'Training Complete'), (2, 'Passed Out')]),
|
||||
),
|
||||
]
|
||||
25
training/migrations/0007_auto_20210908_2043.py
Normal file
25
training/migrations/0007_auto_20210908_2043.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 3.1.13 on 2021-09-08 19:43
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('training', '0006_auto_20210903_2158'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='trainingitem',
|
||||
options={'ordering': ['category__reference_number', 'reference_number']},
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='trainingitem',
|
||||
unique_together={('reference_number', 'name', 'category')},
|
||||
),
|
||||
migrations.AlterOrderWithRespectTo(
|
||||
name='trainingitemqualification',
|
||||
order_with_respect_to='item',
|
||||
),
|
||||
]
|
||||
18
training/migrations/0008_trainingitem_active.py
Normal file
18
training/migrations/0008_trainingitem_active.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.1.13 on 2021-10-27 12:37
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('training', '0007_auto_20210908_2043'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='trainingitem',
|
||||
name='active',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
]
|
||||
22
training/migrations/0009_auto_20211221_1539.py
Normal file
22
training/migrations/0009_auto_20211221_1539.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 3.1.13 on 2021-12-21 15:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('training', '0008_trainingitem_active'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='trainingcategory',
|
||||
name='reference_number',
|
||||
field=models.CharField(max_length=3, unique=True),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='trainingitem',
|
||||
unique_together={('reference_number', 'active', 'category')},
|
||||
),
|
||||
]
|
||||
23
training/migrations/0010_auto_20211228_1144.py
Normal file
23
training/migrations/0010_auto_20211228_1144.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.1.13 on 2021-12-28 11:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('training', '0009_auto_20211221_1539'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='trainingcategory',
|
||||
name='reference_number',
|
||||
field=models.IntegerField(unique=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='trainingitem',
|
||||
name='reference_number',
|
||||
field=models.IntegerField(),
|
||||
),
|
||||
]
|
||||
0
training/migrations/__init__.py
Normal file
0
training/migrations/__init__.py
Normal file
259
training/models.py
Normal file
259
training/models.py
Normal file
@@ -0,0 +1,259 @@
|
||||
from django.db import models
|
||||
|
||||
from RIGS.models import RevisionMixin, Profile
|
||||
from reversion import revisions as reversion
|
||||
from django.urls import reverse
|
||||
|
||||
from django.utils.safestring import SafeData, mark_safe
|
||||
|
||||
# 'shim' overtop the profile model to neatly contain all training related fields etc
|
||||
|
||||
|
||||
@reversion.register # profile is already registered, but this triggers my custom versioning logic
|
||||
class Trainee(Profile, RevisionMixin):
|
||||
class Meta:
|
||||
proxy = True
|
||||
|
||||
# TODO remove levels that the user has a qualification in
|
||||
# FIXME use queryset
|
||||
def started_levels(self):
|
||||
return [level for level in TrainingLevel.objects.all() if level.percentage_complete(self) > 0]
|
||||
|
||||
def level_qualifications(self, only_confirmed=False):
|
||||
return self.levels.all().filter(confirmed_on__isnull=only_confirmed).select_related('level')
|
||||
|
||||
@property
|
||||
def is_supervisor(self):
|
||||
return self.level_qualifications(True) \
|
||||
.filter(level__gte=TrainingLevel.SUPERVISOR) \
|
||||
.exclude(level__department=TrainingLevel.HAULAGE) \
|
||||
.exclude(level__department__isnull=True).exists()
|
||||
|
||||
@property
|
||||
def is_driver(self):
|
||||
return self.level_qualifications(True).filter(level__department=TrainingLevel.HAULAGE).exists()
|
||||
|
||||
def get_records_of_depth(self, depth):
|
||||
return self.qualifications_obtained.filter(depth=depth).select_related('item', 'trainee', 'supervisor')
|
||||
|
||||
def is_user_qualified_in(self, item, required_depth):
|
||||
return self.qualifications_obtained.values('item', 'depth').filter(item=item).filter(depth__gte=required_depth).first() is not None # this is a somewhat ghetto version of get_or_none
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('trainee_detail', kwargs={'pk': self.pk})
|
||||
|
||||
|
||||
class TrainingCategory(models.Model):
|
||||
reference_number = models.IntegerField(unique=True)
|
||||
name = models.CharField(max_length=50)
|
||||
|
||||
def __str__(self):
|
||||
return "{}. {}".format(self.reference_number, self.name)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = 'Training Categories'
|
||||
|
||||
|
||||
class TrainingItem(models.Model):
|
||||
reference_number = models.IntegerField()
|
||||
category = models.ForeignKey('TrainingCategory', related_name='items', on_delete=models.RESTRICT)
|
||||
name = models.CharField(max_length=50)
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
@property
|
||||
def number(self):
|
||||
return "{}.{}".format(self.category.reference_number, self.reference_number)
|
||||
|
||||
def __str__(self):
|
||||
name = "{} {}".format(self.number, self.name)
|
||||
if not self.active:
|
||||
name += " (inactive)"
|
||||
return name
|
||||
|
||||
@staticmethod
|
||||
def user_has_qualification(item, user, depth):
|
||||
return user.qualifications_obtained.values('item', 'depth').filter(item=item, depth__gte=depth).exists()
|
||||
|
||||
class Meta:
|
||||
unique_together = ["reference_number", "active", "category"]
|
||||
ordering = ['category__reference_number', 'reference_number']
|
||||
|
||||
|
||||
class TrainingItemQualification(models.Model):
|
||||
STARTED = 0
|
||||
COMPLETE = 1
|
||||
PASSED_OUT = 2
|
||||
CHOICES = (
|
||||
(STARTED, 'Training Started'),
|
||||
(COMPLETE, 'Training Complete'),
|
||||
(PASSED_OUT, 'Passed Out'),
|
||||
)
|
||||
item = models.ForeignKey('TrainingItem', on_delete=models.RESTRICT)
|
||||
depth = models.IntegerField(choices=CHOICES)
|
||||
trainee = models.ForeignKey('Trainee', related_name='qualifications_obtained', on_delete=models.RESTRICT)
|
||||
date = models.DateField()
|
||||
# TODO Remember that some training is external. Support for making an organisation the trainer?
|
||||
supervisor = models.ForeignKey('Trainee', related_name='qualifications_granted', on_delete=models.RESTRICT)
|
||||
notes = models.TextField(blank=True)
|
||||
# TODO Maximum depth - some things stop at Complete and you can't be passed out in them
|
||||
|
||||
def __str__(self):
|
||||
return "{} in {} on {}".format(self.depth, self.item, self.date)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super().save()
|
||||
for level in TrainingLevel.objects.all(): # Mm yes efficiency FIXME
|
||||
if level.user_has_requirements(self.trainee):
|
||||
with reversion.create_revision():
|
||||
level_qualification = TrainingLevelQualification.objects.get_or_create(trainee=self.trainee, level=level)
|
||||
reversion.add_to_revision(self.trainee)
|
||||
|
||||
@classmethod
|
||||
def get_colour_from_depth(obj, depth):
|
||||
if depth == 0:
|
||||
return "warning"
|
||||
elif depth == 1:
|
||||
return "success"
|
||||
else:
|
||||
return "info"
|
||||
|
||||
class Meta:
|
||||
unique_together = ["trainee", "item", "depth"]
|
||||
order_with_respect_to = 'item'
|
||||
|
||||
|
||||
# Levels
|
||||
@reversion.register(follow=["requirements"])
|
||||
class TrainingLevel(models.Model, RevisionMixin):
|
||||
description = models.CharField(max_length=120, blank=True)
|
||||
TA = 0
|
||||
TECHNICIAN = 1
|
||||
SUPERVISOR = 2
|
||||
CHOICES = (
|
||||
(TA, 'Technical Assistant'),
|
||||
(TECHNICIAN, 'Technician'),
|
||||
(SUPERVISOR, 'Supervisor'),
|
||||
)
|
||||
SOUND = 0
|
||||
LIGHTING = 1
|
||||
POWER = 2
|
||||
RIGGING = 3
|
||||
HAULAGE = 4
|
||||
DEPARTMENTS = (
|
||||
(SOUND, 'Sound'),
|
||||
(LIGHTING, 'Lighting'),
|
||||
(POWER, 'Power'),
|
||||
(RIGGING, 'Rigging'),
|
||||
(HAULAGE, 'Haulage'),
|
||||
)
|
||||
department = models.IntegerField(choices=DEPARTMENTS, null=True) # N.B. Technical Assistant does not have a department
|
||||
level = models.IntegerField(choices=CHOICES)
|
||||
prerequisite_levels = models.ManyToManyField('self', related_name='prerequisites', symmetrical=False, blank=True)
|
||||
icon = models.CharField(null=True, blank=True, max_length=20)
|
||||
|
||||
@property
|
||||
def department_colour(self):
|
||||
if self.department == self.SOUND:
|
||||
return "info"
|
||||
elif self.department == self.LIGHTING:
|
||||
return "dark"
|
||||
elif self.department == self.POWER:
|
||||
return "danger"
|
||||
elif self.department == self.RIGGING:
|
||||
return "warning"
|
||||
elif self.department == self.HAULAGE:
|
||||
return "light"
|
||||
else:
|
||||
return "primary"
|
||||
|
||||
def get_requirements_of_depth(self, depth):
|
||||
return self.requirements.filter(depth=depth)
|
||||
|
||||
@property
|
||||
def is_common_competencies(self):
|
||||
return self.department is None and self.level > 0
|
||||
|
||||
@property
|
||||
def started_requirements(self):
|
||||
return self.get_requirements_of_depth(TrainingItemQualification.STARTED)
|
||||
|
||||
@property
|
||||
def complete_requirements(self):
|
||||
return self.get_requirements_of_depth(TrainingItemQualification.COMPLETE)
|
||||
|
||||
@property
|
||||
def passed_out_requirements(self):
|
||||
return self.get_requirements_of_depth(TrainingItemQualification.PASSED_OUT)
|
||||
|
||||
def percentage_complete(self, user):
|
||||
needed_qualifications = self.requirements.all().select_related('item')
|
||||
relavant_qualifications = 0.0
|
||||
# TODO Efficiency...
|
||||
for req in needed_qualifications:
|
||||
if user.is_user_qualified_in(req.item, req.depth):
|
||||
relavant_qualifications += 1.0
|
||||
|
||||
if len(needed_qualifications) > 0:
|
||||
return int(relavant_qualifications / float(len(needed_qualifications)) * 100)
|
||||
else:
|
||||
return 0
|
||||
|
||||
def user_has_requirements(self, user):
|
||||
return all(TrainingItem.user_has_qualification(req.item, user, req.depth) for req in self.requirements.all())
|
||||
|
||||
def __str__(self):
|
||||
if self.department is None:
|
||||
if self.level == self.TA:
|
||||
return self.get_level_display()
|
||||
else:
|
||||
return "{} Common Competencies".format(self.get_level_display())
|
||||
else:
|
||||
return "{} {}".format(self.get_department_display(), self.get_level_display())
|
||||
|
||||
@property
|
||||
def activity_feed_string(self):
|
||||
return str(self)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('level_detail', kwargs={'pk': self.pk})
|
||||
|
||||
|
||||
@reversion.register
|
||||
class TrainingLevelRequirement(models.Model, RevisionMixin):
|
||||
level = models.ForeignKey('TrainingLevel', related_name='requirements', on_delete=models.RESTRICT)
|
||||
item = models.ForeignKey('TrainingItem', on_delete=models.RESTRICT)
|
||||
depth = models.IntegerField(choices=TrainingItemQualification.CHOICES)
|
||||
|
||||
reversion_hide = True
|
||||
|
||||
def __str__(self):
|
||||
return "{} in {}".format(TrainingItemQualification.CHOICES[self.depth][1], self.item)
|
||||
|
||||
class Meta:
|
||||
unique_together = ["level", "item"]
|
||||
|
||||
|
||||
@reversion.register
|
||||
class TrainingLevelQualification(models.Model, RevisionMixin):
|
||||
trainee = models.ForeignKey('Trainee', related_name='levels', on_delete=models.RESTRICT)
|
||||
level = models.ForeignKey('TrainingLevel', on_delete=models.RESTRICT)
|
||||
confirmed_on = models.DateTimeField(null=True)
|
||||
confirmed_by = models.ForeignKey('Trainee', related_name='confirmer', on_delete=models.RESTRICT, null=True)
|
||||
|
||||
reversion_hide = True
|
||||
|
||||
@property
|
||||
def get_icon(self):
|
||||
if self.level.icon is not None:
|
||||
icon = "<span class='fas fa-{}'></span>".format(self.level.icon)
|
||||
else:
|
||||
icon = "".join([w[0] for w in str(self.level).split()])
|
||||
return mark_safe("<span class='badge badge-{} badge-pill' data-toggle='tooltip' title='{}'>{}</span>".format(self.level.department_colour, self.level, icon))
|
||||
|
||||
def __str__(self):
|
||||
if self.level.is_common_competencies:
|
||||
return "{} is qualified in the {}".format(self.trainee, self.level)
|
||||
return "{} is qualified as a {}".format(self.trainee, self.level)
|
||||
|
||||
class Meta:
|
||||
unique_together = ["trainee", "level"]
|
||||
47
training/templates/add_level_requirement.html
Normal file
47
training/templates/add_level_requirement.html
Normal file
@@ -0,0 +1,47 @@
|
||||
{% extends request.is_ajax|yesno:'base_ajax.html,base_training.html' %}
|
||||
|
||||
{% load static %}
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'css/selects.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/selects.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if form.errors %}
|
||||
{% include 'form_errors.html' %}
|
||||
{% endif %}
|
||||
<form id="requirement-form" action="{{ form.action|default:request.path }}" method="post">{% csrf_token %}
|
||||
{% render_field form.level|attr:'hidden' value=form.level.initial %}
|
||||
<div class="form-group form-row">
|
||||
<label for="item_id" class="col-sm-2 col-form-label">Item</label>
|
||||
<select name="item" id="item_id" class="form-control selectpicker custom-select col-sm-10" data-live-search="true" data-sourceurl="{% url 'api_secure' model='training_item' %}" required>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
<label for="depth" class="col-sm-2 col-form-label">Depth</label>
|
||||
{% render_field form.depth|add_class:'form-control col-sm'|attr:'required' %}
|
||||
</div>
|
||||
{% if not request.is_ajax %}
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}
|
||||
<div class="col-sm-12 text-right pr-0">
|
||||
<button type="submit" class="btn btn-primary" title="Save" form="requirement-form"><span class="fas fa-save align-middle"></span> <span class="d-none d-sm-inline align-middle">Save</span></button>
|
||||
</div>
|
||||
{% endblock %}
|
||||
40
training/templates/base_training.html
Normal file
40
training/templates/base_training.html
Normal file
@@ -0,0 +1,40 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% load static %}
|
||||
|
||||
{% block titleheader %}
|
||||
<a class="navbar-brand" href="{% url 'trainee_list' %}">Training</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block titleelements %}
|
||||
{% if user.is_authenticated %}
|
||||
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle text-info" href="#" id="navbarDropdownMy" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
My Record
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownMy">
|
||||
<a class="dropdown-item" href="{% url 'trainee_detail' %}"><span class="fas fa-eye"></span>
|
||||
Overview</a>
|
||||
<a class="dropdown-item" href="{% url 'trainee_item_detail' request.user.pk %}"><span class="fas fa-list"></span>
|
||||
Item Detail</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownLists" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Lists
|
||||
</a>
|
||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownLists">
|
||||
<a class="dropdown-item" href="{% url 'trainee_list' %}"><span class="fas fa-users"></span> Trainee List</a>
|
||||
<a class="dropdown-item" href="{% url 'level_list' %}"><span class="fas fa-layer-group"></span> Level List</a>
|
||||
<a class="dropdown-item" href="{% url 'item_list' %}"><span class="fas fa-sitemap"></span> Item List</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item"><a class="nav-link" href="{% url 'training_activity_table' %}"><span class="fas fa-random"></span> Recent Changes</a></li>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block titleelements_right %}
|
||||
{% include 'partials/search.html' %}
|
||||
{% include 'partials/navbar_user.html' %}
|
||||
{% endblock %}
|
||||
71
training/templates/edit_training_record.html
Normal file
71
training/templates/edit_training_record.html
Normal file
@@ -0,0 +1,71 @@
|
||||
{% extends request.is_ajax|yesno:'base_ajax.html,base_training.html' %}
|
||||
|
||||
{% load static %}
|
||||
{% load widget_tweaks %}
|
||||
{% load button from filters %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'css/selects.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
<script src="{% static 'js/selects.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
<script>
|
||||
//Has to be done here or the pickers disappear on modal error
|
||||
$('document').ready(function(){
|
||||
$(document).find(".selectpicker").selectpicker().each(function(){initPicker($(this))});
|
||||
});
|
||||
</script>
|
||||
<form role="form" action="{{ form.action|default:request.path }}" method="POST" id="add_record_form">
|
||||
{% include 'form_errors.html' %}
|
||||
{% csrf_token %}
|
||||
{% render_field form.trainee|attr:'hidden' value=form.trainee.initial %}
|
||||
<div class="form-group form-row">
|
||||
<label for="item_id" class="col-sm-2 col-form-label">Item</label>
|
||||
<select name="item" id="item_id" class="form-control selectpicker custom-select col-sm-4" data-live-search="true" data-sourceurl="{% url 'api_secure' model='training_item' %}?fields=reference_number,name&filters=active" required>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
<label for="depth" class="col-sm-2 col-form-label">Depth</label>
|
||||
{% render_field form.depth|add_class:'form-control custom-select col-sm-4' %}
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
<label for="supervisor" class="col-sm-2 col-form-label">Supervisor</label>
|
||||
<select name="supervisor" id="supervisor_id" class="form-control selectpicker custom-select col-sm-10" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials" required>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
<label for="date" class="col-sm-2 col-form-label">Training Date</label>
|
||||
<div class="col-sm-8">
|
||||
{% render_field form.date|add_class:'form-control'|attr:'type="date"' value=form.date.initial %}
|
||||
</div>
|
||||
<button class="btn btn-info col-sm-2" onclick="var date = new Date(); $('#id_date').val([date.getFullYear(), ('0' + (date.getMonth()+1)).slice(-2), ('0' + date.getDate()).slice(-2)].join('-'))" tabindex="-1" type="button">Today</button>
|
||||
</div>
|
||||
<div class="form-group form-row">
|
||||
<label for="item_description" class="col-sm-2 col-form-label">Notes</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea type="text" placeholder="Notes" class="form-control"
|
||||
id="notes" rows="3"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
{% if not request.is_ajax %}
|
||||
<div class="col-sm-12 text-right pr-0">
|
||||
{% button 'submit' %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}
|
||||
<div class="col-sm-12 text-right pr-0">
|
||||
<button type="submit" class="btn btn-primary" title="Save" form="add_record_form"><span class="fas fa-save align-middle"></span> <span class="d-none d-sm-inline align-middle">Save</span></button>
|
||||
</div>
|
||||
{% endblock %}
|
||||
28
training/templates/item_list.html
Normal file
28
training/templates/item_list.html
Normal file
@@ -0,0 +1,28 @@
|
||||
{% extends 'base_training.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div id="accordion">
|
||||
{% for category in categories %}
|
||||
<div class="card">
|
||||
<div class="card-header" id="heading{{forloop.counter}}">
|
||||
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapse{{forloop.counter}}" aria-expanded="true" aria-controls="collapse{{forloop.counter}}">
|
||||
{{ category }}
|
||||
</button>
|
||||
</div>
|
||||
<div id="collapse{{forloop.counter}}" class="collapse" aria-labelledby="heading{{forloop.counter}}" data-parent="#accordion">
|
||||
<div class="card-body">
|
||||
<div class="list-group list-group-flush">
|
||||
{% for item in category.items.all %}
|
||||
{% if item.active %}
|
||||
<li class="list-group-item">{{ item }}</li>
|
||||
{% elif request.user.is_superuser %}
|
||||
<li class="list-group-item text-warning">{{ item }} (inactive)</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
127
training/templates/level_detail.html
Normal file
127
training/templates/level_detail.html
Normal file
@@ -0,0 +1,127 @@
|
||||
{% extends 'base_training.html' %}
|
||||
|
||||
{% load user_has_qualification from tags %}
|
||||
{% load user_level_if_present from tags %}
|
||||
{% load markdown_tags %}
|
||||
{% load static %}
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'css/selects.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/selects.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
<script>
|
||||
$('document').ready(function(){
|
||||
$('#requirement_button').click(function (e) {
|
||||
e.preventDefault();
|
||||
var url = $(this).attr("href");
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: function(){
|
||||
$link = $(this);
|
||||
// Anti modal inception
|
||||
if ($link.parents('#modal').length === 0) {
|
||||
modaltarget = $link.data('target');
|
||||
modalobject = "";
|
||||
$('#modal').load(url, function (e) {
|
||||
$('#modal').modal();
|
||||
$(".selectpicker").selectpicker().each(function(){initPicker($(this))});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if request.user.is_supervisor or perms.training.change_traininglevel %}
|
||||
<div class="col-sm-12 text-right pr-0">
|
||||
<a type="button" class="btn btn-success mb-3" href="{% url 'add_requirement' pk=object.pk %}" id="requirement_button">
|
||||
<span class="fas fa-plus"></span> Add New Requirement
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="card mb-3">
|
||||
<h4 class="card-header">Description</h4>
|
||||
<div class="card-body">
|
||||
<p>{{ object.description|markdown }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h4 class="card-header">Level Requirements</h4>
|
||||
<table class="table card-body">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" class="table-warning">Training Started</th>
|
||||
<th scope="col" class="table-success">Training Complete</th>
|
||||
<th scope="col" class="table-info">Passed Out</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><ul class="list-unstyled">{% for req in object.started_requirements %}<li>{{ req.item }} {% user_has_qualification request.user req.item 0 %} {% if request.user.is_supervisor or perms.training.change_traininglevel %}<a type="button" class="btn btn-danger btn-sm" href="{% url 'remove_requirement' pk=req.pk %}"><span class="fas fa-times-circle"></span></a>{% endif %}</li>{% endfor %}</ul></td>
|
||||
<td><ul class="list-unstyled">{% for req in object.complete_requirements %}<li>{{ req.item }} {% user_has_qualification request.user req.item 1 %} {% if request.user.is_supervisor or perms.training.change_traininglevel %}<a type="button" class="btn btn-danger btn-sm" href="{% url 'remove_requirement' pk=req.pk %}"><span class="fas fa-times-circle"></span></a>{% endif %}</li>{% endfor %}</ul></td>
|
||||
<td><ul class="list-unstyled">{% for req in object.passed_out_requirements %}<li>{{ req.item }} {% user_has_qualification request.user req.item 2 %} {% if request.user.is_supervisor or perms.training.change_traininglevel %}<a type="button" class="btn btn-danger btn-sm" href="{% url 'remove_requirement' pk=req.pk %}"><span class="fas fa-times-circle"></span></a>{%endif%}</li>{% endfor %}</ul></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h4 class="card-header">Prerequisite Levels:</h4>
|
||||
<div class="card-body">
|
||||
<ul>
|
||||
{% for level in object.prerequisite_levels.all %}
|
||||
{% user_level_if_present request.user level as level_qualification %}
|
||||
<li><a href="{{level.get_absolute_url}}">{{ level }}</a> <span class="fas {% if level_qualification %}text-success fa-check{% if level_qualification.confirmed_by is not None %}-double{% endif %}{% else %}fa-hourglass-start text-warning{%endif%}"></span></li>
|
||||
{% for nested_level in level.prerequisite_levels.all %}
|
||||
{% user_level_if_present request.user nested_level as nested_level_qualification %}
|
||||
<ul>
|
||||
<li><a href="{{nested_level.get_absolute_url}}">{{ nested_level }}</a> <span class="fas {% if nested_level_qualification %}text-success fa-check{% if nested_level_qualification.confirmed_by is not None %}-double{% endif %}{% else %}fa-hourglass-start text-warning{%endif%}"></span></li>
|
||||
</ul>
|
||||
{% endfor %}
|
||||
{% empty %}
|
||||
None
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card mb-3 d-none d-md-block">
|
||||
<h4 class="card-header">Users with this level</h4>
|
||||
<div class="card-body">
|
||||
<table class="table table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Person</th>
|
||||
<th scope="col">Confirmed?</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user in users_with %}
|
||||
{% user_level_if_present user object as level_qualification %}
|
||||
<tr {% if not level_qualification.confirmed_on %}style="border-style: dashed; opacity: 80%"{%endif%}>
|
||||
<td><img src="{{user.profile_picture}}" style="width: 50px" class="img-thumbnail"/> {{user}}</td>
|
||||
<td>{% if level_qualification.confirmed_on %}<p class="card-text"><small>Qualified on {{ level_qualification.confirmed_on }}</small></p>{%else%}Unconfirmed{%endif%}</td>
|
||||
<td><a href="{% url 'profile_detail' user.pk %}" class="btn btn-primary btn-sm"><span class="fas fa-user"></span> View Profile</a></div></td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
Nobody here but us chickens... <span class="fas fa-egg text-warning"></span>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col text-right">
|
||||
{% include 'partials/last_edited.html' with target="traininglevel_history" %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
85
training/templates/level_list.html
Normal file
85
training/templates/level_list.html
Normal file
@@ -0,0 +1,85 @@
|
||||
{% extends 'base_training.html' %}
|
||||
|
||||
{% load markdown_tags %}
|
||||
{% load get_supervisor from tags %}
|
||||
|
||||
{% block css %}
|
||||
<style>
|
||||
.tree ul {
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.tree li {
|
||||
list-style-type: none;
|
||||
margin:10px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tree li::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top:-7px;
|
||||
left:-20px;
|
||||
border-left: 1px solid #ccc;
|
||||
border-bottom:1px solid #ccc;
|
||||
border-radius:0 0 0 0px;
|
||||
width:20px;
|
||||
height:15px;
|
||||
}
|
||||
|
||||
.tree li::after {
|
||||
position:absolute;
|
||||
content:"";
|
||||
top:8px;
|
||||
left:-20px;
|
||||
border-left: 1px solid #ccc;
|
||||
border-top:1px solid #ccc;
|
||||
border-radius:0px 0 0 0;
|
||||
width:20px;
|
||||
height:100%;
|
||||
}
|
||||
|
||||
.tree li:last-child::after {
|
||||
display:none;
|
||||
}
|
||||
|
||||
.tree li:last-child:before{
|
||||
border-radius: 0 0 0 5px;
|
||||
}
|
||||
|
||||
ul.tree>li:first-child::before {
|
||||
display:none;
|
||||
}
|
||||
|
||||
ul.tree>li:first-child::after {
|
||||
border-radius:5px 0 0 0;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="alert alert-info" role="alert">
|
||||
<p>Please Note:</p>
|
||||
<ul>
|
||||
<li>Technical Assistant status is automatically valid when the item requirements are met.</li>
|
||||
<li>Technician status is also automatic, but notification of status should be made at the next general meeting, at which point 'approval' should be granted on the system.</li>
|
||||
<li>Supervisor status is <em>not automatically valid</em> and until signed off at a general meeting, does not count.</li>
|
||||
</ul>
|
||||
<sup>Correct as of 3rd September 2021, check the Training Policy.</sup>
|
||||
</div>
|
||||
<ul class="tree">
|
||||
<li><div class="card"><div class="card-header">{{ta}}</div><div class="card-body">{{ta.description|markdown}}</div></div>
|
||||
<ul>
|
||||
{% for level in tech %}
|
||||
<li><div class="card"><div class="card-header"><a href="{{level.get_absolute_url}}">{{level}}</a></div><div class="card-body">{{level.description|markdown}}</div></div>
|
||||
<ul>
|
||||
{% with level|get_supervisor as super %}
|
||||
<li><div class="card"><div class="card-header"><a href="{{super.get_absolute_url}}">{{super}}</a></div><div class="card-body">{{super.description|markdown}}</div></div></li>
|
||||
{% endwith %}
|
||||
</ul>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
5
training/templates/partials/add_qualification.html
Normal file
5
training/templates/partials/add_qualification.html
Normal file
@@ -0,0 +1,5 @@
|
||||
{% if request.user.as_trainee.is_supervisor or perms.training.add_trainingitemqualification %}
|
||||
<a type="button" class="btn btn-success" href="{% url 'add_qualification' object.pk %}" id="add_record">
|
||||
<span class="fas fa-plus"></span> Add New Training Record
|
||||
</a>
|
||||
{% endif %}
|
||||
54
training/templates/session_log_form.html
Normal file
54
training/templates/session_log_form.html
Normal file
@@ -0,0 +1,54 @@
|
||||
{% extends 'base_rigs.html' %}
|
||||
|
||||
{% load static %}
|
||||
{% load button from filters %}
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'css/selects.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/selects.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ block.super }}
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
<script src="{% static 'js/interaction.js' %}"></script>
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<form class="form">
|
||||
<h3>People</h3>
|
||||
<div class="form-group">
|
||||
<label for="selectpicker">Select Supervisor</label>
|
||||
<select name="supervisor" id="supervisor_id" class="form-control selectpicker custom-select" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials">
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="selectpicker">Select Attendees</label>
|
||||
<select multiple name="attendees" id="attendees_id" class="form-control selectpicker custom-select" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials">
|
||||
</select>
|
||||
</div>
|
||||
<h3>Training Items</h3>
|
||||
<div class="row">
|
||||
{% for depth in depths %}
|
||||
<div class="col">
|
||||
<h4>{{ depth.1 }}</h4>
|
||||
<select multiple name="{{ depth.0 }}" id="{{ depth.0 }}_id" class="form-control selectpicker custom-select" data-live-search="true" data-sourceurl="{% url 'api_secure' model='training_item' %}">
|
||||
</select>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="col-sm-12 text-right my-3">
|
||||
{% button 'submit' %}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
91
training/templates/trainee_detail.html
Normal file
91
training/templates/trainee_detail.html
Normal file
@@ -0,0 +1,91 @@
|
||||
{% extends 'base_training.html' %}
|
||||
|
||||
{% load static %}
|
||||
{% load percentage_complete from tags %}
|
||||
{% load markdown_tags %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'css/selects.css' %}"/>
|
||||
{% endblock %}
|
||||
|
||||
{% block preload_js %}
|
||||
<script src="{% static 'js/selects.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
<script>
|
||||
$('document').ready(function(){
|
||||
$('#add_record').click(function (e) {
|
||||
e.preventDefault();
|
||||
var url = $(this).attr("href");
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: function(){
|
||||
$link = $(this);
|
||||
// Anti modal inception
|
||||
if ($link.parents('#modal').length === 0) {
|
||||
modaltarget = $link.data('target');
|
||||
modalobject = "";
|
||||
$('#modal').load(url, function (e) {
|
||||
$('#modal').modal();
|
||||
//$(".selectpicker").selectpicker().each(function(){initPicker($(this))});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-sm-12 text-right">
|
||||
{% include 'partials/add_qualification.html' %}
|
||||
<a href="{% url 'trainee_item_detail' object.pk %}" class="btn btn-info"><span class="fas fa-info-circle"></span> View Detailed Record</a><br/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<h2 class="col-12">Training Levels</h2>
|
||||
<ul class="list-group col-12">
|
||||
{% for qual in completed_levels %}
|
||||
<li class="list-group-item">
|
||||
<a href="{% url 'level_detail' qual.level.pk %}">{{ qual.level }}</a>
|
||||
{% if qual.confirmed_on is None %}
|
||||
{% if request.user.pk != object.pk and request.user.is_supervisor %}
|
||||
<span class="badge badge-warning">Awaiting Confirmation</span> <a class="btn btn-info" href="{% url 'confirm_level' object.pk qual.level.pk %}">Confirm</a>
|
||||
{% else %}
|
||||
<button class="btn btn-warning" disabled>Awaiting Confirmation</button>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<button class="btn btn-success active">Confirmed <small>by {{ qual.confirmed_by|default:'System' }}</small></button>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% empty %}
|
||||
<div class="alert alert-warning mx-auto">No qualifications in any levels yet...did someone forget to fill out the paperwork?</div>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="card-columns">
|
||||
{% for level in started_levels %}
|
||||
{% percentage_complete level object as completion %}
|
||||
<div class="card my-3 border-warning">
|
||||
<h3 class="card-header"><a href="{{ level.get_absolute_url }}">{{ level }}</a></h3>
|
||||
<div class="card-body">
|
||||
{{ level.description|markdown }}
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div class="progress">
|
||||
<div class="progress-bar progress-bar-striped" role="progressbar" style="width: {{completion}}%" aria-valuenow="{{completion}}" aria-valuemin="0" aria-valuemax="100">{{completion}}% complete</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col text-right">
|
||||
{% include 'partials/last_edited.html' with target="trainee_history" %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
42
training/templates/trainee_item_list.html
Normal file
42
training/templates/trainee_item_list.html
Normal file
@@ -0,0 +1,42 @@
|
||||
{% extends 'base_training.html' %}
|
||||
|
||||
{% load url_replace from filters %}
|
||||
{% load paginator from filters %}
|
||||
{% load linkornone from filters %}
|
||||
{% load button from filters %}
|
||||
{% load colour_from_depth from tags %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Training Item</th>
|
||||
<th>Depth</th>
|
||||
<th>Date</th>
|
||||
<th>Supervisor</th>
|
||||
<th>Notes</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for object in object_list %}
|
||||
<tr id="row_item" {% if request.user.is_superuser and not object.item.active %}class="text-warning"{%endif%}>
|
||||
<th scope="row" class="align-middle" id="cell_name">{{ object.item }}</th>
|
||||
<td class="table-{% colour_from_depth object.depth %}">{{ object.get_depth_display }}</td>
|
||||
<td>{{ object.date }}</td>
|
||||
<td><a href="{{ object.supervisor.get_absolute_url}}">{{ object.supervisor }}</a></td>
|
||||
<td>{{ object.notes }}</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr class="table-warning">
|
||||
<td colspan="6" class="text-center">Nothing found</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
58
training/templates/trainee_list.html
Normal file
58
training/templates/trainee_list.html
Normal file
@@ -0,0 +1,58 @@
|
||||
{% extends 'base_training.html' %}
|
||||
|
||||
{% load url_replace from filters %}
|
||||
{% load orderby from filters %}
|
||||
{% load paginator from filters %}
|
||||
{% load linkornone from filters %}
|
||||
{% load button from filters %}
|
||||
{% load get_levels_of_depth from tags %}
|
||||
|
||||
{% block js %}
|
||||
<script>
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% include 'partials/list_search.html' %}
|
||||
<div class="row pt-2">
|
||||
<div class="col">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Name</th>
|
||||
<th>Van Driver?</th>
|
||||
<th>Technician?</th>
|
||||
<th>Supervisor?</th>
|
||||
<th>Qualification Count</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for object in object_list %}
|
||||
<tr id="row_item">
|
||||
<th scope="row" class="align-middle" id="cell_name"><a href="{% url 'trainee_detail' object.pk %}">{{ object.name }} {% if request.user.pk == object.pk %}<span class="fas fa-user text-success"></span>{%endif%}</a></th>
|
||||
<td {% if object.is_driver %}class="table-success"{%endif%}>{{ object.is_driver|yesno|title }}</td>
|
||||
<td>{% for level in object|get_levels_of_depth:1 %}{{ level.get_icon }}{%empty%}No{%endfor%}</td>
|
||||
<td {% if object.is_supervisor %}class="table-success"{%endif%}>{{ object.is_supervisor|yesno|title }}</td>
|
||||
<td>{{ object.num_qualifications }}</td>
|
||||
<td style="white-space: nowrap">
|
||||
<a class="btn btn-info" href="{% url 'trainee_detail' pk=object.pk %}"><span class="fas fa-eye"></span> View Training Record</a>
|
||||
<a href="{% url 'trainee_item_detail' pk=object.pk %}" class="btn btn-info"><span class="fas fa-info-circle"></span> View Detailed Record</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr class="table-warning">
|
||||
<td colspan="6" class="text-center">Nothing found</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% paginator %}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,16 @@
|
||||
{% extends 'base_training.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<p>Are you sure you wish to delete {{ page_title }}</p>
|
||||
|
||||
<div class="text-right">
|
||||
<form action="{{ action_link }}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="next" value="{% url 'level_detail' object.level.pk %}"/>
|
||||
<input type="submit" value="Yes" class="btn btn-danger col-sm-1"/>
|
||||
<a href="{% url 'level_detail' object.level.pk %}" class="btn btn-success col-sm-1">No</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
0
training/templatetags/__init__.py
Normal file
0
training/templatetags/__init__.py
Normal file
42
training/templatetags/tags.py
Normal file
42
training/templatetags/tags.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from django import forms
|
||||
from django import template
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import SafeData, mark_safe
|
||||
from django.utils.text import normalize_newlines
|
||||
|
||||
from training import models
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def user_has_qualification(user, item, depth):
|
||||
if models.TrainingItem.user_has_qualification(item, user, depth) is not None:
|
||||
return mark_safe("<span class='fas fa-check text-success'></span>")
|
||||
else:
|
||||
return mark_safe("<span class='fas fa-hourglass-start text-warning'></span>")
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def user_level_if_present(user, level):
|
||||
return models.TrainingLevelQualification.objects.filter(trainee=user, level=level).first()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def percentage_complete(level, user):
|
||||
return level.percentage_complete(user)
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def colour_from_depth(depth):
|
||||
return models.TrainingItemQualification.get_colour_from_depth(depth)
|
||||
|
||||
|
||||
@register.filter
|
||||
def get_supervisor(tech):
|
||||
return models.TrainingLevel.objects.get(department=tech.department, level=models.TrainingLevel.SUPERVISOR)
|
||||
|
||||
|
||||
@register.filter
|
||||
def get_levels_of_depth(trainee, level):
|
||||
return trainee.level_qualifications(True).filter(level__level=level)
|
||||
24
training/urls.py
Normal file
24
training/urls.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from django.urls import path
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from PyRIGS.decorators import permission_required_with_403
|
||||
|
||||
from training import views
|
||||
|
||||
urlpatterns = [
|
||||
path('items/', login_required(views.ItemList.as_view()), name='item_list'),
|
||||
path('trainee/list/', login_required(views.TraineeList.as_view()), name='trainee_list'),
|
||||
path('trainee/', login_required(views.TraineeDetail.as_view()), name='trainee_detail'),
|
||||
path('trainee/<int:pk>/',
|
||||
permission_required_with_403('RIGS.view_profile')(views.TraineeDetail.as_view()),
|
||||
name='trainee_detail'),
|
||||
path('trainee/<int:pk>/add_qualification/', login_required(views.AddQualification.as_view()),
|
||||
name='add_qualification'),
|
||||
path('session/', login_required(views.SessionLog.as_view()), name='session_log'),
|
||||
path('levels/', login_required(views.LevelList.as_view()), name='level_list'),
|
||||
path('level/<int:pk>/', login_required(views.LevelDetail.as_view()), name='level_detail'),
|
||||
path('level/<int:pk>/add_requirement/', login_required(views.AddLevelRequirement.as_view()), name='add_requirement'),
|
||||
path('level/remove_requirement/<int:pk>/', login_required(views.RemoveRequirement.as_view()), name='remove_requirement'),
|
||||
path('trainee/<int:pk>/level/<int:level_pk>/confirm', login_required(views.ConfirmLevel.as_view()), name='confirm_level'),
|
||||
path('trainee/<int:pk>/item_record', login_required(views.TraineeItemDetail.as_view()), name='trainee_item_detail'),
|
||||
]
|
||||
198
training/views.py
Normal file
198
training/views.py
Normal file
@@ -0,0 +1,198 @@
|
||||
import reversion
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse_lazy
|
||||
from django.views import generic
|
||||
from PyRIGS.views import OEmbedView, is_ajax, ModalURLMixin
|
||||
from training import models, forms
|
||||
from django.utils import timezone
|
||||
from django.db import transaction
|
||||
from django.db.models import Q, Count, OuterRef, F, Subquery, Window
|
||||
|
||||
from users import views
|
||||
|
||||
|
||||
class ItemList(generic.ListView):
|
||||
template_name = "item_list.html"
|
||||
model = models.TrainingItem
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ItemList, self).get_context_data(**kwargs)
|
||||
context["page_title"] = "Training Items"
|
||||
context["categories"] = models.TrainingCategory.objects.all()
|
||||
return context
|
||||
|
||||
|
||||
class TraineeDetail(views.ProfileDetail):
|
||||
template_name = "trainee_detail.html"
|
||||
model = models.Trainee
|
||||
|
||||
def get_queryset(self):
|
||||
return self.model.objects.prefetch_related('qualifications_obtained')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(TraineeDetail, self).get_context_data(**kwargs)
|
||||
if self.request.user.pk == self.object.pk:
|
||||
context["page_title"] = "Your Training Record"
|
||||
else:
|
||||
context["page_title"] = "{}'s Training Record".format(self.object.first_name + " " + self.object.last_name)
|
||||
context["started_levels"] = self.object.started_levels()
|
||||
context["completed_levels"] = self.object.level_qualifications().select_related('level')
|
||||
context["categories"] = models.TrainingCategory.objects.all().prefetch_related('items')
|
||||
return context
|
||||
|
||||
|
||||
class TraineeItemDetail(generic.ListView):
|
||||
model = models.TrainingItemQualification
|
||||
template_name = 'trainee_item_list.html'
|
||||
|
||||
def get_queryset(self):
|
||||
return models.Trainee.objects.get(pk=self.kwargs['pk']).qualifications_obtained.all().order_by('-date').select_related('item', 'trainee', 'supervisor', 'item__category')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_title"] = "Detailed Training Record for {}".format(models.Trainee.objects.get(pk=self.kwargs['pk']))
|
||||
return context
|
||||
|
||||
|
||||
class LevelDetail(generic.DetailView):
|
||||
template_name = "level_detail.html"
|
||||
model = models.TrainingLevel
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_title"] = "Training Level {} <span class='badge badge-{} badge-pill'><span class='fas fa-{}'></span></span>".format(self.object, self.object.department_colour, self.object.icon)
|
||||
context["users_with"] = map(lambda qual: qual.trainee, models.TrainingLevelQualification.objects.filter(level=self.object))
|
||||
return context
|
||||
|
||||
|
||||
class LevelList(generic.ListView):
|
||||
model = models.TrainingLevel
|
||||
template_name = "level_list.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_title"] = "All Training Levels"
|
||||
context["ta"] = models.TrainingLevel.objects.get(level=models.TrainingLevel.TA)
|
||||
context["tech"] = models.TrainingLevel.objects.filter(level=models.TrainingLevel.TECHNICIAN).order_by('department')
|
||||
context["sup"] = models.TrainingLevel.objects.filter(level=models.TrainingLevel.SUPERVISOR).order_by('department')
|
||||
return context
|
||||
|
||||
|
||||
class TraineeList(generic.ListView):
|
||||
model = models.Trainee
|
||||
template_name = 'trainee_list.html'
|
||||
paginate_by = 25
|
||||
|
||||
def get_queryset(self):
|
||||
q = self.request.GET.get('q', "")
|
||||
|
||||
filter = Q(first_name__icontains=q) | Q(last_name__icontains=q) | Q(initials__icontains=q)
|
||||
|
||||
# try and parse an int
|
||||
try:
|
||||
val = int(q)
|
||||
filter = filter | Q(pk=val)
|
||||
except: # noqa
|
||||
# not an integer
|
||||
pass
|
||||
|
||||
return self.model.objects.filter(filter).annotate(num_qualifications=Count('qualifications_obtained')).order_by('-num_qualifications').prefetch_related('levels', 'qualifications_obtained', 'qualifications_obtained__item')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_title"] = "Training Profile List"
|
||||
return context
|
||||
|
||||
|
||||
class SessionLog(generic.FormView):
|
||||
template_name = "session_log_form.html"
|
||||
form_class = forms.SessionLogForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(SessionLog, self).get_context_data(**kwargs)
|
||||
context["page_title"] = "Log New Training Session"
|
||||
context["depths"] = models.TrainingItemQualification.CHOICES
|
||||
return context
|
||||
|
||||
|
||||
class AddQualification(generic.CreateView, ModalURLMixin):
|
||||
template_name = "edit_training_record.html"
|
||||
model = models.TrainingItemQualification
|
||||
form_class = forms.QualificationForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AddQualification, self).get_context_data(**kwargs)
|
||||
context["depths"] = models.TrainingItemQualification.CHOICES
|
||||
if is_ajax(self.request):
|
||||
context['override'] = "base_ajax.html"
|
||||
else:
|
||||
context['override'] = 'base_training.html'
|
||||
context['page_title'] = "Add Qualification for {}".format(models.Trainee.objects.get(pk=self.kwargs['pk']))
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return self.get_close_url('trainee_detail', 'trainee_detail')
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AddQualification, self).get_form_kwargs()
|
||||
kwargs['pk'] = self.kwargs['pk']
|
||||
return kwargs
|
||||
|
||||
|
||||
class AddLevelRequirement(generic.CreateView, ModalURLMixin):
|
||||
template_name = "add_level_requirement.html"
|
||||
model = models.TrainingLevelRequirement
|
||||
form_class = forms.RequirementForm
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AddLevelRequirement, self).get_context_data(**kwargs)
|
||||
context["page_title"] = "Add Requirements to Training Level {}".format(models.TrainingLevel.objects.get(pk=self.kwargs['pk']))
|
||||
return context
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AddLevelRequirement, self).get_form_kwargs()
|
||||
kwargs['pk'] = self.kwargs['pk']
|
||||
return kwargs
|
||||
|
||||
def get_success_url(self):
|
||||
return self.get_close_url('level_detail', 'level_detail')
|
||||
|
||||
@transaction.atomic()
|
||||
@reversion.create_revision()
|
||||
def form_valid(self, form, *args, **kwargs):
|
||||
reversion.add_to_revision(form.cleaned_data['level'])
|
||||
reversion.set_comment("Level requirement added")
|
||||
return super().form_valid(form, *args, **kwargs)
|
||||
|
||||
|
||||
class RemoveRequirement(generic.DeleteView):
|
||||
model = models.TrainingLevelRequirement
|
||||
template_name = 'traininglevelrequirement_confirm_delete.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_title"] = "Delete Requirement '{}' from Training Level {}?".format(self.object, self.object.level)
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return self.request.POST.get('next')
|
||||
|
||||
@transaction.atomic()
|
||||
@reversion.create_revision()
|
||||
def delete(self, *args, **kwargs):
|
||||
reversion.add_to_revision(self.get_object().level)
|
||||
return super().delete(*args, **kwargs)
|
||||
|
||||
|
||||
class ConfirmLevel(generic.RedirectView):
|
||||
@transaction.atomic()
|
||||
@reversion.create_revision()
|
||||
def get_redirect_url(self, *args, **kwargs):
|
||||
level_qualification = models.TrainingLevelQualification.objects.get(trainee=kwargs['pk'], level=kwargs['level_pk'])
|
||||
level_qualification.confirmed_by = self.request.user
|
||||
level_qualification.confirmed_on = timezone.now()
|
||||
level_qualification.save()
|
||||
reversion.add_to_revision(level_qualification.trainee)
|
||||
reversion.set_user(self.request.user)
|
||||
return reverse_lazy('trainee_detail', kwargs={'pk': kwargs['pk']})
|
||||
@@ -20,6 +20,7 @@ class Command(BaseCommand):
|
||||
hs_group = None
|
||||
|
||||
def handle(self, *args, **options):
|
||||
print("Generating sample user data")
|
||||
from django.conf import settings
|
||||
|
||||
if not (settings.DEBUG or settings.STAGING):
|
||||
@@ -32,6 +33,7 @@ class Command(BaseCommand):
|
||||
self.setup_groups()
|
||||
self.setup_useful_profiles()
|
||||
self.setup_generic_profiles()
|
||||
print("Done generating sample user data")
|
||||
|
||||
def setup_groups(self):
|
||||
self.keyholder_group = Group.objects.create(name='Keyholders')
|
||||
|
||||
@@ -56,43 +56,37 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="col-lg-4 col-12 mb-2">
|
||||
<div class="card">
|
||||
<div class="row no-gutters">
|
||||
<div class="col-md-3">
|
||||
<img src="{{object.profile_picture}}" class="card-img img-fluid" />
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<div class="card-body">
|
||||
<dl class="row">
|
||||
<dt class="col-5">First Name</dt>
|
||||
<dd class="col-7">{{object.first_name}}</dd>
|
||||
<img src="{{object.profile_picture}}" class="card-img img-fluid" />
|
||||
<div class="card-body">
|
||||
<dl class="row">
|
||||
<dt class="col-5">First Name</dt>
|
||||
<dd class="col-7">{{object.first_name}}</dd>
|
||||
|
||||
<dt class="col-5">Last Name</dt>
|
||||
<dd class="col-7">{{object.last_name}}</dd>
|
||||
<dt class="col-5">Last Name</dt>
|
||||
<dd class="col-7">{{object.last_name}}</dd>
|
||||
|
||||
<dt class="col-5">Email</dt>
|
||||
<dd class="col-7">{{object.email}}</dd>
|
||||
<dt class="col-5">Email</dt>
|
||||
<dd class="col-7">{{object.email}}</dd>
|
||||
|
||||
<dt class="col-5">Last Login</dt>
|
||||
<dd class="col-7">{{object.last_login|date:"d/m/Y H:i"}}</dd>
|
||||
<dt class="col-5">Last Login</dt>
|
||||
<dd class="col-7">{{object.last_login|date:"d/m/Y H:i"}}</dd>
|
||||
|
||||
<dt class="col-5">Date Joined</dt>
|
||||
<dd class="col-7">{{object.date_joined|date:"d/m/Y H:i"}}</dd>
|
||||
<dt class="col-5">Date Joined</dt>
|
||||
<dd class="col-7">{{object.date_joined|date:"d/m/Y H:i"}}</dd>
|
||||
|
||||
<dt class="col-5">Initials</dt>
|
||||
<dd class="col-7">{{object.initials}}</dd>
|
||||
<dt class="col-5">Initials</dt>
|
||||
<dd class="col-7">{{object.initials}}</dd>
|
||||
|
||||
<dt class="col-5">Phone</dt>
|
||||
<dd class="col-7">{{object.phone|linkornone:'tel'}}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<dt class="col-5">Phone</dt>
|
||||
<dd class="col-7">{{object.phone|linkornone:'tel'}}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% if not request.is_ajax and object.pk == user.pk %}
|
||||
<div class="col-12 my-2">
|
||||
<div class="col-lg-8 col-12">
|
||||
<div class="card">
|
||||
<div class="card-header">Personal iCal Details</div>
|
||||
<div class="card-body">
|
||||
@@ -152,9 +146,31 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col col-lg-6 mb-2">
|
||||
<div class="card">
|
||||
<div class="card-header">Training Record</div>
|
||||
<div class="card-body">
|
||||
<a href="{% url 'trainee_detail' object.pk %}" class="btn btn-primary"><span class="fas fa-eye"></span> View Training Record</a>
|
||||
{% include 'partials/add_qualification.html' %}
|
||||
<ul class="list-group pt-3">
|
||||
<li class="list-group-item active">Achieved Levels:</li>
|
||||
{% for qual in completed_levels %}
|
||||
<a href="{% url 'level_detail' qual.level.pk %}"class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">{{ qual.level }}<span class='badge badge-{{qual.level.department_colour}} badge-pill'><span class='fas fa-{{qual.level.icon|default:"question"}}'></span></span></a>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<div class="card">
|
||||
<div class="card-header">Events</div>
|
||||
{% with object.latest_events as events %}
|
||||
{% include 'partials/event_table.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h4>Events</h4>
|
||||
{% with object.latest_events as events %}
|
||||
{% include 'partials/event_table.html' %}
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -42,6 +42,7 @@ class ProfileDetail(generic.DetailView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(ProfileDetail, self).get_context_data(**kwargs)
|
||||
context['page_title'] = "Profile: {}".format(self.object)
|
||||
context["completed_levels"] = self.object.as_trainee.level_qualifications()
|
||||
return context
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
{% if version.revision.user %}
|
||||
<a href="{% url 'profile_detail' pk=version.revision.user.pk %}" class="modal-href">
|
||||
<img class="media-object rounded" src="{{ version.revision.user.profile_picture}}" />
|
||||
</a>
|
||||
{% else %}
|
||||
<img class="media-object rounded" src="{% static 'imgs/pyrigs-avatar.png' %}" />
|
||||
{% endif %}
|
||||
@@ -31,6 +30,7 @@
|
||||
<div class="media-body">
|
||||
<h5>
|
||||
{{ version.revision.user.name|default:'System' }}
|
||||
{% if version.revision.user %}</a>{% endif %}
|
||||
<span class="float-right"><small><span class="fas fa-clock"></span> <span class="time">{{version.revision.date_created|date:"c"}}</span> ({{version.revision.date_created}})</small></span>
|
||||
</h5>
|
||||
{% endif %}
|
||||
|
||||
@@ -13,7 +13,7 @@ urlpatterns = [
|
||||
name='activity_feed'),
|
||||
]
|
||||
|
||||
for app in [apps.get_app_config(label) for label in ("RIGS", "assets")]:
|
||||
for app in [apps.get_app_config(label) for label in ("RIGS", "assets", "training")]:
|
||||
appname = str(app.label)
|
||||
if appname == 'RIGS':
|
||||
appname = 'rigboard'
|
||||
|
||||
@@ -21,7 +21,6 @@ class FieldComparison(object):
|
||||
def display_value(self, value):
|
||||
if (isinstance(self.field, IntegerField) or isinstance(self.field, CharField)) and self.field.choices is not None and len(self.field.choices) > 0:
|
||||
choice = [x[1] for x in self.field.choices if x[0] == value]
|
||||
# TODO This defensive piece should not be necessary?
|
||||
if len(choice) > 0:
|
||||
return choice[0]
|
||||
if isinstance(self.field, BooleanField):
|
||||
@@ -122,7 +121,7 @@ class ModelComparison(object):
|
||||
old_item_versions = self.version.parent.revision.version_set.exclude(content_type=item_type)
|
||||
new_item_versions = self.version.revision.version_set.exclude(content_type=item_type).exclude(content_type=ContentType.objects.get_for_model(models.EventAuthorisation))
|
||||
|
||||
comparisonParams = {'excluded_keys': ['id', 'event', 'order', 'checklist']}
|
||||
comparisonParams = {'excluded_keys': ['id', 'event', 'order', 'checklist', 'level']}
|
||||
|
||||
# Build some dicts of what we have
|
||||
item_dict = {} # build a list of items, key is the item_pk
|
||||
|
||||
Reference in New Issue
Block a user