From a77f46d6979aa155a3905f6aafd3850c86052daa Mon Sep 17 00:00:00 2001 From: stefan Date: Sat, 16 Nov 2024 13:22:59 +0100 Subject: [PATCH] added verbose name to storages to be printed on labels etc. --- shimatta_kenkyusho/api/serializers.py | 2 +- shimatta_kenkyusho/parts/forms.py | 3 ++- .../migrations/0012_storage_verbose_name.py | 18 ++++++++++++++++++ shimatta_kenkyusho/parts/models.py | 1 + shimatta_kenkyusho/parts/views.py | 3 +++ .../templates/parts/stocks-detail.html | 3 +++ shimatta_kenkyusho/templates/parts/stocks.html | 2 +- 7 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 shimatta_kenkyusho/parts/migrations/0012_storage_verbose_name.py diff --git a/shimatta_kenkyusho/api/serializers.py b/shimatta_kenkyusho/api/serializers.py index 7bf01a8..4c404cb 100644 --- a/shimatta_kenkyusho/api/serializers.py +++ b/shimatta_kenkyusho/api/serializers.py @@ -29,7 +29,7 @@ class StorageSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = parts_models.Storage - fields = ['url', 'id', 'name', 'parent_storage', 'responsible', 'full_path'] + fields = ['url', 'id', 'name', 'verbose_name', 'parent_storage', 'responsible', 'template', 'full_path'] class ComponentSerializer(serializers.HyperlinkedModelSerializer): package_data = PackageSerializerNoLink(source='package', read_only=True) diff --git a/shimatta_kenkyusho/parts/forms.py b/shimatta_kenkyusho/parts/forms.py index fbbf9fd..6d94b08 100644 --- a/shimatta_kenkyusho/parts/forms.py +++ b/shimatta_kenkyusho/parts/forms.py @@ -92,7 +92,8 @@ class MyTestForm(forms.Form): pass class ChangeStorageForm(forms.Form): - storage_name = forms.CharField(label="storage_name", initial='') + storage_name = forms.CharField(label="Name", initial='') + verbose_name = forms.CharField(label="Verbose Name", initial='') responsible = AutocompleteForeingKeyField(api_search_url='user-list', image_field_name=None, name_field_name='username', diff --git a/shimatta_kenkyusho/parts/migrations/0012_storage_verbose_name.py b/shimatta_kenkyusho/parts/migrations/0012_storage_verbose_name.py new file mode 100644 index 0000000..5ad2741 --- /dev/null +++ b/shimatta_kenkyusho/parts/migrations/0012_storage_verbose_name.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.5 on 2024-11-16 11:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('parts', '0011_auto_20241110_1242'), + ] + + operations = [ + migrations.AddField( + model_name='storage', + name='verbose_name', + field=models.CharField(blank=True, max_length=100, null=True), + ), + ] diff --git a/shimatta_kenkyusho/parts/models.py b/shimatta_kenkyusho/parts/models.py index f5c3de8..b78ebf8 100644 --- a/shimatta_kenkyusho/parts/models.py +++ b/shimatta_kenkyusho/parts/models.py @@ -62,6 +62,7 @@ class Storage(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True) name = models.CharField(max_length=100, validators=[storage_name_validator]) + verbose_name = models.CharField(max_length=100, null=True, blank=True) parent_storage = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True) responsible = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, blank=True, null=True) diff --git a/shimatta_kenkyusho/parts/views.py b/shimatta_kenkyusho/parts/views.py index 585f19f..6de8672 100644 --- a/shimatta_kenkyusho/parts/views.py +++ b/shimatta_kenkyusho/parts/views.py @@ -484,6 +484,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView): context['add_storage_form'] = add_storage_form change_storage_form = ChangeStorageForm() change_storage_form.fields['storage_name'].initial = self.object.name + change_storage_form.fields['verbose_name'].initial = self.object.verbose_name change_storage_form.fields['responsible'].initial = self.object.responsible.id change_storage_form.fields['is_template'].initial = self.object.is_template context['change_storage_form'] = change_storage_form @@ -498,6 +499,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView): sub_name = f.cleaned_data['storage_name'] try: Storage.objects.create(name=sub_name, + verbose_name=f.cleaned_data.get('verbose_name'), parent_storage=self.object, responsible=f.cleaned_data['responsible'], is_template=f.cleaned_data['is_template'], @@ -514,6 +516,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView): sub_name = f.cleaned_data['storage_name'] try: self.object.name = f.cleaned_data['storage_name'] + self.object.verbose_name = f.cleaned_data.get('verbose_name') self.object.responsible = f.cleaned_data['responsible'] self.object.is_template = f.cleaned_data['is_template'] self.object.save() diff --git a/shimatta_kenkyusho/templates/parts/stocks-detail.html b/shimatta_kenkyusho/templates/parts/stocks-detail.html index 4276312..4d969f6 100644 --- a/shimatta_kenkyusho/templates/parts/stocks-detail.html +++ b/shimatta_kenkyusho/templates/parts/stocks-detail.html @@ -20,6 +20,9 @@
{% qr_from_text object.get_qr_code size="m" image_format="svg" %}
+
+

{{storage.name}}{% if storage.verbose_name %} ({{storage.verbose_name}}){% endif %}

+
{% if object.parent_storage %}

Sub-Storages Parent Storage {% else %} diff --git a/shimatta_kenkyusho/templates/parts/stocks.html b/shimatta_kenkyusho/templates/parts/stocks.html index 38147c6..a3ead93 100644 --- a/shimatta_kenkyusho/templates/parts/stocks.html +++ b/shimatta_kenkyusho/templates/parts/stocks.html @@ -40,7 +40,7 @@
  • -
    {{storage.name}}
    +
    {{storage.name}}{% if storage.verbose_name %} ({{storage.verbose_name}}){% endif %}
    Responsible: {{ storage.responsible }}
    {{storage.get_total_stock_amount}}