summaryrefslogtreecommitdiff
path: root/app/utils/views.py
blob: c5f3f593b2c7ca70870667324ccdd8877c0b3fcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from itertools import chain
from django.views.generic import ListView
from photos.models import LuxImage, LuxVideo
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):
    """
    The view that handles the admin insert image/video feature
    """
    images = LuxImage.objects.all()[:50]
    videos = LuxVideo.objects.all()[:10]
    object_list = sorted(
        chain(images, videos),
        key=lambda instance: instance.pub_date,
        reverse=True
    )
    return render_to_response('admin/insert_images.html', {'object_list': object_list, 'textarea_id': request.GET['textarea']}, context_instance=RequestContext(request))