diff options
author | Filipp Lepalaan <filipp@mac.com> | 2015-11-16 11:49:17 +0200 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2015-11-16 11:49:17 +0200 |
commit | 767debc0bd38361808c0ca29c89e6cf950eeb7f2 (patch) | |
tree | c5bf50d8ac1f674eb614a8c1372486f48a8b0ddc | |
parent | bda127bd38b496c64abeec6d5ba7c0a09eddcb3f (diff) | |
download | Servo-767debc0bd38361808c0ca29c89e6cf950eeb7f2.tar.gz Servo-767debc0bd38361808c0ca29c89e6cf950eeb7f2.tar.bz2 Servo-767debc0bd38361808c0ca29c89e6cf950eeb7f2.zip |
Cleanup
-rw-r--r-- | servo/models/account.py | 4 | ||||
-rw-r--r-- | servo/models/note.py | 4 | ||||
-rw-r--r-- | servo/views/note.py | 24 | ||||
-rw-r--r-- | servo/views/purchases.py | 12 | ||||
-rw-r--r-- | servo/views/search.py | 3 | ||||
-rw-r--r-- | servo/views/shipments.py | 51 |
6 files changed, 26 insertions, 72 deletions
diff --git a/servo/models/account.py b/servo/models/account.py index 46eb674..13718c2 100644 --- a/servo/models/account.py +++ b/servo/models/account.py @@ -35,7 +35,6 @@ class TechieManager(UserManager): class User(AbstractUser): - customer = TreeForeignKey( Customer, null=True, @@ -58,7 +57,7 @@ class User(AbstractUser): related_name='+', on_delete=models.PROTECT, verbose_name=_('Current Location'), - help_text=_(u'Orders you create will be registered to this location.') + help_text=_('Orders you create will be registered to this location.') ) queues = models.ManyToManyField(Queue, blank=True, verbose_name=_('queues')) LOCALES = ( @@ -277,7 +276,6 @@ class User(AbstractUser): class UserGroup(Group): - def members_as_list(self): pass diff --git a/servo/models/note.py b/servo/models/note.py index ad92f7e..f5b8c15 100644 --- a/servo/models/note.py +++ b/servo/models/note.py @@ -349,9 +349,7 @@ class Note(MPTTModel): return r.exclude(status='FAILED').exists() def send_mail(self, user): - """ - Sends this note as an email - """ + """Sends this note as an email""" mailto = self.mailto() # Only send the same note once diff --git a/servo/views/note.py b/servo/views/note.py index 2ea6a14..58b7382 100644 --- a/servo/views/note.py +++ b/servo/views/note.py @@ -13,12 +13,12 @@ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.cache import cache_page from django.shortcuts import render, redirect, get_object_or_404 from django.contrib.auth.decorators import permission_required -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from reportlab.lib.units import mm from reportlab.graphics.shapes import Drawing from reportlab.graphics.barcode import createBarcodeDrawing +from servo.lib.utils import paginate from servo.models import Order, Template, Tag, Customer, Note, Attachment, Escalation from servo.forms import NoteForm, NoteSearchForm, EscalationForm @@ -70,14 +70,7 @@ def prep_list_view(request, kind): all_notes = Note.objects.all().exclude(escalation=None) page = request.GET.get("page") - paginator = Paginator(all_notes, 20) - - try: - notes = paginator.page(page) - except PageNotAnInteger: - notes = paginator.page(1) - except EmptyPage: - notes = paginator.page(paginator.num_pages) + notes = paginate(all_notes, page, 20) data['kind'] = kind data['notes'] = notes @@ -352,17 +345,10 @@ def find(request): results = results.order_by('-created_at') - paginator = Paginator(results, 10) - page = request.GET.get("page") - - try: - notes = paginator.page(page) - except PageNotAnInteger: - notes = paginator.page(1) - except EmptyPage: - notes = paginator.page(paginator.num_pages) - title = _('Message search') + notes = paginate(requlets, page, 10) + page = request.GET.get("page") + return render(request, "notes/find.html", locals()) diff --git a/servo/views/purchases.py b/servo/views/purchases.py index 8d382e9..5d1cacd 100644 --- a/servo/views/purchases.py +++ b/servo/views/purchases.py @@ -9,10 +9,9 @@ from django.utils.translation import ugettext as _ from django.contrib.auth.decorators import permission_required from django.shortcuts import render, redirect, get_object_or_404 -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger - from django.contrib import messages +from servo.lib.utils import paginate from servo.models.order import ServiceOrderItem from servo.models import (Order, Product, GsxAccount, PurchaseOrder, PurchaseOrderItem,) @@ -58,14 +57,7 @@ def list_pos(request): all_orders = all_orders.filter(created_by=created_by) page = request.GET.get("page") - paginator = Paginator(all_orders, 50) - - try: - orders = paginator.page(page) - except PageNotAnInteger: - orders = paginator.page(1) - except EmptyPage: - orders = paginator.page(paginator.num_pages) + orders = paginate(all_orders, page, 50) data['orders'] = orders data['form'] = form diff --git a/servo/views/search.py b/servo/views/search.py index 30e1496..219318b 100644 --- a/servo/views/search.py +++ b/servo/views/search.py @@ -33,9 +33,6 @@ def search_gsx(request, what, param, query): except gsxws.GsxError as message: return render(request, "devices/search_gsx_error.html", locals()) - if request.is_ajax(): - return get_gsx_search_results(request, what, param, query) - return render(request, "devices/search_gsx.html", locals()) diff --git a/servo/views/shipments.py b/servo/views/shipments.py index 18c44ba..5cfec52 100644 --- a/servo/views/shipments.py +++ b/servo/views/shipments.py @@ -6,11 +6,11 @@ from decimal import * from django.utils import timezone from django.contrib import messages from django.http import HttpResponse -from django.shortcuts import render, redirect from django.utils.translation import ugettext as _ from django.forms.models import inlineformset_factory -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.shortcuts import render, redirect, get_object_or_404 +from servo.lib.utils import paginate from servo.models import GsxAccount, ServicePart, Shipment, PurchaseOrderItem from servo.forms.product import PurchaseOrderItemForm, IncomingSearchForm from servo.forms.returns import * @@ -19,7 +19,7 @@ from servo.forms.returns import * def prep_counts(): incoming = PurchaseOrderItem.objects.filter(received_at=None) incoming = incoming.exclude(purchase_order__submitted_at=None).count() - pending_return = '' + returns = Shipment.objects.exclude(dispatched_at=None).count() return locals() @@ -78,21 +78,11 @@ def prep_list_view(request): inventory = PurchaseOrderItem.objects.filter(purchase_order__sales_order__code=service_order) page = request.GET.get("page") - data['count'] = inventory.count() inventory = inventory.order_by('-id') - - paginator = Paginator(inventory, 200) + data['count'] = inventory.count() + data['inventory'] = paginate(inventory, page, 200) data['title'] = _(u"%d incoming products") % data['count'] - try: - inventory = paginator.page(page) - except PageNotAnInteger: - inventory = paginator.page(1) - except EmptyPage: - inventory = paginator.page(paginator.num_pages) - - data['inventory'] = inventory - return data @@ -124,7 +114,7 @@ def view_incoming(request, pk): Shows an incoming part """ next = False - item = PurchaseOrderItem.objects.get(pk=pk) + item = get_object_or_404(PurchaseOrderItem, pk=pk) data = prep_list_view(request) @@ -189,28 +179,21 @@ def list_bulk_returns(request): returns = Shipment.objects.exclude(dispatched_at=None).annotate(num_parts=Count('servicepart')) page = request.GET.get("page") - paginator = Paginator(returns, 50) - - try: - returns = paginator.page(page) - except PageNotAnInteger: - returns = paginator.page(1) - except EmptyPage: - returns = paginator.page(paginator.num_pages) - + returns = paginate(returns, page, 50) counts = prep_counts() + return render(request, "shipments/list_bulk_returns.html", locals()) def view_packing_list(request, pk): - shipment = Shipment.objects.get(pk=pk) + shipment = get_object_or_404(Shipment, pk=pk) pdf = shipment.packing_list.read() return HttpResponse(pdf, content_type="application/pdf") def view_bulk_return(request, pk): title = _("View bulk return") - shipment = Shipment.objects.get(pk=pk) + shipment = get_object_or_404(Shipment, pk=pk) return render(request, "shipments/view_bulk_return.html", locals()) @@ -275,13 +258,13 @@ def remove_from_return(request, pk, part_pk): """ Removes a part from a bulk return """ - shipment = Shipment.objects.get(pk=pk) - part = ServicePart.objects.get(pk=part_pk) + shipment = get_object_or_404(Shipment, pk=pk) + part = get_object_or_404(ServicePart, pk=part_pk) try: shipment.toggle_part(part) messages.success(request, _(u"Part %s removed from bulk return") % part.part_number) - except Exception, e: + except Exception as e: messages.error(request, e) return redirect(edit_bulk_return) @@ -294,8 +277,8 @@ def add_to_return(request, pk, part=None): data = {'action': request.path} if pk and part: - shipment = Shipment.objects.get(pk=pk) - part = ServicePart.objects.get(pk=part) + shipment = get_object_or_404(Shipment, pk=pk) + part = get_object_or_404(ServicePart, pk=part) shipment.servicepart_set.add(part) messages.success(request, _(u"Part %s added to return") % part.part_number) @@ -315,9 +298,9 @@ def update_part(request, part, return_type): """ Update part status to GSX """ + part = get_object_or_404(ServicePart, pk=part) return_type = int(return_type) - part = ServicePart.objects.get(pk=part) - + msg = "" form = "" title = "" |