mhu/4-port-to-django-5.1 Port to recent Django version #18
@ -1,20 +1,12 @@
|
||||
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
|
||||
import uuid
|
||||
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 Distributor
|
||||
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 DistributorView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
||||
@ -28,7 +20,7 @@ class DistributorView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
||||
|
||||
if not search:
|
||||
return qs
|
||||
|
||||
|
||||
search_fragments = search.strip().split()
|
||||
|
||||
for search in search_fragments:
|
||||
@ -39,10 +31,10 @@ class DistributorView(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_distributors(search_string)
|
||||
|
||||
paginator = Paginator(queryset, self.default_page_size)
|
||||
paginator = Paginator(queryset, self.default_page_size)
|
||||
|
||||
|
||||
context['search_string'] = search_string
|
||||
@ -50,7 +42,7 @@ class DistributorView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
||||
context['new_distri_form'] = DistributorForm()
|
||||
|
||||
return context
|
||||
|
||||
|
||||
def handle_add_new_distributor(self, request):
|
||||
|
||||
form = DistributorForm(data=request.POST, files=request.FILES)
|
||||
@ -77,19 +69,19 @@ class DistributorDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
||||
pk_url_kwarg = 'uuid'
|
||||
base_title = ''
|
||||
navbar_selected = 'Distributors'
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
self.base_title = 'Distributor / '+self.object.name
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['distributor'] = self.object
|
||||
context['edit_form'] = DistributorForm(instance=self.object)
|
||||
|
||||
|
||||
return context
|
||||
|
||||
def handle_delete_distributor(self, request):
|
||||
delete_error = None
|
||||
protected_objects = None
|
||||
|
||||
|
||||
# Try to delete this instance
|
||||
try:
|
||||
self.object.delete()
|
||||
@ -98,7 +90,7 @@ class DistributorDetailView(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
|
||||
@ -125,5 +117,5 @@ class DistributorDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
||||
return self.handle_delete_distributor(request)
|
||||
elif 'submit-distri-edit' in request.POST:
|
||||
return self.edit_distributor(request)
|
||||
|
||||
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user