mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-18 05:52:15 +00:00
Merge branch 'master' into training
# Conflicts: # RIGS/models.py
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
from django.db import models, migrations
|
||||
import RIGS.models
|
||||
import versioning
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@@ -25,6 +26,6 @@ class Migration(migrations.Migration):
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model, RIGS.models.RevisionMixin),
|
||||
bases=(models.Model, versioning.versioning.RevisionMixin),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from django.db import models, migrations
|
||||
import RIGS.models
|
||||
import versioning
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@@ -21,6 +22,6 @@ class Migration(migrations.Migration):
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model, RIGS.models.RevisionMixin),
|
||||
bases=(models.Model, versioning.versioning.RevisionMixin),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
from django.db import models, migrations
|
||||
from django.conf import settings
|
||||
import RIGS.models
|
||||
import versioning
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@@ -41,7 +42,7 @@ class Migration(migrations.Migration):
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model, RIGS.models.RevisionMixin),
|
||||
bases=(models.Model, versioning.versioning.RevisionMixin),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='EventItem',
|
||||
@@ -70,7 +71,7 @@ class Migration(migrations.Migration):
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model, RIGS.models.RevisionMixin),
|
||||
bases=(models.Model, versioning.versioning.RevisionMixin),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='event',
|
||||
|
||||
@@ -4,6 +4,7 @@ import RIGS.models
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import versioning
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@@ -58,7 +59,7 @@ class Migration(migrations.Migration):
|
||||
'ordering': ['event'],
|
||||
'permissions': [('review_eventchecklist', 'Can review Event Checklists')],
|
||||
},
|
||||
bases=(models.Model, RIGS.models.RevisionMixin),
|
||||
bases=(models.Model, versioning.versioning.RevisionMixin),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='EventChecklistCrew',
|
||||
@@ -69,7 +70,7 @@ class Migration(migrations.Migration):
|
||||
('end', models.DateTimeField()),
|
||||
('checklist', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, related_name='crew', to='RIGS.eventchecklist')),
|
||||
],
|
||||
bases=(models.Model, RIGS.models.RevisionMixin),
|
||||
bases=(models.Model, versioning.versioning.RevisionMixin),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='EventChecklistVehicle',
|
||||
@@ -78,7 +79,7 @@ class Migration(migrations.Migration):
|
||||
('vehicle', models.CharField(max_length=255)),
|
||||
('checklist', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, related_name='vehicles', to='RIGS.eventchecklist')),
|
||||
],
|
||||
bases=(models.Model, RIGS.models.RevisionMixin),
|
||||
bases=(models.Model, versioning.versioning.RevisionMixin),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='RiskAssessment',
|
||||
@@ -117,7 +118,7 @@ class Migration(migrations.Migration):
|
||||
'ordering': ['event'],
|
||||
'permissions': [('review_riskassessment', 'Can review Risk Assessments')],
|
||||
},
|
||||
bases=(models.Model, RIGS.models.RevisionMixin),
|
||||
bases=(models.Model, versioning.versioning.RevisionMixin),
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='eventcrew',
|
||||
|
||||
@@ -33,6 +33,7 @@ class AssetSearchForm(forms.Form):
|
||||
category = forms.ModelMultipleChoiceField(models.AssetCategory.objects.all(), required=False)
|
||||
status = forms.ModelMultipleChoiceField(models.AssetStatus.objects.all(), required=False)
|
||||
is_cable = forms.BooleanField(required=False)
|
||||
date_acquired = forms.DateField(required=False)
|
||||
|
||||
|
||||
class SupplierForm(forms.ModelForm):
|
||||
|
||||
@@ -6,7 +6,8 @@ from django.urls import reverse
|
||||
from reversion import revisions as reversion
|
||||
from reversion.models import Version
|
||||
|
||||
from RIGS.models import RevisionMixin, Profile
|
||||
from RIGS.models import Profile
|
||||
from versioning.versioning import RevisionMixin
|
||||
|
||||
|
||||
class AssetCategory(models.Model):
|
||||
|
||||
@@ -61,25 +61,45 @@
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col px-0">
|
||||
<form id="asset-search-form" method="GET" class="form-inline justify-content-end">
|
||||
<div class="input-group px-1 mb-2 mb-sm-0 flex-nowrap">
|
||||
{% render_field form.q|add_class:'form-control' placeholder='Enter Asset ID/Desc/Serial' %}
|
||||
<label for="q" class="sr-only">Asset ID/Description/Serial Number:</label>
|
||||
<span class="input-group-append">{% button 'search' id="id_search" %}</span>
|
||||
</div>
|
||||
<div id="category-group" class="form-group px-1" style="margin-bottom: 0;">
|
||||
<label for="category" class="sr-only">Category</label>
|
||||
{% render_field form.category|attr:'multiple'|add_class:'form-control custom-select selectpicker col-sm' data-none-selected-text="Categories" data-header="Categories" data-actions-box="true" %}
|
||||
</div>
|
||||
<div id="status-group" class="form-group px-1" style="margin-bottom: 0;">
|
||||
<label for="status" class="sr-only">Status</label>
|
||||
{% render_field form.status|attr:'multiple'|add_class:'form-control custom-select selectpicker col-sm' data-none-selected-text="Statuses" data-header="Statuses" data-actions-box="true" %}
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
{% render_field form.is_cable|add_class:'form-check-input' %}
|
||||
<label class="form-check-label" for="is_cable">Only Cables?</label>
|
||||
</div>
|
||||
<button id="filter-submit" type="submit" class="btn btn-secondary" style="width: 6em">Filter</button>
|
||||
<form id="asset-search-form" method="GET">
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<div class="input-group px-1 mb-2 mb-sm-0 flex-nowrap">
|
||||
{% render_field form.q|add_class:'form-control' placeholder='Enter Asset ID/Desc/Serial' %}
|
||||
<label for="q" class="sr-only">Asset ID/Description/Serial Number:</label>
|
||||
<span class="input-group-append">{% button 'search' id="id_search" %}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row mt-2">
|
||||
<div class="col">
|
||||
<div id="category-group" class="form-group px-1" style="margin-bottom: 0;">
|
||||
<label for="category" class="sr-only">Category</label>
|
||||
{% render_field form.category|attr:'multiple'|add_class:'form-control custom-select selectpicker col-sm' data-none-selected-text="Categories" data-header="Categories" data-actions-box="true" %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div id="status-group" class="form-group px-1" style="margin-bottom: 0;">
|
||||
<label for="status" class="sr-only">Status</label>
|
||||
{% render_field form.status|attr:'multiple'|add_class:'form-control custom-select selectpicker col-sm' data-none-selected-text="Statuses" data-header="Statuses" data-actions-box="true" %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col mt-2">
|
||||
<div class="form-check form-check-inline">
|
||||
{% render_field form.is_cable|add_class:'form-check-input' %}
|
||||
<label class="form-check-label" for="is_cable">Only Cables?</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<div class="form-group d-flex flex-nowrap">
|
||||
<label for="date_acquired" class="text-nowrap mt-auto">Date Acquired</label>
|
||||
{% render_field form.date_acquired|add_class:'form-control mx-2' %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto mr-auto">
|
||||
<button id="filter-submit" type="submit" class="btn btn-secondary" style="width: 6em">Filter</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -61,6 +61,9 @@ class AssetList(LoginRequiredMixin, generic.ListView):
|
||||
if form.cleaned_data['is_cable']:
|
||||
queryset = queryset.filter(is_cable=True)
|
||||
|
||||
if form.cleaned_data['date_acquired']:
|
||||
queryset = queryset.filter(date_acquired=form.cleaned_data['date_acquired'])
|
||||
|
||||
if form.cleaned_data['category']:
|
||||
queryset = queryset.filter(category__in=form.cleaned_data['category'])
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import logging
|
||||
|
||||
from diff_match_patch import diff_match_patch
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
@@ -7,9 +5,42 @@ from django.db.models import EmailField, IntegerField, TextField, CharField, Boo
|
||||
from django.utils.functional import cached_property
|
||||
from reversion.models import Version, VersionQuerySet
|
||||
|
||||
from RIGS import models
|
||||
|
||||
logger = logging.getLogger('tec.pyrigs')
|
||||
class RevisionMixin:
|
||||
@property
|
||||
def is_first_version(self):
|
||||
versions = Version.objects.get_for_object(self)
|
||||
return len(versions) == 1
|
||||
|
||||
@property
|
||||
def current_version(self):
|
||||
version = Version.objects.get_for_object(self).select_related('revision').first()
|
||||
return version
|
||||
|
||||
@property
|
||||
def last_edited_at(self):
|
||||
version = self.current_version
|
||||
if version is None:
|
||||
return None
|
||||
return version.revision.date_created
|
||||
|
||||
@property
|
||||
def last_edited_by(self):
|
||||
version = self.current_version
|
||||
if version is None:
|
||||
return None
|
||||
return version.revision.user
|
||||
|
||||
@property
|
||||
def current_version_id(self):
|
||||
version = self.current_version
|
||||
if version is None:
|
||||
return None
|
||||
return "V{0} | R{1}".format(version.pk, version.revision.pk)
|
||||
|
||||
@property
|
||||
def date_created(self):
|
||||
return self.current_version.revision.date_created
|
||||
|
||||
|
||||
class FieldComparison:
|
||||
@@ -116,10 +147,11 @@ class ModelComparison:
|
||||
|
||||
@cached_property
|
||||
def item_changes(self):
|
||||
from RIGS.models import EventAuthorisation
|
||||
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).exclude(content_type=ContentType.objects.get_for_model(models.EventAuthorisation))
|
||||
new_item_versions = self.version.revision.version_set.exclude(content_type=item_type).exclude(content_type=ContentType.objects.get_for_model(EventAuthorisation))
|
||||
|
||||
comparisonParams = {'excluded_keys': ['id', 'event', 'order', 'checklist', 'level', '_order', 'date_joined']}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user