Compare commits
5 Commits
b3f8041f08
...
5ce7d99db2
Author | SHA1 | Date | |
---|---|---|---|
5ce7d99db2 | |||
5109f8d094 | |||
6d0ec7e448 | |||
8422ff0eeb | |||
1f3ed7f8ed |
@ -1,20 +1,12 @@
|
|||||||
from django.shortcuts import render, redirect
|
import uuid
|
||||||
from django.urls import reverse
|
from django.shortcuts import redirect
|
||||||
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 ..models import Distributor
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
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.functions import Lower
|
|
||||||
import uuid
|
|
||||||
from .generic_views import BaseTemplateMixin
|
from .generic_views import BaseTemplateMixin
|
||||||
|
|
||||||
class DistributorView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
class DistributorView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
||||||
@ -28,7 +20,7 @@ class DistributorView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
|
|
||||||
if not search:
|
if not search:
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
search_fragments = search.strip().split()
|
search_fragments = search.strip().split()
|
||||||
|
|
||||||
for search in search_fragments:
|
for search in search_fragments:
|
||||||
@ -39,10 +31,10 @@ class DistributorView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
page_num = self.request.GET.get('page', default=1)
|
page_num = self.request.GET.get('page', default=1)
|
||||||
search_string = self.request.GET.get('search', default=None)
|
search_string = self.request.GET.get('search', default=None)
|
||||||
|
|
||||||
queryset = self.search_distributors(search_string)
|
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
|
context['search_string'] = search_string
|
||||||
@ -50,7 +42,7 @@ class DistributorView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
context['new_distri_form'] = DistributorForm()
|
context['new_distri_form'] = DistributorForm()
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def handle_add_new_distributor(self, request):
|
def handle_add_new_distributor(self, request):
|
||||||
|
|
||||||
form = DistributorForm(data=request.POST, files=request.FILES)
|
form = DistributorForm(data=request.POST, files=request.FILES)
|
||||||
@ -77,19 +69,19 @@ class DistributorDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
pk_url_kwarg = 'uuid'
|
pk_url_kwarg = 'uuid'
|
||||||
base_title = ''
|
base_title = ''
|
||||||
navbar_selected = 'Distributors'
|
navbar_selected = 'Distributors'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
self.base_title = 'Distributor / '+self.object.name
|
self.base_title = 'Distributor / '+self.object.name
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['distributor'] = self.object
|
context['distributor'] = self.object
|
||||||
context['edit_form'] = DistributorForm(instance=self.object)
|
context['edit_form'] = DistributorForm(instance=self.object)
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def handle_delete_distributor(self, request):
|
def handle_delete_distributor(self, request):
|
||||||
delete_error = None
|
delete_error = None
|
||||||
protected_objects = None
|
protected_objects = None
|
||||||
|
|
||||||
# Try to delete this instance
|
# Try to delete this instance
|
||||||
try:
|
try:
|
||||||
self.object.delete()
|
self.object.delete()
|
||||||
@ -98,7 +90,7 @@ class DistributorDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
protected_objects = pe.protected_objects
|
protected_objects = pe.protected_objects
|
||||||
except:
|
except:
|
||||||
delete_error = 'Cannot delete this distributor. Unknown error'
|
delete_error = 'Cannot delete this distributor. Unknown error'
|
||||||
|
|
||||||
if delete_error:
|
if delete_error:
|
||||||
context = self.get_context_data()
|
context = self.get_context_data()
|
||||||
context['delete_error'] = delete_error
|
context['delete_error'] = delete_error
|
||||||
@ -125,5 +117,5 @@ class DistributorDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
return self.handle_delete_distributor(request)
|
return self.handle_delete_distributor(request)
|
||||||
elif 'submit-distri-edit' in request.POST:
|
elif 'submit-distri-edit' in request.POST:
|
||||||
return self.edit_distributor(request)
|
return self.edit_distributor(request)
|
||||||
|
|
||||||
return super().post(request, *args, **kwargs)
|
return super().post(request, *args, **kwargs)
|
||||||
|
@ -1,20 +1,11 @@
|
|||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import 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.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 ..models import Manufacturer
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
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.functions import Lower
|
|
||||||
import uuid
|
|
||||||
from .generic_views import BaseTemplateMixin
|
from .generic_views import BaseTemplateMixin
|
||||||
|
|
||||||
class ManufacturersView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
class ManufacturersView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
||||||
@ -28,7 +19,7 @@ class ManufacturersView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
|
|
||||||
if not search:
|
if not search:
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
search_fragements = search.strip().split()
|
search_fragements = search.strip().split()
|
||||||
|
|
||||||
for search in search_fragements:
|
for search in search_fragements:
|
||||||
@ -40,10 +31,10 @@ class ManufacturersView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
page_num = self.request.GET.get('page', default=1)
|
page_num = self.request.GET.get('page', default=1)
|
||||||
search_string = self.request.GET.get('search', default=None)
|
search_string = self.request.GET.get('search', default=None)
|
||||||
|
|
||||||
queryset = self.search_manufacturers(search_string)
|
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
|
context['search_string'] = search_string
|
||||||
@ -51,7 +42,7 @@ class ManufacturersView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
context['new_manufacturer_form'] = ManufacturerForm()
|
context['new_manufacturer_form'] = ManufacturerForm()
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def handle_add_new_manufacturer(self, request):
|
def handle_add_new_manufacturer(self, request):
|
||||||
|
|
||||||
form = ManufacturerForm(data=request.POST, files=request.FILES)
|
form = ManufacturerForm(data=request.POST, files=request.FILES)
|
||||||
@ -78,19 +69,19 @@ class ManufacturerDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
pk_url_kwarg = 'uuid'
|
pk_url_kwarg = 'uuid'
|
||||||
base_title = ''
|
base_title = ''
|
||||||
navbar_selected = 'Manufacturers'
|
navbar_selected = 'Manufacturers'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
self.base_title = 'Manufacturer / '+self.object.name
|
self.base_title = 'Manufacturer / '+self.object.name
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['manufacturer'] = self.object
|
context['manufacturer'] = self.object
|
||||||
context['edit_form'] = ManufacturerForm(instance=self.object)
|
context['edit_form'] = ManufacturerForm(instance=self.object)
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def handle_delete_manufacturer(self, request):
|
def handle_delete_manufacturer(self, request):
|
||||||
delete_error = None
|
delete_error = None
|
||||||
protected_objects = None
|
protected_objects = None
|
||||||
|
|
||||||
# Try to delete this instance
|
# Try to delete this instance
|
||||||
try:
|
try:
|
||||||
self.object.delete()
|
self.object.delete()
|
||||||
@ -99,7 +90,7 @@ class ManufacturerDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
protected_objects = pe.protected_objects
|
protected_objects = pe.protected_objects
|
||||||
except:
|
except:
|
||||||
delete_error = 'Cannot delete this distributor. Unknown error'
|
delete_error = 'Cannot delete this distributor. Unknown error'
|
||||||
|
|
||||||
if delete_error:
|
if delete_error:
|
||||||
context = self.get_context_data()
|
context = self.get_context_data()
|
||||||
context['delete_error'] = delete_error
|
context['delete_error'] = delete_error
|
||||||
@ -126,5 +117,5 @@ class ManufacturerDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
return self.handle_delete_manufacturer(request)
|
return self.handle_delete_manufacturer(request)
|
||||||
elif 'submit-manufacturer-edit' in request.POST:
|
elif 'submit-manufacturer-edit' in request.POST:
|
||||||
return self.edit_manufacturer(request)
|
return self.edit_manufacturer(request)
|
||||||
|
|
||||||
return super().post(request, *args, **kwargs)
|
return super().post(request, *args, **kwargs)
|
@ -1,20 +1,11 @@
|
|||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import 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.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 import IntegrityError
|
|
||||||
from django.db.models import ProtectedError
|
from django.db.models import ProtectedError
|
||||||
from ..forms import *
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.db.models.functions import Lower
|
from ..forms import *
|
||||||
import uuid
|
from ..models import Package
|
||||||
from .generic_views import BaseTemplateMixin
|
from .generic_views import BaseTemplateMixin
|
||||||
|
|
||||||
class PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
class PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
||||||
@ -28,7 +19,7 @@ class PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
|
|
||||||
if not search:
|
if not search:
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
search_fragments = search.strip().split()
|
search_fragments = search.strip().split()
|
||||||
for search in search_fragments:
|
for search in search_fragments:
|
||||||
if search.lower() == 'smd':
|
if search.lower() == 'smd':
|
||||||
@ -47,10 +38,10 @@ class PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
page_num = self.request.GET.get('page', default=1)
|
page_num = self.request.GET.get('page', default=1)
|
||||||
search_string = self.request.GET.get('search', default=None)
|
search_string = self.request.GET.get('search', default=None)
|
||||||
|
|
||||||
package_queryset = self.search_packages(search_string)
|
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
|
context['search_string'] = search_string
|
||||||
@ -58,7 +49,7 @@ class PackageView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
|||||||
context['new_pkg_form'] = PackageForm()
|
context['new_pkg_form'] = PackageForm()
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def handle_add_new_package(self, request):
|
def handle_add_new_package(self, request):
|
||||||
|
|
||||||
form = PackageForm(data=request.POST, files=request.FILES)
|
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 self.handle_add_new_package(request)
|
||||||
|
|
||||||
return super().post(request, *args, **kwargs)
|
return super().post(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class PackageDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
class PackageDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
||||||
template_name = 'parts/packages-detail.html'
|
template_name = 'parts/packages-detail.html'
|
||||||
@ -85,19 +76,19 @@ class PackageDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
pk_url_kwarg = 'uuid'
|
pk_url_kwarg = 'uuid'
|
||||||
base_title = ''
|
base_title = ''
|
||||||
navbar_selected = 'Packages'
|
navbar_selected = 'Packages'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
self.base_title = 'Package / '+self.object.name
|
self.base_title = 'Package / '+self.object.name
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['package'] = self.object
|
context['package'] = self.object
|
||||||
context['edit_form'] = PackageForm(instance=self.object)
|
context['edit_form'] = PackageForm(instance=self.object)
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def handle_delete_package(self, request):
|
def handle_delete_package(self, request):
|
||||||
delete_error = None
|
delete_error = None
|
||||||
protected_objects = None
|
protected_objects = None
|
||||||
|
|
||||||
# Try to delete this instance
|
# Try to delete this instance
|
||||||
try:
|
try:
|
||||||
self.object.delete()
|
self.object.delete()
|
||||||
@ -106,7 +97,7 @@ class PackageDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
protected_objects = pe.protected_objects
|
protected_objects = pe.protected_objects
|
||||||
except:
|
except:
|
||||||
delete_error = 'Cannot delete this package. Unknown error'
|
delete_error = 'Cannot delete this package. Unknown error'
|
||||||
|
|
||||||
if delete_error:
|
if delete_error:
|
||||||
context = self.get_context_data()
|
context = self.get_context_data()
|
||||||
context['delete_error'] = delete_error
|
context['delete_error'] = delete_error
|
||||||
@ -133,5 +124,5 @@ class PackageDetailView(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
return self.handle_delete_package(request)
|
return self.handle_delete_package(request)
|
||||||
elif 'submit-pkg-edit' in request.POST:
|
elif 'submit-pkg-edit' in request.POST:
|
||||||
return self.edit_package(request)
|
return self.edit_package(request)
|
||||||
|
|
||||||
return super().post(request, *args, **kwargs)
|
return super().post(request, *args, **kwargs)
|
@ -1,24 +1,14 @@
|
|||||||
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.core.exceptions import ValidationError
|
||||||
from django.db import IntegrityError
|
|
||||||
from django.db.models import ProtectedError
|
|
||||||
from ..forms import *
|
|
||||||
from .component_import import import_components_from_csv
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.db.models.functions import Lower
|
from django.db.models.functions import Lower
|
||||||
from django.forms import formset_factory
|
from ..models import Storage, Stock
|
||||||
from django.http import HttpResponse
|
from ..forms import *
|
||||||
import uuid
|
|
||||||
from .generic_views import BaseTemplateMixin
|
from .generic_views import BaseTemplateMixin
|
||||||
|
|
||||||
class StockView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
class StockView(LoginRequiredMixin, BaseTemplateMixin, TemplateView):
|
||||||
@ -85,7 +75,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
|
|
||||||
def search_stock_queryset(self, search):
|
def search_stock_queryset(self, search):
|
||||||
stocks_in_storage = Stock.objects.filter(storage=self.object).order_by(Lower('component__name'))
|
stocks_in_storage = Stock.objects.filter(storage=self.object).order_by(Lower('component__name'))
|
||||||
|
|
||||||
if search is None or search == '':
|
if search is None or search == '':
|
||||||
return stocks_in_storage
|
return stocks_in_storage
|
||||||
|
|
||||||
@ -106,7 +96,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
stocks_in_storage = stocks_in_storage.filter(Q(component__name__icontains = search) |
|
stocks_in_storage = stocks_in_storage.filter(Q(component__name__icontains = search) |
|
||||||
Q(component__package__name__icontains = search) |
|
Q(component__package__name__icontains = search) |
|
||||||
Q(component__manufacturer__name__icontains = search))
|
Q(component__manufacturer__name__icontains = search))
|
||||||
|
|
||||||
return stocks_in_storage
|
return stocks_in_storage
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
@ -119,7 +109,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
stock_search_input = self.request.GET.get('search')
|
stock_search_input = self.request.GET.get('search')
|
||||||
|
|
||||||
componente_stock_page = self.request.GET.get('stock_page', default=1)
|
componente_stock_page = self.request.GET.get('stock_page', default=1)
|
||||||
|
|
||||||
stock_paginator = Paginator(self.search_stock_queryset(stock_search_input), self.default_pagination_size)
|
stock_paginator = Paginator(self.search_stock_queryset(stock_search_input), self.default_pagination_size)
|
||||||
|
|
||||||
context['storages'] = storage_paginator.get_page(storage_page)
|
context['storages'] = storage_paginator.get_page(storage_page)
|
||||||
@ -160,7 +150,6 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
def handle_change_storage_post(self, request, **kwargs):
|
def handle_change_storage_post(self, request, **kwargs):
|
||||||
f = ChangeStorageForm(data=request.POST)
|
f = ChangeStorageForm(data=request.POST)
|
||||||
if f.is_valid():
|
if f.is_valid():
|
||||||
sub_name = f.cleaned_data['storage_name']
|
|
||||||
try:
|
try:
|
||||||
self.object.name = f.cleaned_data['storage_name']
|
self.object.name = f.cleaned_data['storage_name']
|
||||||
self.object.verbose_name = f.cleaned_data.get('verbose_name')
|
self.object.verbose_name = f.cleaned_data.get('verbose_name')
|
||||||
@ -175,20 +164,20 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
|
|
||||||
def handle_del_storage_post(self, request, **kwargs):
|
def handle_del_storage_post(self, request, **kwargs):
|
||||||
parent = self.object.parent_storage
|
parent = self.object.parent_storage
|
||||||
try:
|
try:
|
||||||
self.object.delete()
|
self.object.delete()
|
||||||
except:
|
except:
|
||||||
context = self.get_context_data(**kwargs)
|
context = self.get_context_data(**kwargs)
|
||||||
context['delete_storage_errors'] = ['Error deleting Storage '+str(self.object)]
|
context['delete_storage_errors'] = ['Error deleting Storage '+str(self.object)]
|
||||||
return self.render_to_response(context)
|
return self.render_to_response(context)
|
||||||
|
|
||||||
if parent is None:
|
if parent is None:
|
||||||
return redirect('parts-stocks')
|
return redirect('parts-stocks')
|
||||||
else:
|
else:
|
||||||
return redirect(reverse('parts-stocks-detail', kwargs={'uuid':parent.id}))
|
return redirect(reverse('parts-stocks-detail', kwargs={'uuid':parent.id}))
|
||||||
|
|
||||||
def handle_del_stock_post(self, request, **kwargs):
|
def handle_del_stock_post(self, request, **kwargs):
|
||||||
del_error = None
|
del_error = None # TODO: Check error handling. This is clearly not working as intended :P
|
||||||
if 'stock_uuid' in request.POST:
|
if 'stock_uuid' in request.POST:
|
||||||
f = DeleteStockForm(data=request.POST)
|
f = DeleteStockForm(data=request.POST)
|
||||||
if f.is_valid():
|
if f.is_valid():
|
||||||
@ -199,16 +188,15 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
if s.storage == self.object:
|
if s.storage == self.object:
|
||||||
s.delete()
|
s.delete()
|
||||||
else:
|
else:
|
||||||
del_error = 'Cannot delete stock from another storage.'
|
del_error = 'Cannot delete stock from another storage.'
|
||||||
except:
|
except:
|
||||||
del_error = 'Could not find requested stock in this storage.'
|
del_error = 'Could not find requested stock in this storage.'
|
||||||
|
|
||||||
context = self.get_context_data(**kwargs)
|
context = self.get_context_data(**kwargs)
|
||||||
return self.render_to_response(context)
|
return self.render_to_response(context)
|
||||||
|
|
||||||
def handle_update_watermark(self, request, **kwargs):
|
def handle_update_watermark(self, request, **kwargs):
|
||||||
edit_form = EditWatermarkForm(data=request.POST)
|
edit_form = EditWatermarkForm(data=request.POST)
|
||||||
update_watermark_error = None
|
|
||||||
if edit_form.is_valid():
|
if edit_form.is_valid():
|
||||||
edit_form.save()
|
edit_form.save()
|
||||||
else:
|
else:
|
||||||
@ -216,7 +204,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
|
|
||||||
context = self.get_context_data(**kwargs)
|
context = self.get_context_data(**kwargs)
|
||||||
return self.render_to_response(context)
|
return self.render_to_response(context)
|
||||||
|
|
||||||
def handle_amount_change_post(self, request, increase, **kwargs):
|
def handle_amount_change_post(self, request, increase, **kwargs):
|
||||||
edit_form = EditStockAmountForm(data=request.POST)
|
edit_form = EditStockAmountForm(data=request.POST)
|
||||||
if edit_form.is_valid():
|
if edit_form.is_valid():
|
||||||
@ -259,7 +247,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
|||||||
elif 'submit-amount-reduce' in request.POST:
|
elif 'submit-amount-reduce' in request.POST:
|
||||||
return self.handle_amount_change_post(request, False, **kwargs)
|
return self.handle_amount_change_post(request, False, **kwargs)
|
||||||
elif 'submit-amount-increase' in request.POST:
|
elif 'submit-amount-increase' in request.POST:
|
||||||
return self.handle_amount_change_post(request, True, **kwargs)
|
return self.handle_amount_change_post(request, True, **kwargs)
|
||||||
elif 'submit-add-stock' in request.POST:
|
elif 'submit-add-stock' in request.POST:
|
||||||
return self.handle_add_stock_post(request, **kwargs)
|
return self.handle_add_stock_post(request, **kwargs)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user