mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-16 21:12:13 +00:00
* 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
59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
from django import forms
|
|
|
|
from assets import models
|
|
from django.db.models import Q
|
|
|
|
|
|
class AssetForm(forms.ModelForm):
|
|
related_models = {
|
|
'asset': models.Asset,
|
|
'supplier': models.Supplier
|
|
}
|
|
|
|
class Meta:
|
|
model = models.Asset
|
|
fields = '__all__'
|
|
exclude = ['asset_id_prefix', 'asset_id_number', 'last_audited_at', 'last_audited_by']
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.fields['date_sold'].widget.format = '%Y-%m-%d'
|
|
self.fields['date_acquired'].widget.format = '%Y-%m-%d'
|
|
|
|
|
|
class AssetAuditForm(AssetForm):
|
|
class Meta(AssetForm.Meta):
|
|
# Prevents assets losing existing data that isn't included in the audit form
|
|
exclude = ['asset_id_prefix', 'asset_id_number', 'last_audited_at', 'last_audited_by',
|
|
'parent', 'purchased_from', 'purchase_price', 'comments']
|
|
|
|
|
|
class AssetSearchForm(forms.Form):
|
|
query = forms.CharField(required=False)
|
|
category = forms.ModelMultipleChoiceField(models.AssetCategory.objects.all(), required=False)
|
|
status = forms.ModelMultipleChoiceField(models.AssetStatus.objects.all(), required=False)
|
|
|
|
|
|
class SupplierForm(forms.ModelForm):
|
|
class Meta:
|
|
model = models.Supplier
|
|
fields = '__all__'
|
|
|
|
|
|
class SupplierSearchForm(forms.Form):
|
|
query = forms.CharField(required=False)
|
|
|
|
|
|
class CableTypeForm(forms.ModelForm):
|
|
class Meta:
|
|
model = models.CableType
|
|
fields = '__all__'
|
|
|
|
def clean(self):
|
|
form_data = self.cleaned_data
|
|
queryset = models.CableType.objects.filter(Q(plug=form_data['plug']) & Q(socket=form_data['socket']) & Q(circuits=form_data['circuits']) & Q(cores=form_data['cores']))
|
|
# Being identical to itself shouldn't count...
|
|
if queryset.exists() and self.instance.pk != queryset[0].pk:
|
|
raise forms.ValidationError("A cable type that exactly matches this one already exists, please use that instead.", code="notunique")
|
|
return form_data
|