Compare commits

..

No commits in common. "032c4fc8382797d6b59c4f783cbfba749f30f182" and "35b99e1b187e146df1ce94bae236c87d297cecec" have entirely different histories.

5 changed files with 2 additions and 79 deletions

View File

@ -44,7 +44,6 @@ class ComponentSerializer(serializers.HyperlinkedModelSerializer):
ro_component_type = serializers.ReadOnlyField(source='component_type.class_name')
ro_parameters = ComponentParameterSerializer(many=True, source='componentparameter_set', read_only=True)
ro_distributor_numbers = ComponentDistributorNumSerializer(many=True, source='distributornum_set', read_only=True)
ro_dynamic_description = serializers.ReadOnlyField(source='dynamic_description')
class Meta:
model = parts_models.Component
@ -61,8 +60,7 @@ class ComponentSerializer(serializers.HyperlinkedModelSerializer):
'ro_image',
'ro_component_type',
'ro_parameters',
'ro_distributor_numbers',
'ro_dynamic_description']
'ro_distributor_numbers']
class StockSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField()

View File

@ -1,18 +0,0 @@
# Generated by Django 5.1.3 on 2025-01-31 21:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('parts', '0014_storage_expand_sub_storage_stocks'),
]
operations = [
migrations.AddField(
model_name='componenttype',
name='description_template',
field=models.TextField(blank=True),
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 5.1.3 on 2025-01-31 21:44
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('parts', '0015_componenttype_description_template'),
]
operations = [
migrations.AddField(
model_name='componentparametertype',
name='interfix',
field=models.CharField(blank=True, max_length=10),
),
]

View File

@ -6,7 +6,6 @@ from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.dispatch import receiver
from django.core.validators import MinValueValidator, MaxValueValidator
from django.template import engines
import os
import uuid
from shimatta_modules.EngineeringNumberConverter import EngineeringNumberConverter as NumConv
@ -30,7 +29,6 @@ class ComponentParameterType(models.Model):
parameter_name = models.CharField(max_length=50, unique=True)
parameter_description = models.TextField(null=False, blank=True)
unit = models.CharField(max_length=10, null=False, blank=True)
interfix = models.CharField(max_length=10, null=False, blank=True, help_text="char to be used as decimal point in dynamic description eg. 2R2")
parameter_type = models.CharField(max_length=1, choices=TYPE_CHOICES, default='N')
def __str__(self):
@ -51,9 +49,6 @@ class ComponentType(models.Model):
class_name = models.CharField(max_length=50, unique=True)
passive = models.BooleanField()
possible_parameter = models.ManyToManyField(ComponentParameterType, blank=True)
description_template = models.TextField(blank=True,
help_text="Template to assemble the dynamic description. "
"Use template syntax, access the component with 'object', parameters with 'param_*'.")
def __str__(self):
return '[' + self.class_name + ']'
@ -273,18 +268,6 @@ class Component(models.Model):
if sum is None:
sum = 0
return sum
@property
def dynamic_description(self):
django_engine = engines["django"]
template = django_engine.from_string(self.component_type.description_template)
parameters = list(ComponentParameter.objects.filter(component=self))
parameters += list(PackageParameter.objects.filter(package=self.package))
context = {f'param_{param.parameter_type.parameter_name}': param for param in parameters}
context.update({'object': self})
return template.render(context)
class AbstractParameter(models.Model):
class Meta:
@ -319,25 +302,6 @@ class AbstractParameter(models.Model):
elif my_type == 'F':
return self.text_value
def resolved_value_as_short_string(self):
my_type = self.parameter_type.parameter_type
if my_type == 'E' or my_type == 'I':
# Engineering float number
(num, prefix) = NumConv.number_to_engineering(self.value, it_unit=(True if my_type=='I' else False))
result = f'{num:g}'
interpostfix = (prefix if prefix else self.parameter_type.interfix or '.')
if '.' in result:
result = result.replace('.', interpostfix)
else:
result = result + interpostfix
return result
elif my_type == 'N':
# Standard float number
return f'{self.value:g}{self.parameter_type.unit}'
else:
return self.resolved_value_as_string()
class ComponentParameter(AbstractParameter):
class Meta:
unique_together = ('component', 'parameter_type')

View File

@ -101,10 +101,7 @@
<span class="text-secondary"><br>Lot: {{stock.lot}}</span>
{% endif %}
</div>
<div class="flex-grow-2 ms-3 d-none d-lg-block" style="text-align: center;">
<pre>{{ stock.component.dynamic_description }}</pre>
</div>
<div class="flex-grow-2 ms-5 d-none d-lg-block">
<div class="flex-grow-2 ms-3 d-none d-lg-block">
{% qr_from_text stock.get_qr_code size="6" image_format="svg" %}
</div>
<div class="ms-3">