From 63a2f6d47b853e79b9a0e956324e15766e46f4ad Mon Sep 17 00:00:00 2001 From: Arona Jones Date: Fri, 16 Dec 2022 14:48:54 +0000 Subject: [PATCH] Add URLField for linking to uploaded quotes --- RIGS/migrations/0046_subhire.py | 6 ++++-- RIGS/migrations/0047_alter_subhire_options.py | 17 ----------------- RIGS/models.py | 15 +++++---------- RIGS/templates/subhire_detail.html | 2 ++ RIGS/templates/subhire_form.html | 4 ++++ RIGS/utils.py | 3 ++- RIGS/validators.py | 10 ++++++++++ RIGS/views/rigboard.py | 4 ---- RIGS/views/subhire.py | 2 +- 9 files changed, 28 insertions(+), 35 deletions(-) delete mode 100644 RIGS/migrations/0047_alter_subhire_options.py create mode 100644 RIGS/validators.py diff --git a/RIGS/migrations/0046_subhire.py b/RIGS/migrations/0046_subhire.py index f5a488a8..9b11a65d 100644 --- a/RIGS/migrations/0046_subhire.py +++ b/RIGS/migrations/0046_subhire.py @@ -1,5 +1,6 @@ -# Generated by Django 3.2.16 on 2022-12-16 12:10 +# Generated by Django 3.2.16 on 2022-12-16 14:41 +import RIGS.validators from django.db import migrations, models import django.db.models.deletion import versioning.versioning @@ -25,12 +26,13 @@ class Migration(migrations.Migration): ('end_time', models.TimeField(blank=True, null=True)), ('purchase_order', models.CharField(blank=True, default='', max_length=255, verbose_name='PO')), ('insurance_value', models.DecimalField(decimal_places=2, max_digits=10)), + ('quote', models.URLField(default='', validators=[RIGS.validators.validate_url])), ('events', models.ManyToManyField(to='RIGS.Event')), ('organisation', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='RIGS.organisation')), ('person', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='RIGS.person')), ], options={ - 'abstract': False, + 'permissions': [('subhire_finance', 'Can see financial data for subhire - insurance values')], }, bases=(models.Model, versioning.versioning.RevisionMixin), ), diff --git a/RIGS/migrations/0047_alter_subhire_options.py b/RIGS/migrations/0047_alter_subhire_options.py deleted file mode 100644 index 7c5323a6..00000000 --- a/RIGS/migrations/0047_alter_subhire_options.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.2.16 on 2022-12-16 14:22 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('RIGS', '0046_subhire'), - ] - - operations = [ - migrations.AlterModelOptions( - name='subhire', - options={'permissions': [('subhire_finance', 'Can see financial data for subhire - insurance values')]}, - ), - ] diff --git a/RIGS/models.py b/RIGS/models.py index 027fe260..54bec957 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -8,7 +8,7 @@ from urllib.parse import urlparse import pytz from django import forms -from django.db.models import Q, F +from django.db.models import Q from django.conf import settings from django.contrib.auth.models import AbstractUser from django.core.exceptions import ValidationError @@ -17,9 +17,10 @@ from django.urls import reverse from django.utils import timezone from django.utils.functional import cached_property from reversion import revisions as reversion -from reversion.models import Version from versioning.versioning import RevisionMixin +from .validators import validate_url + def filter_by_pk(filt, query): # try and parse an int @@ -621,6 +622,8 @@ class SubhireManager(models.Manager): class Subhire(BaseEvent): insurance_value = models.DecimalField(max_digits=10, decimal_places=2) # TODO Validate if this is over notifiable threshold events = models.ManyToManyField(Event) + quote = models.URLField(default='', validators=[validate_url]) + objects = SubhireManager() @@ -774,14 +777,6 @@ class Payment(models.Model, RevisionMixin): return f"payment of £{self.amount}" -def validate_url(value): - if not value: - return # Required error is done the field - obj = urlparse(value) - if obj.hostname not in ('nottinghamtec.sharepoint.com'): - raise ValidationError('URL must point to a location on the TEC Sharepoint') - - @reversion.register class RiskAssessment(models.Model, RevisionMixin): SMALL = (0, 'Small') diff --git a/RIGS/templates/subhire_detail.html b/RIGS/templates/subhire_detail.html index ae4b6c72..9d252950 100644 --- a/RIGS/templates/subhire_detail.html +++ b/RIGS/templates/subhire_detail.html @@ -44,6 +44,8 @@
Insurance Value
£{{ object.insurance_value }}
{% endif %} +
Quote
+
View
diff --git a/RIGS/templates/subhire_form.html b/RIGS/templates/subhire_form.html index 87cfc3be..7e7f6fc7 100644 --- a/RIGS/templates/subhire_form.html +++ b/RIGS/templates/subhire_form.html @@ -188,6 +188,10 @@ If this value is greater than £50,000 then please email productions@nottinghamtec.co.uk in addition to complete the additional insurance requirements +
+ +
{% render_field form.quote class+="form-control" %}
+
diff --git a/RIGS/utils.py b/RIGS/utils.py index 1ebf91f4..e2d249bb 100644 --- a/RIGS/utils.py +++ b/RIGS/utils.py @@ -1,7 +1,8 @@ from datetime import datetime, timedelta, date import calendar from calendar import HTMLCalendar -from RIGS.models import BaseEvent, Event, Subhire +from RIGS.models import Event, Subhire + class Calendar(HTMLCalendar): def __init__(self, year=None, month=None): diff --git a/RIGS/validators.py b/RIGS/validators.py new file mode 100644 index 00000000..c536e7f3 --- /dev/null +++ b/RIGS/validators.py @@ -0,0 +1,10 @@ +from urllib.parse import urlparse +from django.core.exceptions import ValidationError + + +def validate_url(value): + if not value: + return # Required error is done the field + obj = urlparse(value) + if obj.hostname not in ('nottinghamtec.sharepoint.com'): + raise ValidationError('URL must point to a location on the TEC Sharepoint') \ No newline at end of file diff --git a/RIGS/views/rigboard.py b/RIGS/views/rigboard.py index d4f703cd..e845ed65 100644 --- a/RIGS/views/rigboard.py +++ b/RIGS/views/rigboard.py @@ -2,7 +2,6 @@ import copy import datetime import re import premailer -import simplejson from django.conf import settings from django.contrib import messages @@ -12,12 +11,9 @@ from django.core.exceptions import SuspiciousOperation from django.core.mail import EmailMultiAlternatives from django.db.models import Q from django.http import HttpResponse -from django.shortcuts import get_object_or_404 from django.template.loader import get_template -from django.urls import reverse from django.urls import reverse_lazy from django.utils import timezone -from django.utils.html import mark_safe from django.utils.decorators import method_decorator from django.views import generic diff --git a/RIGS/views/subhire.py b/RIGS/views/subhire.py index ff2a476d..1c49ff90 100644 --- a/RIGS/views/subhire.py +++ b/RIGS/views/subhire.py @@ -1,6 +1,6 @@ from django.urls import reverse_lazy from django.views import generic -from PyRIGS.views import OEmbedView, is_ajax, ModalURLMixin, PrintView, get_related +from PyRIGS.views import ModalURLMixin, get_related from RIGS import models, forms