Add URLField for linking to uploaded quotes

This commit is contained in:
2022-12-16 14:48:54 +00:00
parent 8393e85b74
commit 63a2f6d47b
9 changed files with 28 additions and 35 deletions

View File

@@ -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 from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
import versioning.versioning import versioning.versioning
@@ -25,12 +26,13 @@ class Migration(migrations.Migration):
('end_time', models.TimeField(blank=True, null=True)), ('end_time', models.TimeField(blank=True, null=True)),
('purchase_order', models.CharField(blank=True, default='', max_length=255, verbose_name='PO')), ('purchase_order', models.CharField(blank=True, default='', max_length=255, verbose_name='PO')),
('insurance_value', models.DecimalField(decimal_places=2, max_digits=10)), ('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')), ('events', models.ManyToManyField(to='RIGS.Event')),
('organisation', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='RIGS.organisation')), ('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')), ('person', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='RIGS.person')),
], ],
options={ options={
'abstract': False, 'permissions': [('subhire_finance', 'Can see financial data for subhire - insurance values')],
}, },
bases=(models.Model, versioning.versioning.RevisionMixin), bases=(models.Model, versioning.versioning.RevisionMixin),
), ),

View File

@@ -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')]},
),
]

View File

@@ -8,7 +8,7 @@ from urllib.parse import urlparse
import pytz import pytz
from django import forms from django import forms
from django.db.models import Q, F from django.db.models import Q
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
@@ -17,9 +17,10 @@ from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from django.utils.functional import cached_property from django.utils.functional import cached_property
from reversion import revisions as reversion from reversion import revisions as reversion
from reversion.models import Version
from versioning.versioning import RevisionMixin from versioning.versioning import RevisionMixin
from .validators import validate_url
def filter_by_pk(filt, query): def filter_by_pk(filt, query):
# try and parse an int # try and parse an int
@@ -621,6 +622,8 @@ class SubhireManager(models.Manager):
class Subhire(BaseEvent): class Subhire(BaseEvent):
insurance_value = models.DecimalField(max_digits=10, decimal_places=2) # TODO Validate if this is over notifiable threshold insurance_value = models.DecimalField(max_digits=10, decimal_places=2) # TODO Validate if this is over notifiable threshold
events = models.ManyToManyField(Event) events = models.ManyToManyField(Event)
quote = models.URLField(default='', validators=[validate_url])
objects = SubhireManager() objects = SubhireManager()
@@ -774,14 +777,6 @@ class Payment(models.Model, RevisionMixin):
return f"payment of £{self.amount}" 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 @reversion.register
class RiskAssessment(models.Model, RevisionMixin): class RiskAssessment(models.Model, RevisionMixin):
SMALL = (0, 'Small') SMALL = (0, 'Small')

View File

@@ -44,6 +44,8 @@
<dt class="col-sm-6">Insurance Value</dt> <dt class="col-sm-6">Insurance Value</dt>
<dd class="col-sm-6">£{{ object.insurance_value }}</dd> <dd class="col-sm-6">£{{ object.insurance_value }}</dd>
{% endif %} {% endif %}
<dt class="col-sm-6">Quote</dt>
<dd class="col-sm-6"><a href="{{ object.quote }}">View</a></dd>
</dl> </dl>
</div> </div>
</div> </div>

View File

@@ -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 If this value is greater than £50,000 then please email productions@nottinghamtec.co.uk in addition to complete the additional insurance requirements
</div> </div>
</div> </div>
<div class="form-group">
<label for="{{ form.quote.id_for_label }}" class="col-sm-6 col-form-label">{{ form.quote.label }} (TEC SharePoint link)</label>
<div class="col-sm-12">{% render_field form.quote class+="form-control" %}</div>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,7 +1,8 @@
from datetime import datetime, timedelta, date from datetime import datetime, timedelta, date
import calendar import calendar
from calendar import HTMLCalendar from calendar import HTMLCalendar
from RIGS.models import BaseEvent, Event, Subhire from RIGS.models import Event, Subhire
class Calendar(HTMLCalendar): class Calendar(HTMLCalendar):
def __init__(self, year=None, month=None): def __init__(self, year=None, month=None):

10
RIGS/validators.py Normal file
View File

@@ -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')

View File

@@ -2,7 +2,6 @@ import copy
import datetime import datetime
import re import re
import premailer import premailer
import simplejson
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
@@ -12,12 +11,9 @@ from django.core.exceptions import SuspiciousOperation
from django.core.mail import EmailMultiAlternatives from django.core.mail import EmailMultiAlternatives
from django.db.models import Q from django.db.models import Q
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template.loader import get_template from django.template.loader import get_template
from django.urls import reverse
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils import timezone from django.utils import timezone
from django.utils.html import mark_safe
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views import generic from django.views import generic

View File

@@ -1,6 +1,6 @@
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.views import generic 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 from RIGS import models, forms