mhu/4-port-to-django-5.1 Port to recent Django version #18

Merged
sst merged 13 commits from mhu/4-port-to-django-5.1 into develop 2024-11-19 00:03:22 +01:00
Showing only changes of commit 6d0ec7e448 - Show all commits

View File

@ -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 Package
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 PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
@ -28,7 +19,7 @@ class PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
if not search:
return qs
search_fragments = search.strip().split()
for search in search_fragments:
if search.lower() == 'smd':
@ -47,10 +38,10 @@ class PackageView(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)
package_queryset = self.search_packages(search_string)
paginator = Paginator(package_queryset, self.default_page_size)
paginator = Paginator(package_queryset, self.default_page_size)
context['search_string'] = search_string
@ -58,7 +49,7 @@ class PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
context['new_pkg_form'] = PackageForm()
return context
def handle_add_new_package(self, request):
form = PackageForm(data=request.POST, files=request.FILES)
@ -77,7 +68,7 @@ class PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
return self.handle_add_new_package(request)
return super().post(request, *args, **kwargs)
class PackageDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
template_name = 'parts/packages-detail.html'
@ -85,19 +76,19 @@ class PackageDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
pk_url_kwarg = 'uuid'
base_title = ''
navbar_selected = 'Packages'
def get_context_data(self, **kwargs):
self.base_title = 'Package / '+self.object.name
context = super().get_context_data(**kwargs)
context['package'] = self.object
context['edit_form'] = PackageForm(instance=self.object)
return context
def handle_delete_package(self, request):
delete_error = None
protected_objects = None
# Try to delete this instance
try:
self.object.delete()
@ -106,7 +97,7 @@ class PackageDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
protected_objects = pe.protected_objects
except:
delete_error = 'Cannot delete this package. Unknown error'
if delete_error:
context = self.get_context_data()
context['delete_error'] = delete_error
@ -133,5 +124,5 @@ class PackageDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
return self.handle_delete_package(request)
elif 'submit-pkg-edit' in request.POST:
return self.edit_package(request)
return super().post(request, *args, **kwargs)