aboutsummaryrefslogtreecommitdiff
path: root/apps/utils/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'apps/utils/views.py')
-rw-r--r--apps/utils/views.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/apps/utils/views.py b/apps/utils/views.py
new file mode 100644
index 0000000..dcb16a8
--- /dev/null
+++ b/apps/utils/views.py
@@ -0,0 +1,69 @@
+from itertools import chain
+import json
+from django.http import Http404, HttpResponse
+from django.views.generic import ListView
+from photos.models import LuxImage, LuxVideo
+from django.shortcuts import render_to_response
+from django.shortcuts import render
+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'])
+ request.base_path = path
+ 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()[:80]
+ videos = LuxVideo.objects.all()[:10]
+ object_list = sorted(
+ chain(images, videos),
+ key=lambda instance: instance.pub_date,
+ reverse=True
+ )
+ return render(request, 'admin/insert_images.html', {'object_list': object_list, 'textarea_id': request.GET['textarea']})
+
+
+from taggit.models import Tag
+
+from dal import autocomplete
+
+class TagAutocomplete(autocomplete.Select2QuerySetView):
+ def get_queryset(self):
+ # Don't forget to filter out results depending on the visitor !
+ if not self.request.user.is_authenticated:
+ return Tag.objects.none()
+
+ qs = Tag.objects.all()
+
+ if self.q:
+ qs = qs.filter(name__istartswith=self.q)
+
+ return qs
+
+from django.apps import apps
+
+def nav_json(request, app, model, pk):
+ model = apps.get_model(app_label=app, model_name=model)
+ p = model.objects.get(pk=pk)
+ data = {}
+ data['prev'] = p.get_previous_admin_url
+ data['next'] = p.get_next_admin_url
+ data = json.dumps(data)
+ return HttpResponse(data)