Fixup import of component_views.py

This commit is contained in:
Mario Hüttel 2024-11-18 21:08:55 +01:00
parent 173f0e3c91
commit b3f8041f08

View File

@ -1,24 +1,16 @@
from django.shortcuts import render, redirect import uuid
from django.shortcuts import redirect
from django.urls import reverse from django.urls import reverse
from django.contrib.auth import logout, login
from django.contrib.auth.forms import AuthenticationForm as AuthForm
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth import update_session_auth_hash
import django.forms as forms
from django.views.generic import TemplateView, DetailView from django.views.generic import TemplateView, DetailView
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from ..models import Storage, Stock, Component, Distributor, Manufacturer, Package, ComponentParameter, DistributorNum
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.core.exceptions import ValidationError from django.db.models import Q
from django.forms import formset_factory
from django.db import IntegrityError from django.db import IntegrityError
from django.db.models import ProtectedError from django.db.models import ProtectedError
from ..models import Stock, Component, ComponentParameter, DistributorNum
from ..forms import * from ..forms import *
from .component_import import import_components_from_csv from .component_import import import_components_from_csv
from django.db.models import Q
from django.db.models.functions import Lower
from django.forms import formset_factory
from django.http import HttpResponse
import uuid
from .generic_views import BaseTemplateMixin from .generic_views import BaseTemplateMixin
@ -76,7 +68,8 @@ class ComponentView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
context['advanced_search_form'] = advanced_search context['advanced_search_form'] = advanced_search
context['advanced_search_param_formset'] = parameter_formset context['advanced_search_param_formset'] = parameter_formset
if advanced_search.is_valid(): if advanced_search.is_valid():
paginator_queryset = self.get_component_queryset_from_advanced_search(advanced_search.cleaned_data) paginator_queryset = self.get_component_queryset_from_advanced_search(
advanced_search.cleaned_data)
else: else:
paginator_queryset = Component.objects.all() paginator_queryset = Component.objects.all()
@ -162,7 +155,6 @@ class ComponentView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
else: else:
return super().post(request, *args, **kwargs) return super().post(request, *args, **kwargs)
class ComponentDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView): class ComponentDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
template_name = 'parts/components-detail.html' template_name = 'parts/components-detail.html'
model = Component model = Component
@ -178,8 +170,10 @@ class ComponentDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
context['comp_form'] = ComponentForm(instance=self.object) context['comp_form'] = ComponentForm(instance=self.object)
context['new_distri_num_form'] = DistributorNumberCreateForm() context['new_distri_num_form'] = DistributorNumberCreateForm()
context['new_param_form'] = ComponentParameterCreateForm() context['new_param_form'] = ComponentParameterCreateForm()
context['distri_nums'] = DistributorNum.objects.filter(component=self.object).order_by('distributor__name') context['distri_nums'] = DistributorNum.objects.filter(component=self.object).order_by(
context['parameters'] = ComponentParameter.objects.filter(component=self.object).order_by('parameter_type__parameter_name') 'distributor__name')
context['parameters'] = ComponentParameter.objects.filter(component=self.object).order_by(
'parameter_type__parameter_name')
return context return context