from django.views.generic import ListView from photos.models import LuxImage from django.shortcuts import render_to_response from django.template import RequestContext class PaginatedListView(ListView): """ handles my own pagination system """ context_object_name = 'object_list' def dispatch(self, request, *args, **kwargs): path = request.path.split('/')[1:-1] if path[-1] == self.kwargs['page']: path = "/".join(t for t in path[:-1]) request.page_url = "/" + path + '/%d/' else: request.page_url = request.path + '%d/' print(request.page_url) request.page = int(self.kwargs['page']) return super(PaginatedListView, self).dispatch(request, *args, **kwargs) def insert_image(request): images = LuxImage.objects.all()[:50] return render_to_response('admin/insert_images.html', {'images': images, 'textarea_id': request.GET['textarea']}, context_instance=RequestContext(request))