Event properties internal/authorised always return a explicit boolean rather than sometimes None

This commit is contained in:
2020-09-01 15:02:16 +01:00
parent 1d5429052f
commit 87e831a468
8 changed files with 50 additions and 47 deletions

View File

@@ -177,14 +177,14 @@ class Command(BaseCommand):
"asset_finance", "view_asset", "view_supplier", "asset_finance",
"add_supplier", "view_cabletype", "change_cabletype",
"add_cabletype", "view_eventchecklist", "change_eventchecklist",
"add_eventchecklist", "view_riskassessment", "change_riskassessment",
"add_riskassessment", "add_eventchecklistcrew", "change_eventchecklistcrew",
"delete_eventchecklistcrew", "view_eventchecklistcrew", "add_eventchecklistvehicle",
"change_eventchecklistvehicle",
"delete_eventchecklistvehicle", "view_eventchecklistvehicle", ]
"add_eventchecklist", "view_riskassessment", "change_riskassessment",
"add_riskassessment", "add_eventchecklistcrew", "change_eventchecklistcrew",
"delete_eventchecklistcrew", "view_eventchecklistcrew", "add_eventchecklistvehicle",
"change_eventchecklistvehicle",
"delete_eventchecklistvehicle", "view_eventchecklistvehicle", ]
financePerms = keyholderPerms + ["add_invoice", "change_invoice", "view_invoice",
"add_payment", "change_payment", "delete_payment"]
hsPerms = keyHolderPerms + [ "review_riskassessment", "review_eventchecklist" ]
hsPerms = keyholderPerms + ["review_riskassessment", "review_eventchecklist"]
for permId in keyholderPerms:
self.keyholder_group.permissions.add(Permission.objects.get(codename=permId))
@@ -226,8 +226,8 @@ class Command(BaseCommand):
financeUser.save()
hsUser = models.Profile.objects.create(username="hs", first_name="HS", last_name="User",
initials="HSU",
email="hsuser@example.com", is_active=True)
initials="HSU",
email="hsuser@example.com", is_active=True)
hsUser.groups.add(self.hs_group)
hsUser.groups.add(self.keyholder_group)
hsUser.set_password('hs')

View File

