From 8422ff0eebf82f63ba548d1f8d9abd14a6b98048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 18 Nov 2024 21:17:31 +0100 Subject: [PATCH] Fixup imports in manufacturer views --- .../parts/views/manufacturer_views.py | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/shimatta_kenkyusho/parts/views/manufacturer_views.py b/shimatta_kenkyusho/parts/views/manufacturer_views.py index afa001d..d647d77 100644 --- a/shimatta_kenkyusho/parts/views/manufacturer_views.py +++ b/shimatta_kenkyusho/parts/views/manufacturer_views.py @@ -1,20 +1,11 @@ -from django.shortcuts import render, redirect -from django.urls import reverse -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.shortcuts import redirect from django.views.generic import TemplateView, DetailView from django.contrib.auth.mixins import LoginRequiredMixin -from ..models import Storage, Stock, Component, Distributor, Manufacturer, Package, ComponentParameter, DistributorNum +from ..models import Manufacturer from django.core.paginator import Paginator -from django.core.exceptions import ValidationError -from django.db import IntegrityError from django.db.models import ProtectedError from ..forms import * from django.db.models import Q -from django.db.models.functions import Lower -import uuid from .generic_views import BaseTemplateMixin class ManufacturersView(LoginRequiredMixin, BaseTemplateMixin, TemplateView): @@ -28,7 +19,7 @@ class ManufacturersView(LoginRequiredMixin, BaseTemplateMixin, TemplateView): if not search: return qs - + search_fragements = search.strip().split() for search in search_fragements: @@ -40,10 +31,10 @@ class ManufacturersView(LoginRequiredMixin, BaseTemplateMixin, TemplateView): context = super().get_context_data(**kwargs) page_num = self.request.GET.get('page', default=1) search_string = self.request.GET.get('search', default=None) - + queryset = self.search_manufacturers(search_string) - paginator = Paginator(queryset, self.default_page_size) + paginator = Paginator(queryset, self.default_page_size) context['search_string'] = search_string @@ -51,7 +42,7 @@ class ManufacturersView(LoginRequiredMixin, BaseTemplateMixin, TemplateView): context['new_manufacturer_form'] = ManufacturerForm() return context - + def handle_add_new_manufacturer(self, request): form = ManufacturerForm(data=request.POST, files=request.FILES) @@ -78,19 +69,19 @@ class ManufacturerDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView): pk_url_kwarg = 'uuid' base_title = '' navbar_selected = 'Manufacturers' - + def get_context_data(self, **kwargs): self.base_title = 'Manufacturer / '+self.object.name context = super().get_context_data(**kwargs) context['manufacturer'] = self.object context['edit_form'] = ManufacturerForm(instance=self.object) - + return context def handle_delete_manufacturer(self, request): delete_error = None protected_objects = None - + # Try to delete this instance try: self.object.delete() @@ -99,7 +90,7 @@ class ManufacturerDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView): protected_objects = pe.protected_objects except: delete_error = 'Cannot delete this distributor. Unknown error' - + if delete_error: context = self.get_context_data() context['delete_error'] = delete_error @@ -126,5 +117,5 @@ class ManufacturerDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView): return self.handle_delete_manufacturer(request) elif 'submit-manufacturer-edit' in request.POST: return self.edit_manufacturer(request) - + return super().post(request, *args, **kwargs) \ No newline at end of file