summaryrefslogtreecommitdiff
path: root/app/photos/views.py
blob: 7d108419ef732b1746bdafd65bc507aaf940d1f7 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from django.shortcuts import render_to_response,get_object_or_404
from django.template import RequestContext
from django.views.generic.list_detail import object_list
from django.http import Http404,HttpResponse
from django.core import serializers
from django.conf import settings

from photos.models import Photo,PhotoGallery
from locations.models import Country, Region
    
    
    
def gallery_list(request,page):
    request.page_url = '/photos/%d/'
    request.page = int(page)
    qs = PhotoGallery.objects.all()
    try:
        is_build = request.POST['builder']
        extra_context= {
            'page':page,
            'MEDIA_URL': settings.BAKED_MEDIA_URL
        }
    except KeyError:
        extra_context={'page':page,}
    return object_list(request, queryset=qs, template_name='archives/photos.html',extra_context=extra_context)

def gallery(request,slug):
    context = {
        'object': PhotoGallery.objects.get(set_slug=slug)
    }    
    return render_to_response('details/photo_galleries.html', context, context_instance = RequestContext(request))

def photo_json(request, slug):
    p = PhotoGallery.objects.filter(set_slug=slug)
    return HttpResponse(serializers.serialize('json', p), mimetype='application/json')

"""
Grabs entries by region or country
"""
def gallery_list_by_area(request,slug,page):
    request.page_url = '/photos/'+slug+'/%d/'
    request.page = int(page)
    try:
        region = Region.objects.get(slug__exact=slug)
        qs = PhotoGallery.objects.filter(region = region).order_by('-id')
    except:
        region = Country.objects.get(slug__exact=slug)
        qs = PhotoGallery.objects.filter(location__state__country = region).order_by('-id')
        if not region:
            raise Http404
    context = {
        'region': region,
        'country_list': Country.objects.filter(visited=True),
        'region_list': Region.objects.all(),
        'page': page
    }
    return object_list(request, queryset=qs, template_name='archives/photos.html',
                       extra_context=context)