mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Create initial asset audit framework (#403)
* WIP: Basic work on audit * WIP: Audit modal works Need to get the ID search working. * WIP: Javascript shenanigans for asset audit search It's not clean but it works.. * Improve audit search bar Optimise for APM! * Filter asset audit list by never-audited * Added cable functionality to audit form Also improved styling * FIX: Revert partialising of asset search * Various UX Improvements Also rearranged asset detail/edit to be more space efficient * FIX: Remove assets from to-be-audited table when audited Previously required a page reload * Improve sample data generator Does reversion properly and sets colours for asset statuses * FIX: Gracefully handle 404s in audit search * FEAT: Add buttons for some common defaults on audit form TODO: Partialise those fragments and add them to the edit/create forms too. * FIX: Fix asset sample data command when run alone * FEAT: More handy buttons * FIX: Stop quickbuttons being tab-selected If someone's tabbing through, they won't be needing the buttons... * FIX: Hide asset detail buttons for basic users * FIX: Migrations * Start tests for audit * Some deduplication for testing code * Improve asset audit testing * Remember to test the tests Arona * Potentially make modal tests more consistent * FIX?: Up WebDriverWait timeout for modal tests * FIX?: What about this way... * Remake migrations * Fix README badges to point to right branch While I'm here eh :P * Use aware time in audit * Fix migrations again * Fix for my fix... * Modify audit exclusions to properly prevent data loss * pep eiiiiiight
This commit is contained in:
@@ -4,13 +4,17 @@ from django.http import HttpResponse, Http404
|
||||
from django.views import generic
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.urls import reverse
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.core import serializers
|
||||
from django.contrib import messages
|
||||
from assets import models, forms
|
||||
from RIGS import versioning
|
||||
|
||||
import simplejson
|
||||
import datetime
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name='dispatch')
|
||||
@@ -109,7 +113,14 @@ class AssetEdit(LoginRequiredMixin, AssetIDUrlMixin, generic.UpdateView):
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("asset_detail", kwargs={"pk": self.object.asset_id})
|
||||
if self.request.is_ajax():
|
||||
url = reverse_lazy('closemodal')
|
||||
update_url = str(reverse_lazy('asset_update', kwargs={'pk': self.object.pk}))
|
||||
messages.info(self.request, "modalobject=" + serializers.serialize("json", [self.object]))
|
||||
messages.info(self.request, "modalobject[0]['update_url']='" + update_url + "'")
|
||||
else:
|
||||
url = reverse_lazy('asset_detail', kwargs={'pk': self.object.asset_id, })
|
||||
return url
|
||||
|
||||
|
||||
class AssetCreate(LoginRequiredMixin, generic.CreateView):
|
||||
@@ -173,6 +184,30 @@ class AssetEmbed(AssetDetail):
|
||||
template_name = 'asset_embed.html'
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name='dispatch')
|
||||
class AssetAuditList(AssetList):
|
||||
template_name = 'asset_audit_list.html'
|
||||
hide_hidden_status = False
|
||||
|
||||
# TODO Refresh this when the modal is submitted
|
||||
def get_queryset(self):
|
||||
self.form = forms.AssetSearchForm(data={})
|
||||
return self.model.objects.filter(Q(last_audited_at__isnull=True))
|
||||
|
||||
|
||||
class AssetAudit(AssetEdit):
|
||||
template_name = 'asset_audit.html'
|
||||
form_class = forms.AssetAuditForm
|
||||
|
||||
def get_success_url(self):
|
||||
# TODO For some reason this doesn't stick when done in form_valid??
|
||||
asset = self.get_object()
|
||||
asset.last_audited_by = self.request.user
|
||||
asset.last_audited_at = timezone.now()
|
||||
asset.save()
|
||||
return super().get_success_url()
|
||||
|
||||
|
||||
class SupplierList(generic.ListView):
|
||||
model = models.Supplier
|
||||
template_name = 'supplier_list.html'
|
||||
|
||||
Reference in New Issue
Block a user