Versioning module now does magic

Automatic creation of views/urls for anything registered with reversion, with a small amount of hackage to preserve legacy stuff. (and the DAMNED asset IDs!) I would never get distracted...
This commit is contained in:
2020-08-29 16:23:10 +01:00
parent 8ea96674db
commit d708207ab9
23 changed files with 188 additions and 197 deletions

View File

@@ -197,6 +197,8 @@ class VatRate(models.Model, RevisionMixin):
objects = VatManager()
reversion_hide = True
@property
def as_percent(self):
return self.rate * 100
@@ -332,6 +334,10 @@ class Event(models.Model, RevisionMixin):
auth_request_at = models.DateTimeField(null=True, blank=True)
auth_request_to = models.EmailField(null=True, blank=True)
@property
def display_id(self):
return str("N%05d" % self.pk)
# Calculated values
"""
EX Vat
@@ -467,7 +473,6 @@ class Event(models.Model, RevisionMixin):
self.full_clean()
super(Event, self).save(*args, **kwargs)
class EventItem(models.Model):
event = models.ForeignKey('Event', related_name='items', blank=True, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
@@ -476,6 +481,8 @@ class EventItem(models.Model):
cost = models.DecimalField(max_digits=10, decimal_places=2)
order = models.IntegerField()
reversion_hide = True
@property
def total_cost(self):
return self.cost * self.quantity
@@ -673,5 +680,7 @@ class EventChecklistVehicle(models.Model):
vehicle = models.CharField(max_length=255)
driver = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='drivers', on_delete=models.CASCADE)
reversion_hide = True
def __str__(self):
return "{} driven by {}".format(self.vehicle, str(self.driver))

View File

@@ -19,7 +19,7 @@ from premailer import Premailer
from z3c.rml import rml2pdf
from RIGS import models
from versioning.versioning import models_for_feed
from reversion import revisions as reversion
def send_eventauthorisation_success_email(instance):
@@ -142,11 +142,9 @@ def send_admin_awaiting_approval_email(user, request, **kwargs):
user_activated.connect(send_admin_awaiting_approval_email)
# TODO Move
def update_cache(sender, instance, created, **kwargs):
cache.clear()
for model in models_for_feed():
for model in reversion.get_registered_models():
post_save.connect(update_cache, sender=model)

View File

@@ -80,7 +80,7 @@
class="hidden-xs">Edit</span></a>
</div>
<div class="col-12 text-right">
{% include 'partials/last_edited.html' with target="ec_history" %}
{% include 'partials/last_edited.html' with target="eventchecklist_history" %}
</div>
</div>
{% endblock %}

View File

@@ -14,7 +14,7 @@
{% for event in events %}
<tr {% include 'partials/event_table_colour.html' %} id="event_row">
<!---Number-->
<th scope="row" id="event_number">{{ event.pk }}</th>
<th scope="row" id="event_number">{{ event.display_id }}</th>
<!--Dates-->
<td id="event_dates">
<div><strong>{{ event.start_date|date:"D d/m/Y" }}</strong></div>

View File

@@ -1,53 +0,0 @@
{% extends 'base_rigs.html' %}
{% load humanize %}
{% block title %}RIGS{% endblock %}
{% block content %}
<div class="row">
<h1 class="col-sm-12 pb-3">R<small class="text-muted">ig</small> I<small class="text-muted">nformation</small class="text-muted"> G<small class="text-muted">athering</small> S<small class="text-muted">ystem</small></h1>
<h4 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%}</h4>
<div class="col-sm">
<div class="card">
<div class="card-header">
<h4 class="list-group-item-heading">Rigboard</h4>
</div>
<div class="list-group list-group-flush">
<a class="list-group-item list-group-item-action" href="{% url 'rigboard' %}"><i class="fas fa-list"></i> Rigboard</a>
<a class="list-group-item list-group-item-action" href="{% url 'web_calendar' %}"><i class="fas fa-calendar"></i> Calendar</a>
{% if perms.RIGS.add_event %}
<a class="list-group-item list-group-item-action" href="{% url 'event_create' %}"><i class="fas fa-plus"></i> New Event</a>
{% endif %}
</div>
<div class="card-header">
<h4 class="list-group-item-heading">Asset Database</h4>
</div>
<div class="list-group list-group-flush">
<a class="list-group-item list-group-item-action" href="{% url 'asset_index' %}"><i class="fas fa-tag"></i> Asset List </a>
{% if perms.assets.add_asset %}
<a class="list-group-item list-group-item-action" href="{% url 'asset_create' %}"><i class="fas fa-plus"></i> New Asset</a>
{% endif %}
<a class="list-group-item list-group-item-action" href="{% url 'supplier_list' %}"><i class="fas fa-parachute-box"></i> Supplier List </a>
{% if perms.assets.add_asset %}
<a class="list-group-item list-group-item-action" href="{% url 'supplier_create' %}"><i class="fas fa-plus"></i> New Supplier</a>
{% endif %}
</div>
<div class="card-header">
<h4 class="list-group-item-heading">Quick Links</h4>
</div>
<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"><i class="fas fa-comment-alt"></i> TEC Forum</a>
<a class="list-group-item list-group-item-action" href="//members.nottinghamtec.co.uk/wiki" target="_blank" rel="noopener noreferrer"><i class="fas fa-pen-square"></i> TEC Wiki</a>
{% if perms.RIGS.view_event %}
<a class="list-group-item list-group-item-action" href="//members.nottinghamtec.co.uk/price" target="_blank"><i class="fas fa-pound-sign"></i> Price List</a>
{% endif %}
</div>
</div>
</div>
{% if perms.RIGS.view_event %}
<div class="col-sm">
{% include 'activity_feed.html' %}
</div>
{% endif %}
</div><!---end row--->
{% endblock %}

View File

@@ -33,7 +33,7 @@
<tbody>
{% for event in object_list %}
<tr {% include 'partials/event_table_colour.html' %}>
<th scope="row"><a href="{% url 'event_detail' event.pk %}">N{{ event.pk|stringformat:"05d" }}</a><br>
<th scope="row"><a href="{% url 'event_detail' event.pk %}">{{ event.display_id }}</a><br>
<span class="text-muted">{{ event.get_status_display }}</span></th>
<td>{{ event.start_date }}</td>
<td>

View File

@@ -150,7 +150,7 @@
class="hidden-xs">Edit</span></a>
</div>
<div class="col-12 text-right">
{% include 'partials/last_edited.html' with target="ra_history" %}
{% include 'partials/last_edited.html' with target="riskassessment_history" %}
</div>
</div>
{% endblock %}

View File

@@ -6,12 +6,8 @@ from django.views.generic import RedirectView
from PyRIGS.decorators import (api_key_required, has_oembed,
permission_required_with_403)
from RIGS import finance, ical, models, rigboard, views, hs
from versioning import versioning
from django.views.decorators.cache import cache_page
urlpatterns = [
path('', login_required(views.Index.as_view()), name='index'),
# People
path('people/', permission_required_with_403('RIGS.view_person')(views.PersonList.as_view()),
name='person_list'),
@@ -19,9 +15,6 @@ urlpatterns = [
name='person_create'),
path('people/<int:pk>/', permission_required_with_403('RIGS.view_person')(views.PersonDetail.as_view()),
name='person_detail'),
path('people/<int:pk>/history/',
permission_required_with_403('RIGS.view_person')(versioning.VersionHistory.as_view()),
name='person_history', kwargs={'model': models.Person}),
path('people/<int:pk>/edit/', permission_required_with_403('RIGS.change_person')(views.PersonUpdate.as_view()),
name='person_update'),
@@ -34,9 +27,6 @@ urlpatterns = [
path('organisations/<int:pk>/',
permission_required_with_403('RIGS.view_organisation')(views.OrganisationDetail.as_view()),
name='organisation_detail'),
path('organisations/<int:pk>/history/',
permission_required_with_403('RIGS.view_organisation')(versioning.VersionHistory.as_view()),
name='organisation_history', kwargs={'model': models.Organisation}),
path('organisations/<int:pk>/edit/',
permission_required_with_403('RIGS.change_organisation')(views.OrganisationUpdate.as_view()),
name='organisation_update'),
@@ -48,9 +38,6 @@ urlpatterns = [
name='venue_create'),
path('venues/<int:pk>/', permission_required_with_403('RIGS.view_venue')(views.VenueDetail.as_view()),
name='venue_detail'),
path('venues/<int:pk>/history/',
permission_required_with_403('RIGS.view_venue')(versioning.VersionHistory.as_view()),
name='venue_history', kwargs={'model': models.Venue}),
path('venues/<int:pk>/edit/', permission_required_with_403('RIGS.change_venue')(views.VenueUpdate.as_view()),
name='venue_update'),
@@ -63,11 +50,7 @@ urlpatterns = [
url(r'^rigboard/calendar/(?P<view>(month|week|day))/(?P<date>(\d{4}-\d{2}-\d{2}))/$',
login_required()(rigboard.WebCalendar.as_view()), name='web_calendar'),
path('rigboard/archive/', RedirectView.as_view(permanent=True, pattern_name='event_archive')),
path('rigboard/activity/', permission_required_with_403('RIGS.view_event')(versioning.ActivityTable.as_view()),
name='activity_table'),
path('rigboard/activity/feed/',
cache_page(60 * 10)(permission_required_with_403('RIGS.view_event')(versioning.ActivityFeed.as_view())),
name='activity_feed'),
path('event/<int:pk>/', has_oembed(oembed_view="event_oembed")(rigboard.EventDetail.as_view()),
name='event_detail'),
@@ -86,9 +69,6 @@ urlpatterns = [
name='event_update'),
path('event/<int:pk>/duplicate/', permission_required_with_403('RIGS.add_event')(rigboard.EventDuplicate.as_view()),
name='event_duplicate'),
path('event/<int:pk>/history/',
permission_required_with_403('RIGS.view_event')(versioning.VersionHistory.as_view()),
name='event_history', kwargs={'model': models.Event}),
# Event H&S
path('event/hs/', permission_required_with_403('RIGS.change_event')(hs.HSList.as_view()), name='hs_list'),
@@ -99,8 +79,6 @@ urlpatterns = [
name='ra_detail'),
path('event/ra/<int:pk>/edit/', permission_required_with_403('RIGS.change_event')(hs.EventRiskAssessmentEdit.as_view()),
name='ra_edit'),
path('event/ra/<int:pk>/history/', permission_required_with_403('RIGS.change_event')(versioning.VersionHistory.as_view()),
name='ra_history', kwargs={'model': models.RiskAssessment}),
path('event/ra/list', permission_required_with_403('RIGS.change_event')(hs.EventRiskAssessmentList.as_view()),
name='ra_list'),
path('event/ra/<int:pk>/review/', permission_required_with_403('RIGS.change_event')(hs.EventRiskAssessmentReview.as_view()), name='ra_review'),
@@ -111,13 +89,8 @@ urlpatterns = [
name='ec_detail'),
path('event/checklist/<int:pk>/edit/', permission_required_with_403('RIGS.change_event')(hs.EventChecklistEdit.as_view()),
name='ec_edit'),
path('event/checklist/<int:pk>/history/', permission_required_with_403('RIGS.change_event')(versioning.VersionHistory.as_view()),
name='ec_history', kwargs={'model': models.EventChecklist}),
path('event/checklist/list', permission_required_with_403('RIGS.change_event')(hs.EventChecklistList.as_view()),
name='ec_list'),
# TEMPORARY
path('event/vehicle/<int:pk>/history/', permission_required_with_403('RIGS.change_event')(versioning.VersionHistory.as_view()),
name='vc_history', kwargs={'model': models.EventChecklistVehicle}),
# Finance
path('invoice/', permission_required_with_403('RIGS.view_invoice')(finance.InvoiceIndex.as_view()),
@@ -141,9 +114,6 @@ urlpatterns = [
path('invoice/<int:pk>/delete/',
permission_required_with_403('RIGS.change_invoice')(finance.InvoiceDelete.as_view()),
name='invoice_delete'),
path('invoice/(<int:pk>/history/',
permission_required_with_403('RIGS.view_invoice')(versioning.VersionHistory.as_view()),
name='invoice_history', kwargs={'model': models.Invoice}),
path('payment/create/', permission_required_with_403('RIGS.add_payment')(finance.PaymentCreate.as_view()),
name='payment_create'),

View File

@@ -21,25 +21,6 @@ from assets import models as asset_models
from functools import reduce
from PyRIGS.views import GenericListView
from django.views.decorators.cache import never_cache
from django.utils.decorators import method_decorator
"""
Displays the current rig count along with a few other bits and pieces
"""
# Disable browser based caching
@method_decorator(never_cache, name='dispatch')
class Index(generic.TemplateView):
template_name = 'index.html'
def get_context_data(self, **kwargs):
context = super(Index, self).get_context_data(**kwargs)
context['rig_count'] = models.Event.objects.rig_count()
return context
class PersonList(GenericListView):
template_name = 'person_list.html'