thanks izantal! -rt
On Jul 27, 6:32 pm, lzantal <[email protected]> wrote: > Hi, > > Here is the code to let the user choose the amount of products > displayed per page. > I created a pagemiddleware.py module and added it to the > MIDDLEWARE_CLASSES in settings.py > I have this very simple class in pagemiddleware.py > """ > class PageMiddleware(object): > def process_request(self, request): > if not request.REQUEST.get('itemperpage', False): > if not request.session.get('itemperpage', False): > request.session['itemperpage'] = 15 > else: > try: > request.session['itemperpage'] = > int(request.REQUEST['itemperpage']) > except (KeyError, ValueError, TypeError): > request.session['itemperpage'] = 15 > return None > """ > > After this change the search.html template > """ > {% with results.products as products %} > <div class="item-per-page"> > Items found: {{ products|length }} > <strong>Show: </strong> > <a href="?itemperpage=15&{{ request.META.QUERY_STRING }}"> 15 </a> > ›› > <a href="?itemperpage=30&{{ request.META.QUERY_STRING }}"> 30 </a> > ›› > <a href="?itemperpage=60&{{ request.META.QUERY_STRING }}"> 60 </a> > items per page. > <br class="clear-both" /> > </div> > {% autopaginate products request.session.itemperpage %} > <ul> > {% for product in products %} > / more code here / > {% endfor %} > </ul> > <br /> > {% paginate %} > {% endwith %} > """ > > I put the middleware into the pagination app. > > lzantal > > On Jul 27, 1:12 pm, RT <[email protected]> wrote: > > > That sounds really useful, I'll look forward to it! > > > On Jul 27, 12:38 pm, lzantal <[email protected]> wrote: > > > > Hi, > > > > Glad to hear that.:) > > > I'll be home tonight and will add the code that let the user set > > > quantity/page, > > > It also displays the Items Found. > > > > lzantal > > > > On Jul 27, 9:48 am, RT <[email protected]> wrote: > > > > > Thanks Izantal, that works great! > > > > > -RT > > > > > On Jul 26, 9:48 pm, lzantal <[email protected]> wrote: > > > > > > Hi, > > > > > > On Jul 26, 10:01 am, RT <[email protected]> wrote: > > > > > > > I know this has been discussed before but it seems like it has been > > > > > > awhile. What is the status of pagination (say of search) in > > > > > > Satchmo. > > > > > > Is it easy functionality to attain? > > > > > > Yes it is. I'll dig up the code tomorrow to let the user select how > > > > > many product they want to display on the page Eg: Show 15, 30, 60. > > > > > I am using the pagination app > > > > > http://code.google.com/p/django-pagination/ > > > > > . > > > > > Once you install it here is the pagination specific code from my shop/ > > > > > search.html template > > > > > """ > > > > > {% load pagination_tags %} > > > > > {% with results.products as products %} > > > > > {% autopaginate products %} > > > > > <ul> > > > > > {% for product in products %} > > > > > / more code here / > > > > > {% endfor %} > > > > > </ul> > > > > > <br /> > > > > > {% paginate %} > > > > > {% endwith %} > > > > > > Hope it helps > > > > > > lzantal > > > > > > > -RT -- You received this message because you are subscribed to the Google Groups "Satchmo users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/satchmo-users?hl=en.