@@ -443,9 +443,10 @@ class Event(models.Model, RevisionMixin):
else:
return endDate
@property
def internal(self):
return self.organisation and self.organisation.union_account
return bool(self.organisation and self.organisation.union_account)
@property
def status_color(self):
@@ -453,7 +454,7 @@ class Event(models.Model, RevisionMixin):
return "text-muted table-secondary"
elif not self.is_rig:
return "table-info"
elif self.authorised and self.mic and (self.dry_hire or self.riskassessment):
elif self.mic and (self.dry_hire or self.riskassessment) and self.authorised:
return "table-success"
else:
return "table-warning"
@@ -587,7 +588,7 @@ class Payment(models.Model):
# Probably shouldn't be doing HTML at the python level but hey...they say not to do logic in templates! :P
def get_review_string(obj, review_link):
if obj.reviewed_by:
return "<span class='badge badge-success py-2'>Reviewed by <a href='{}'>{}</a> at {}</span>".format(reverse_lazy('profile_detail', kwargs={'pk': obj.reviewed_by.pk}), obj.reviewed_by, obj.reviewed_at.strftime("%d/%m/%Y %H:%M"))
return "<span class='badge badge-success py-2'>Reviewed by <a href='{}'>{}</a> at {}</span>".format(reverse_lazy('profile_detail', kwargs={'pk': obj.reviewed_by.pk}), obj.reviewed_by, obj.reviewed_at.strftime("%d/%m/%Y %H:%M"))
else:
return "<a class='btn btn-success my-2' href='{}'>Mark Reviewed</a>".format(reverse_lazy(review_link, kwargs={'pk': obj.pk}))
@@ -685,8 +686,8 @@ class EventChecklist(models.Model, RevisionMixin):
extinguishers_location = models.CharField(max_length=255, help_text="Location of fire extinguishers")
# Small Electrical Checks
rcds = models.BooleanField(blank=True,null=True,help_text="RCDs installed where needed and tested?")
supply_test = models.BooleanField(blank=True,null=True,help_text="Electrical supplies tested?<br><small>(using socket tester)</small>")
rcds = models.BooleanField(blank=True, null=True, help_text="RCDs installed where needed and tested?")
supply_test = models.BooleanField(blank=True, null=True, help_text="Electrical supplies tested?<br><small>(using socket tester)</small>")
# Shared electrical checks
earthing = models.BooleanField(help_text="Equipment appropriately earthed?<br><small>(truss, stage, generators etc)</small>")
@@ -694,31 +695,31 @@ class EventChecklist(models.Model, RevisionMixin):
medium_event = models.BooleanField()
# Medium Electrical Checks
source_rcd = models.BooleanField(blank=True,null=True,help_text="Source RCD protected?<br><small>(if cable is more than 3m long) </small>")
labelling = models.BooleanField(blank=True,null=True, help_text="Appropriate and clear labelling on distribution and cabling?")
source_rcd = models.BooleanField(blank=True, null=True, help_text="Source RCD protected?<br><small>(if cable is more than 3m long) </small>")
labelling = models.BooleanField(blank=True, null=True, help_text="Appropriate and clear labelling on distribution and cabling?")
# First Distro
fd_voltage_l1 = models.IntegerField(blank=True,null=True, verbose_name="First Distro Voltage L1-N", help_text="L1 - N")
fd_voltage_l2 = models.IntegerField(blank=True,null=True,verbose_name="First Distro Voltage L2-N", help_text="L2 - N")
fd_voltage_l3 = models.IntegerField(blank=True,null=True,verbose_name="First Distro Voltage L3-N", help_text="L3 - N")
fd_phase_rotation = models.BooleanField(blank=True,null=True,verbose_name="Phase Rotation", help_text="Phase Rotation<br><small>(if required)</small>")
fd_earth_fault = models.IntegerField(blank=True,null=True,verbose_name="Earth Fault Loop Impedance", help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
fd_pssc = models.IntegerField(blank=True,null=True,verbose_name="PSCC", help_text="Prospective Short Circuit Current")
#Worst case points
w1_description = models.CharField(blank=True,null=True,max_length=255, help_text="Description")
w1_polarity = models.BooleanField(blank=True,null=True,help_text="Polarity Checked?")
w1_voltage = models.IntegerField(blank=True,null=True,help_text="Voltage")
w1_earth_fault = models.IntegerField(blank=True,null=True,help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
w2_description = models.CharField(blank=True,null=True,max_length=255, help_text="Description")
w2_polarity = models.BooleanField(blank=True,null=True,help_text="Polarity Checked?")
w2_voltage = models.IntegerField(blank=True,null=True,help_text="Voltage")
w2_earth_fault = models.IntegerField(blank=True,null=True,help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
w3_description = models.CharField(blank=True,null=True,max_length=255, help_text="Description")
w3_polarity = models.BooleanField(blank=True,null=True,help_text="Polarity Checked?")
w3_voltage = models.IntegerField(blank=True,null=True,help_text="Voltage")
w3_earth_fault = models.IntegerField(blank=True,null=True,help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
fd_voltage_l1 = models.IntegerField(blank=True, null=True, verbose_name="First Distro Voltage L1-N", help_text="L1 - N")
fd_voltage_l2 = models.IntegerField(blank=True, null=True, verbose_name="First Distro Voltage L2-N", help_text="L2 - N")
fd_voltage_l3 = models.IntegerField(blank=True, null=True, verbose_name="First Distro Voltage L3-N", help_text="L3 - N")
fd_phase_rotation = models.BooleanField(blank=True, null=True, verbose_name="Phase Rotation", help_text="Phase Rotation<br><small>(if required)</small>")
fd_earth_fault = models.IntegerField(blank=True, null=True, verbose_name="Earth Fault Loop Impedance", help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
fd_pssc = models.IntegerField(blank=True, null=True, verbose_name="PSCC", help_text="Prospective Short Circuit Current")
# Worst case points
w1_description = models.CharField(blank=True, null=True, max_length=255, help_text="Description")
w1_polarity = models.BooleanField(blank=True, null=True, help_text="Polarity Checked?")
w1_voltage = models.IntegerField(blank=True, null=True, help_text="Voltage")
w1_earth_fault = models.IntegerField(blank=True, null=True, help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
w2_description = models.CharField(blank=True, null=True, max_length=255, help_text="Description")
w2_polarity = models.BooleanField(blank=True, null=True, help_text="Polarity Checked?")
w2_voltage = models.IntegerField(blank=True, null=True, help_text="Voltage")
w2_earth_fault = models.IntegerField(blank=True, null=True, help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
w3_description = models.CharField(blank=True, null=True, max_length=255, help_text="Description")
w3_polarity = models.BooleanField(blank=True, null=True, help_text="Polarity Checked?")
w3_voltage = models.IntegerField(blank=True, null=True, help_text="Voltage")
w3_earth_fault = models.IntegerField(blank=True, null=True, help_text="Earth Fault Loop Impedance (Z<small>S</small>)")
all_rcds_tested = models.BooleanField(blank=True,null=True,help_text="All circuit RCDs tested?<br><small>(using test button)</small>")
public_sockets_tested = models.BooleanField(blank=True,null=True,help_text="Public/Performer accessible circuits tested?<br><small>(using socket tester)</small>")
all_rcds_tested = models.BooleanField(blank=True, null=True, help_text="All circuit RCDs tested?<br><small>(using test button)</small>")
public_sockets_tested = models.BooleanField(blank=True, null=True, help_text="Public/Performer accessible circuits tested?<br><small>(using socket tester)</small>")
reviewed_at = models.DateTimeField(null=True)
reviewed_by = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True,
@@ -732,17 +733,17 @@ class EventChecklist(models.Model, RevisionMixin):
def clean(self):
errdict = {}
if self.earthing == None or self.pat == None:
if self.earthing is None or self.pat is None:
errdict['earthing'] = 'Fill out the electrical checks'
if not self.medium_event and (self.rcds == None or self.supply_test == None):
if not self.medium_event and (self.rcds is None or self.supply_test is None):
errdict['rcds'] = 'Fill out the small event electrical checks'
if self.medium_event:
if self.source_rcd == None or self.labelling == None or self.all_rcds_tested == None or self.public_sockets_tested == None:
if self.source_rcd is None or self.labelling is None or self.all_rcds_tested is None or self.public_sockets_tested is None:
errdict['source_rcd'] = 'Fill out the medium event electrical checks'
if self.w1_description == None or self.w1_polarity == None or self.w1_voltage == None or self.w1_earth_fault == None:
if self.w1_description is None or self.w1_polarity is None or self.w1_voltage is None or self.w1_earth_fault is None:
errdict['w1_description'] = 'Fully complete at least the first worst case point'
if errdict != {}: # If there was an error when validation

View File

@@ -8,6 +8,7 @@
<a href="{% url 'event_create' %}" class="btn btn-success my-3 float-right">New <i class="fas fa-plus"></i></a>
{% endif %}
<p>Key: <span class="badge badge-success mr-1">Ready</span><span class="badge badge-warning mr-1">Action Required</span><span class="badge badge-secondary mr-1">Cancelled</span><span class="badge badge-info">Non-Rig</span></p>
{% include 'event_table.html' %}
{% endblock %}

View File

@@ -166,6 +166,7 @@ def yesnoi(boolean, invert=False, autoescape=True):
value += ' <span class="fas fa-exclamation" style="color: red;"></span>'
return mark_safe(value)
@register.filter
def title_spaced(string):
return title(string).replace('_', ' ')

View File

@@ -393,7 +393,7 @@ class TestEventDuplicate(BaseRigboardTest):
self.assertEqual(newEvent.auth_request_by, None)
self.assertEqual(newEvent.auth_request_at, None)
self.assertFalse(hasattr(newEvent, 'authorised'))
self.assertFalse(newEvent.authorised)
self.assertNotIn("N%05d" % self.testEvent.pk, self.driver.find_element_by_xpath('//h1').text)
self.assertNotIn("Event data duplicated but not yet saved", self.page.warning) # Check info message not visible

View File

@@ -101,8 +101,8 @@ class EventTestCase(TestCase):
self.assertEqual(models.Event.objects.count(), 18, "Incorrect number of events, check setup")
def test_rig_count(self):
# by my count this is 7
self.assertEqual(models.Event.objects.rig_count(), 8)
# Changed to not include unreturned dry hires in rig count
self.assertEqual(models.Event.objects.rig_count(), 7)
def test_current_events(self):
current_events = models.Event.objects.current_events()
@@ -374,8 +374,8 @@ class EventAuthorisationTestCase(TestCase):
is_superuser=True # lazily grant all permissions
)[0]
self.person = models.Person.objects.create(name='Authorisation Test Person')
self.organisation = models.Organisation.objects.create(name='Authorisation Test Organisation')
self.event = models.Event.objects.create(name="AuthorisationTestCase", person=self.person,
self.organisation = models.Organisation.objects.create(name='Authorisation Test Organisation', union_account=True)
self.event = models.Event.objects.create(name="AuthorisationTestCase", person=self.person, organisation=self.organisation,
start_date=date.today())
# Add some items
models.EventItem.objects.create(event=self.event, name="Authorisation test item", quantity=2, cost=123.45,

View File

@@ -592,7 +592,7 @@ class TestVersioningViews(TestCase):
self.assertEqual(response.status_code, 200)
def test_activity_table_loads_successfully(self):
request_url = reverse('asset_activity_table')
request_url = reverse('assets_activity_table')
response = self.client.get(request_url, follow=True)
self.assertEqual(response.status_code, 200)

View File

@@ -118,7 +118,7 @@ class ModelComparison(object):
@cached_property
def item_changes(self):
if self.follow:
if self.follow and self.version.object is not None:
item_type = ContentType.objects.get_for_model(self.version.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)