From 82a30ca77d2d3e7e312b39f986734c4c7fcf7019 Mon Sep 17 00:00:00 2001 From: Arona Jones Date: Fri, 3 Jan 2020 21:46:39 +0000 Subject: [PATCH] Miscellaneous changes to the Asset DB (#390) * FIX #388: Prevent assets losing supplier data on edit * FEAT: Add associated assets to supplier detail view * FIX: Tweak supplier list to make detail view accessible * Potential fix for #380 No idea if it works because I can't reproduce locally. S/O Reckons it should... :P * FEAT #386: Asset search searches serial number. Pending addition of advanced search. * FIX: Order asset categories/statuses alphabetically Instead of by pk because that's silly. * FEAT: Statuses can have a CSS class defined in the admin panel This replaces the hardcoding of colours in the asset list. * FIX: Squash migrations * Fixed supplier not working on all the create asset template * Refactored away "assets" property on "Supplier" by using "related_name" instead Co-authored-by: Matthew Smith --- RIGS/views.py | 3 + assets/filters.py | 2 +- assets/forms.py | 5 ++ assets/migrations/0009_auto_20200102_1933.py | 21 ++++++ ...2_1933_squashed_0011_auto_20200102_2040.py | 28 +++++++ .../0010_assetstatus_display_class.py | 18 +++++ assets/migrations/0010_auto_20200103_2134.py | 19 +++++ assets/migrations/0011_auto_20200102_2040.py | 18 +++++ assets/models.py | 5 +- assets/templates/asset_create.html | 1 - assets/templates/asset_list.html | 4 +- assets/templates/asset_update.html | 1 - .../partials/asset_list_table_body.html | 16 +--- .../partials/purchasedetails_form.html | 25 ++++++- .../templates/partials/supplier_picker.html | 64 ---------------- assets/templates/supplier_detail.html | 73 ++++++++++++++++++- assets/templates/supplier_list.html | 2 +- assets/views.py | 2 +- templates/base_assets.html | 5 ++ 19 files changed, 220 insertions(+), 92 deletions(-) create mode 100644 assets/migrations/0009_auto_20200102_1933.py create mode 100644 assets/migrations/0009_auto_20200102_1933_squashed_0011_auto_20200102_2040.py create mode 100644 assets/migrations/0010_assetstatus_display_class.py create mode 100644 assets/migrations/0010_auto_20200103_2134.py create mode 100644 assets/migrations/0011_auto_20200102_2040.py delete mode 100644 assets/templates/partials/supplier_picker.html diff --git a/RIGS/views.py b/RIGS/views.py index b197334c..023f0089 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -17,6 +17,7 @@ from django.views.decorators.csrf import csrf_exempt from RIGS import models, forms +from assets import models as asset_models from functools import reduce """ @@ -248,6 +249,7 @@ class SecureAPIRequest(generic.View): 'organisation': models.Organisation, 'profile': models.Profile, 'event': models.Event, + 'supplier': asset_models.Supplier } perms = { @@ -256,6 +258,7 @@ class SecureAPIRequest(generic.View): 'organisation': 'RIGS.view_organisation', 'profile': 'RIGS.view_profile', 'event': None, + 'supplier': None } ''' diff --git a/assets/filters.py b/assets/filters.py index c7efcd7f..b7cc8ffa 100644 --- a/assets/filters.py +++ b/assets/filters.py @@ -6,4 +6,4 @@ from assets import models class AssetFilter(django_filters.FilterSet): class Meta: model = models.Asset - fields = ['asset_id', 'description', 'category', 'status'] + fields = ['asset_id', 'description', 'serial_number', 'category', 'status'] diff --git a/assets/forms.py b/assets/forms.py index 7571d28b..ea05efd3 100644 --- a/assets/forms.py +++ b/assets/forms.py @@ -4,6 +4,11 @@ from assets import models class AssetForm(forms.ModelForm): + related_models = { + 'asset': models.Asset, + 'supplier': models.Supplier + } + class Meta: model = models.Asset fields = '__all__' diff --git a/assets/migrations/0009_auto_20200102_1933.py b/assets/migrations/0009_auto_20200102_1933.py new file mode 100644 index 00000000..57f745a1 --- /dev/null +++ b/assets/migrations/0009_auto_20200102_1933.py @@ -0,0 +1,21 @@ +# Generated by Django 2.0.13 on 2020-01-02 19:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0008_auto_20191206_2124'), + ] + + operations = [ + migrations.AlterModelOptions( + name='assetcategory', + options={'ordering': ['name'], 'verbose_name': 'Asset Category', 'verbose_name_plural': 'Asset Categories'}, + ), + migrations.AlterModelOptions( + name='assetstatus', + options={'ordering': ['name'], 'verbose_name': 'Asset Status', 'verbose_name_plural': 'Asset Statuses'}, + ), + ] diff --git a/assets/migrations/0009_auto_20200102_1933_squashed_0011_auto_20200102_2040.py b/assets/migrations/0009_auto_20200102_1933_squashed_0011_auto_20200102_2040.py new file mode 100644 index 00000000..649c419c --- /dev/null +++ b/assets/migrations/0009_auto_20200102_1933_squashed_0011_auto_20200102_2040.py @@ -0,0 +1,28 @@ +# Generated by Django 2.0.13 on 2020-01-02 20:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + replaces = [('assets', '0009_auto_20200102_1933'), ('assets', '0010_assetstatus_display_class'), ('assets', '0011_auto_20200102_2040')] + + dependencies = [ + ('assets', '0008_auto_20191206_2124'), + ] + + operations = [ + migrations.AlterModelOptions( + name='assetcategory', + options={'ordering': ['name'], 'verbose_name': 'Asset Category', 'verbose_name_plural': 'Asset Categories'}, + ), + migrations.AlterModelOptions( + name='assetstatus', + options={'ordering': ['name'], 'verbose_name': 'Asset Status', 'verbose_name_plural': 'Asset Statuses'}, + ), + migrations.AddField( + model_name='assetstatus', + name='display_class', + field=models.CharField(help_text='HTML class to be appended to alter display of assets with this status, such as in the list.', max_length=80), + ), + ] diff --git a/assets/migrations/0010_assetstatus_display_class.py b/assets/migrations/0010_assetstatus_display_class.py new file mode 100644 index 00000000..f2521ea0 --- /dev/null +++ b/assets/migrations/0010_assetstatus_display_class.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.13 on 2020-01-02 19:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0009_auto_20200102_1933'), + ] + + operations = [ + migrations.AddField( + model_name='assetstatus', + name='display_class', + field=models.TextField(default='', help_text='HTML class to be appended to alter display of assets with this status, such as in the list.'), + ), + ] diff --git a/assets/migrations/0010_auto_20200103_2134.py b/assets/migrations/0010_auto_20200103_2134.py new file mode 100644 index 00000000..91d2a131 --- /dev/null +++ b/assets/migrations/0010_auto_20200103_2134.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.13 on 2020-01-03 21:34 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0009_auto_20200102_1933_squashed_0011_auto_20200102_2040'), + ] + + operations = [ + migrations.AlterField( + model_name='asset', + name='purchased_from', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='assets', to='assets.Supplier'), + ), + ] diff --git a/assets/migrations/0011_auto_20200102_2040.py b/assets/migrations/0011_auto_20200102_2040.py new file mode 100644 index 00000000..d89aa0ad --- /dev/null +++ b/assets/migrations/0011_auto_20200102_2040.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.13 on 2020-01-02 20:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0010_assetstatus_display_class'), + ] + + operations = [ + migrations.AlterField( + model_name='assetstatus', + name='display_class', + field=models.CharField(help_text='HTML class to be appended to alter display of assets with this status, such as in the list.', max_length=80), + ), + ] diff --git a/assets/models.py b/assets/models.py index 2398a563..f152a39a 100644 --- a/assets/models.py +++ b/assets/models.py @@ -16,6 +16,7 @@ class AssetCategory(models.Model): class Meta: verbose_name = 'Asset Category' verbose_name_plural = 'Asset Categories' + ordering = ['name'] name = models.CharField(max_length=80) @@ -27,10 +28,12 @@ class AssetStatus(models.Model): class Meta: verbose_name = 'Asset Status' verbose_name_plural = 'Asset Statuses' + ordering = ['name'] name = models.CharField(max_length=80) should_show = models.BooleanField( default=True, help_text="Should this be shown by default in the asset list.") + display_class = models.CharField(max_length=80, help_text="HTML class to be appended to alter display of assets with this status, such as in the list.") def __str__(self): return self.name @@ -78,7 +81,7 @@ class Asset(models.Model, RevisionMixin): category = models.ForeignKey(to=AssetCategory, on_delete=models.CASCADE) status = models.ForeignKey(to=AssetStatus, on_delete=models.CASCADE) serial_number = models.CharField(max_length=150, blank=True) - purchased_from = models.ForeignKey(to=Supplier, on_delete=models.CASCADE, blank=True, null=True) + purchased_from = models.ForeignKey(to=Supplier, on_delete=models.CASCADE, blank=True, null=True, related_name="assets") date_acquired = models.DateField() date_sold = models.DateField(blank=True, null=True) purchase_price = models.DecimalField(blank=True, null=True, decimal_places=2, max_digits=10) diff --git a/assets/templates/asset_create.html b/assets/templates/asset_create.html index b0bb8297..bc953d2d 100644 --- a/assets/templates/asset_create.html +++ b/assets/templates/asset_create.html @@ -3,7 +3,6 @@ {% load asset_templatetags %} {% block title %}Asset {{ object.asset_id }}{% endblock %} - {% block content %}