mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-23 16:32:15 +00:00
Initial work on associating events with subhires
This commit is contained in:
@@ -132,6 +132,7 @@ class SubhireForm(forms.ModelForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['start_date'].widget.format = '%Y-%m-%d'
|
||||
self.fields['end_date'].widget.format = '%Y-%m-%d'
|
||||
|
||||
class Meta:
|
||||
|
||||
18
RIGS/migrations/0046_subhire_events.py
Normal file
18
RIGS/migrations/0046_subhire_events.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.2.16 on 2022-10-20 11:56
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('RIGS', '0045_subhire'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='subhire',
|
||||
name='events',
|
||||
field=models.ManyToManyField(to='RIGS.Event'),
|
||||
),
|
||||
]
|
||||
@@ -575,7 +575,7 @@ class EventAuthorisation(models.Model, RevisionMixin):
|
||||
@reversion.register
|
||||
class Subhire(BaseEvent):
|
||||
insurance_value = models.DecimalField(max_digits=10, decimal_places=2) # TODO Validate if this is over notifiable threshold
|
||||
# TODO Associated events
|
||||
events = models.ManyToManyField(Event)
|
||||
|
||||
@property
|
||||
def display_id(self):
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
{# Event details #}
|
||||
<div class="col-md-6 mb-2">
|
||||
<div class="card card-default">
|
||||
<div class="card-header">Event Details</div>
|
||||
<div class="card-header">Hire Details</div>
|
||||
<div class="card-body">
|
||||
<div class="form-group" data-toggle="tooltip" title="Name of the event, displays on rigboard and on paperwork">
|
||||
<label for="{{ form.name.id_for_label }}"
|
||||
@@ -150,6 +150,14 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-header">Associated Event(s)</div>
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<select multiple name="events" id="events_id" class="selectpicker" data-live-search="true" data-sourceurl="{% url 'api_secure' model='event' %}"></select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-header">Equipment Information</div>
|
||||
<div class="card-body">
|
||||
|
||||
@@ -70,10 +70,14 @@ urlpatterns = [
|
||||
path('event/<int:pk>/duplicate/', permission_required_with_403('RIGS.add_event')(views.EventDuplicate.as_view()),
|
||||
name='event_duplicate'),
|
||||
|
||||
|
||||
# Subhire
|
||||
path('subhire/<int:pk>/', views.SubhireDetail.as_view(),
|
||||
name='subhire_detail'),
|
||||
path('subhire/create/', permission_required_with_403('RIGS.add_event')(views.SubhireCreate.as_view()),
|
||||
name='subhire_create'),
|
||||
path('subhire/<int:pk>/edit', views.SubhireEdit.as_view(),
|
||||
name='subhire_edit'),
|
||||
|
||||
|
||||
# Event H&S
|
||||
|
||||
@@ -3,3 +3,4 @@ from .finance import *
|
||||
from .hs import *
|
||||
from .ical import *
|
||||
from .rigboard import *
|
||||
from .subhire import *
|
||||
|
||||
@@ -373,30 +373,3 @@ class EventAuthoriseRequestEmailPreview(generic.DetailView):
|
||||
context['to_name'] = self.request.GET.get('to_name', None)
|
||||
context['target'] = 'event_authorise_form_preview'
|
||||
return context
|
||||
|
||||
|
||||
class SubhireDetail(generic.DetailView, ModalURLMixin):
|
||||
template_name = 'subhire_detail.html'
|
||||
model = models.Subhire
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['page_title'] = f"{self.object.display_id} | {self.object.name}"
|
||||
return context
|
||||
|
||||
|
||||
class SubhireCreate(generic.CreateView):
|
||||
model = models.Subhire
|
||||
form_class = forms.SubhireForm
|
||||
template_name = 'subhire_form.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['page_title'] = "New Subhire"
|
||||
context['edit'] = True
|
||||
form = context['form']
|
||||
get_related(form, context)
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('subhire_detail', kwargs={'pk': self.object.pk})
|
||||
|
||||
48
RIGS/views/subhire.py
Normal file
48
RIGS/views/subhire.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from django.urls import reverse_lazy
|
||||
from django.views import generic
|
||||
from PyRIGS.views import OEmbedView, is_ajax, ModalURLMixin, PrintView, get_related
|
||||
from RIGS import models, forms
|
||||
|
||||
|
||||
class SubhireDetail(generic.DetailView, ModalURLMixin):
|
||||
template_name = 'subhire_detail.html'
|
||||
model = models.Subhire
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['page_title'] = f"{self.object.display_id} | {self.object.name}"
|
||||
return context
|
||||
|
||||
|
||||
class SubhireCreate(generic.CreateView):
|
||||
model = models.Subhire
|
||||
form_class = forms.SubhireForm
|
||||
template_name = 'subhire_form.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['page_title'] = "New Subhire"
|
||||
context['edit'] = True
|
||||
form = context['form']
|
||||
get_related(form, context)
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('subhire_detail', kwargs={'pk': self.object.pk})
|
||||
|
||||
|
||||
class SubhireEdit(generic.UpdateView):
|
||||
model = models.Subhire
|
||||
form_class = forms.SubhireForm
|
||||
template_name = 'subhire_form.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['page_title'] = f"Edit Subhire: {self.object.display_id} | {self.object.name}"
|
||||
context['edit'] = True
|
||||
form = context['form']
|
||||
get_related(form, context)
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('subhire_detail', kwargs={'pk': self.object.pk})
|
||||
Reference in New Issue
Block a user