Implement key parameter rendering for components. In Stock viewer still missing
This commit is contained in:
parent
ea623212bb
commit
a566e198b8
@ -240,6 +240,33 @@ class Component(models.Model):
|
|||||||
sum = 0
|
sum = 0
|
||||||
return sum
|
return sum
|
||||||
|
|
||||||
|
def get_key_parameters(self):
|
||||||
|
"""
|
||||||
|
Get the key parameters of a component defined by its component type.
|
||||||
|
Returns a tuple of 3 elements. All three might be None
|
||||||
|
"""
|
||||||
|
p1 = None
|
||||||
|
p2 = None
|
||||||
|
p3 = None
|
||||||
|
|
||||||
|
if self.component_type:
|
||||||
|
t = (self.component_type.key_parameter1, self.component_type.key_parameter2, self.component_type.key_parameter3)
|
||||||
|
if t[0]:
|
||||||
|
p1 = ComponentParameter.objects.filter(component=self, parameter_type=t[0]).first()
|
||||||
|
if t[1]:
|
||||||
|
p2 = ComponentParameter.objects.filter(component=self, parameter_type=t[1]).first()
|
||||||
|
if t[2]:
|
||||||
|
p3 = ComponentParameter.objects.filter(component=self, parameter_type=t[2]).first()
|
||||||
|
|
||||||
|
return (p1, p2, p3)
|
||||||
|
|
||||||
|
def get_key_parameters_as_text(self):
|
||||||
|
params = self.get_key_parameters()
|
||||||
|
ret_strings = []
|
||||||
|
for p in params:
|
||||||
|
if p:
|
||||||
|
ret_strings.append(p.resolved_value_as_string())
|
||||||
|
return ret_strings
|
||||||
|
|
||||||
class ComponentParameter(models.Model):
|
class ComponentParameter(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -265,10 +292,12 @@ class ComponentParameter(models.Model):
|
|||||||
if my_type == 'E' or my_type == 'I':
|
if my_type == 'E' or my_type == 'I':
|
||||||
# Engineering float number
|
# Engineering float number
|
||||||
(num, prefix) = NumConv.number_to_engineering(self.value, it_unit=(True if my_type=='I' else False))
|
(num, prefix) = NumConv.number_to_engineering(self.value, it_unit=(True if my_type=='I' else False))
|
||||||
return f'{num:.3f} {prefix}{self.parameter_type.unit}'
|
num = round(num, 3)
|
||||||
|
return f'{num} {prefix}{self.parameter_type.unit}'
|
||||||
elif my_type == 'N':
|
elif my_type == 'N':
|
||||||
# Standard float number
|
# Standard float number
|
||||||
return f'{self.value:.3f} {self.parameter_type.unit}'
|
num = round(self.value, 3)
|
||||||
|
return f'{num} {self.parameter_type.unit}'
|
||||||
elif my_type == 'F':
|
elif my_type == 'F':
|
||||||
return self.text_value
|
return self.text_value
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ from django.db import IntegrityError
|
|||||||
from django.db.models import ProtectedError
|
from django.db.models import ProtectedError
|
||||||
from .forms import *
|
from .forms import *
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from django.db.models import Prefetch
|
||||||
from django.db.models.functions import Lower
|
from django.db.models.functions import Lower
|
||||||
from django.forms import formset_factory
|
from django.forms import formset_factory
|
||||||
import uuid
|
import uuid
|
||||||
@ -149,7 +150,7 @@ class ComponentView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
default_page_size = 25
|
default_page_size = 25
|
||||||
|
|
||||||
def get_component_query_set(self, search_string):
|
def get_component_query_set(self, search_string):
|
||||||
queryset = Component.objects.select_related('package', 'manufacturer').all()
|
queryset = Component.objects.select_related('package', 'manufacturer', 'component_type').prefetch_related('componentparameter_set').all()
|
||||||
|
|
||||||
if search_string is None or search_string == '':
|
if search_string is None or search_string == '':
|
||||||
return queryset
|
return queryset
|
||||||
@ -621,7 +622,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
|
|
||||||
class ComponentDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
class ComponentDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
||||||
template_name = 'parts/components-detail.html'
|
template_name = 'parts/components-detail.html'
|
||||||
model = Component
|
queryset = Component.objects.select_related('component_type', 'package', 'manufacturer').prefetch_related('componentparameter_set')
|
||||||
pk_url_kwarg = 'uuid'
|
pk_url_kwarg = 'uuid'
|
||||||
base_title = ''
|
base_title = ''
|
||||||
navbar_selected = 'Components'
|
navbar_selected = 'Components'
|
||||||
@ -639,6 +640,9 @@ class ComponentDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
if self.object.package:
|
if self.object.package:
|
||||||
context['package_parameters'] = PackageParameter.objects.filter(package=self.object.package).order_by('parameter_type__parameter_name')
|
context['package_parameters'] = PackageParameter.objects.filter(package=self.object.package).order_by('parameter_type__parameter_name')
|
||||||
|
|
||||||
|
parameter_texts = self.object.get_key_parameters_as_text()
|
||||||
|
context['key_parameter_string'] = ', '.join(parameter_texts)
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def handle_submit_edit_component_post(self, request, **kwargs):
|
def handle_submit_edit_component_post(self, request, **kwargs):
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle" scope="row">
|
<td class="align-middle" scope="row">
|
||||||
{{component.name}}
|
{{component.name}}{% if key_parameter_string %}<br><span class="text-secondary">{{key_parameter_string}}</span>{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle" >
|
<td class="align-middle" >
|
||||||
{% if component.package %}
|
{% if component.package %}
|
||||||
@ -128,7 +128,7 @@
|
|||||||
<td>
|
<td>
|
||||||
{{param.resolved_value_as_string}}
|
{{param.resolved_value_as_string}}
|
||||||
</td>
|
</td>
|
||||||
<td><span class="text-info">from Package</span></td>
|
<td><span class="text-secondary">from Package</span></td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for param in parameters %}
|
{% for param in parameters %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -48,7 +48,12 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-grow-1 ms-3">
|
<div class="flex-grow-1 ms-3">
|
||||||
<h6 class="mt-0 text-primary">{{ comp.name }}</h6>
|
<h6 class="mt-0 text-primary">
|
||||||
|
{{ comp.name }}
|
||||||
|
{% for key_param in comp.get_key_parameters_as_text %}
|
||||||
|
{{key_param}}
|
||||||
|
{% endfor %}
|
||||||
|
</h6>
|
||||||
{% if comp.package %}
|
{% if comp.package %}
|
||||||
Package: {{comp.package}}<br>
|
Package: {{comp.package}}<br>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
Reference in New Issue
Block a user