summaryrefslogtreecommitdiff
path: root/app/media/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/media/views.py')
-rw-r--r--app/media/views.py130
1 files changed, 130 insertions, 0 deletions
diff --git a/app/media/views.py b/app/media/views.py
new file mode 100644
index 0000000..915b022
--- /dev/null
+++ b/app/media/views.py
@@ -0,0 +1,130 @@
+import json
+from django.shortcuts import render_to_response, render
+from django.template import RequestContext
+from django.http import Http404, HttpResponse
+from django.core import serializers
+
+from .models import Photo, PhotoGallery, LuxGallery, LuxImage
+from locations.models import Country, Region
+
+from utils.views import PaginatedListView
+from django.views.generic import ListView
+from django.views.generic.detail import DetailView
+
+
+class PrivateGallery(DetailView):
+ model = LuxGallery
+ slug_field = "slug"
+ template_name = "details/photo_gallery.html"
+
+
+class PrivateGalleryList(PaginatedListView):
+ template_name = 'archives/gallery_list.html'
+
+ def get_queryset(self):
+ return LuxGallery.objects.filter(is_public=False)
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(PrivateGalleryList, self).get_context_data(**kwargs)
+ context['is_private'] = True
+ return context
+
+
+class Gallery(DetailView):
+ model = LuxGallery
+ slug_field = "slug"
+ template_name = "details/photo_gallery.html"
+
+
+class GalleryList(PaginatedListView):
+ template_name = 'archives/gallery_list.html'
+
+ def get_queryset(self):
+ return LuxGallery.objects.filter(is_public=True)
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(GalleryList, self).get_context_data(**kwargs)
+ context['is_private'] = False
+ return context
+
+
+class OldGalleryList(PaginatedListView):
+ template_name = 'archives/gallery_list.html'
+ model = PhotoGallery
+
+ def get_queryset(self):
+ return PhotoGallery.objects.filter(is_public=True)
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(OldGalleryList, self).get_context_data(**kwargs)
+ return context
+
+
+class DailyPhotoList(PaginatedListView):
+ template_name = 'archives/photo_daily_list.html'
+
+ def get_queryset(self):
+ return LuxImage.objects.filter(is_public=True, title__startswith="daily_")
+
+
+def gallery_list(request, page):
+ request.page_url = '/photos/%d/'
+ request.page = int(page)
+ context = {
+ 'object_list': PhotoGallery.objects.all(),
+ 'page': page,
+ }
+ return render(request, "archives/photos.html", 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')
+
+
+def photo_preview_json(request, pk):
+ p = LuxImage.objects.get(pk=pk)
+ data = {}
+ data['url'] = p.get_admin_image()
+ data = json.dumps(data)
+ return HttpResponse(data)
+
+
+def thumb_preview_json(request, pk):
+ p = LuxImage.objects.get(pk=pk)
+ data = {}
+ data['url'] = p.get_admin_insert()
+ data = json.dumps(data)
+ return HttpResponse(data)
+
+
+def gallery_list_by_area(request, slug, page):
+ """Grabs entries by region or country"""
+ 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 = {
+ 'object_list': qs,
+ 'country_list': Country.objects.filter(visited=True),
+ 'region_list': Region.objects.all(),
+ 'region': region,
+ 'page': page
+ }
+ return render_to_response("archives/photos.html", context, context_instance=RequestContext(request))