Commits

Roman Ruban  committed 2f3b3f7

added paging to inventory page

  • Participants
  • Parent commits 427864a

Comments (0)

Files changed (3)

File satchmo/apps/product/forms.py

 from django.core import serializers, urlresolvers
 from django.core.management.base import CommandError
 from django.core.management.color import no_style
+from django.core.paginator import Paginator, InvalidPage, EmptyPage
 from django.db import transaction
 from django.http import HttpResponse
 from django.utils.translation import ugettext as _
 
     def __init__(self, *args, **kwargs):
         products = kwargs.pop('products', None)
+        page = kwargs.pop('page', 1)
 
         super(InventoryForm, self).__init__(*args, **kwargs)
 
         if not products:
             products = Product.objects.by_site().order_by('slug')
 
+            paginator = Paginator(products, 25)
+            try:
+                products = paginator.page(page)
+            except (EmptyPage, InvalidPage):
+                products = paginator.page(paginator.num_pages)
+
+            self.pages = products
+            products = products.object_list
+
         for product in products:
             subtypes = product.get_subtypes()
             qtyclasses = ('text', 'qty') + subtypes

File satchmo/apps/product/listeners.py

             | Q(short_description__icontains=keyword)
             | Q(description__icontains=keyword)
             | Q(meta__icontains=keyword)
-            | Q(sku__iexact=keyword) )
+            | Q(sku__icontains=keyword) )
 
     results.update({
         'categories': categories,

File satchmo/apps/product/views/adminviews.py

 from product.models import Product
 from product.modules.configurable.models import ConfigurableProduct
 from satchmo_utils.views import bad_or_missing
+
 import logging
-
 log = logging.getLogger('product.views.adminviews')
 
 def edit_inventory(request):
     """A quick inventory price, qty update form"""
+    page = int(request.GET.get('p', '1'))
+
     if request.method == "POST":
         new_data = request.POST.copy()
-        form = InventoryForm(new_data)
+        form = InventoryForm(new_data, page=page)
         if form.is_valid():
             form.save(request)
             url = urlresolvers.reverse('satchmo_admin_edit_inventory')
+
+            url = '%s?p=%d' % (url, page) if page > 1 else url
             return HttpResponseRedirect(url)
     else:
-        form = InventoryForm()
+        form = InventoryForm(page=page)
 
     ctx = RequestContext(request, {
-        'title' : _('Inventory Editor'),
-        'form' : form
-        })
+        'title': _('Inventory Editor'),
+        'form': form
+    })
 
     return render_to_response('product/admin/inventory_form.html',
                               context_instance=ctx)
             return form.export(request)
     else:
         form = ProductExportForm()
-        fileform = ProductImportForm()
-
+    fileform = ProductImportForm()
 
     ctx = RequestContext(request, {
-        'title' : _('Product Import/Export'),
-        'form' : form,
+        'title': _('Product Import/Export'),
+        'form': form,
         'importform': fileform
-        })
+    })
 
     return render_to_response(template, context_instance=ctx)
 
             errors.append(_('No upload file found'))
 
         ctx = RequestContext(request, {
-            'errors' : errors,
-            'results' : results
+            'errors': errors,
+            'results': results
         })
         return render_to_response("product/admin/product_import_result.html",
                                   context_instance=ctx)
 # product_active_report = user_passes_test(lambda u: u.is_authenticated() and u.is_staff, login_url='/accounts/login/')(product_active_report)
 
 def variation_list(request):
-    products = Product.objects.filter(configurableproduct__in = ConfigurableProduct.objects.all())
+    products = Product.objects.filter(configurableproduct__in=ConfigurableProduct.objects.all())
     ctx = RequestContext(request, {
-           'products' : products,
-    })
+        'products': products,
+        })
 
     return render_to_response('product/admin/variation_manager_list.html',
                               context_instance=ctx)
 
 
-def variation_manager(request, product_id = ""):
+def variation_manager(request, product_id=""):
     try:
         product = Product.objects.get(id=product_id)
         subtypes = product.get_subtypes()
             product = product.productvariation.parent.product
             if 'ConfigurableProduct' in product.get_subtypes():
                 url = urlresolvers.reverse("satchmo_admin_variation_manager",
-                    kwargs = {'product_id' : product.id})
+                                           kwargs={'product_id': product.id})
                 return HttpResponseRedirect(url)
 
         if 'ConfigurableProduct' not in subtypes:
             return bad_or_missing(request, _('The product you have requested is not a Configurable Product.'))
 
     except Product.DoesNotExist:
-            return bad_or_missing(request, _('The product you have requested does not exist.'))
+        return bad_or_missing(request, _('The product you have requested does not exist.'))
 
     if request.method == 'POST':
         new_data = request.POST.copy()
         form = VariationManagerForm(product=product)
 
     ctx = RequestContext(request, {
-        'product' : product,
-        'form' : form,
-    })
+        'product': product,
+        'form': form,
+        })
     return render_to_response('product/admin/variation_manager.html',
                               context_instance=ctx)