Mercurial > public > sg101
comparison user_photos/views.py @ 1158:364f8ec48612
Updated User Photos to V3 design.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 23 Jan 2017 20:17:50 -0600 |
parents | d9cd3180c12c |
children |
comparison
equal
deleted
inserted
replaced
1157:e4f2d6a4b401 | 1158:364f8ec48612 |
---|---|
5 from django.contrib.auth import get_user_model | 5 from django.contrib.auth import get_user_model |
6 from django.contrib.auth.decorators import login_required | 6 from django.contrib.auth.decorators import login_required |
7 from django.http import (HttpResponse, HttpResponseForbidden, | 7 from django.http import (HttpResponse, HttpResponseForbidden, |
8 HttpResponseNotAllowed, JsonResponse) | 8 HttpResponseNotAllowed, JsonResponse) |
9 from django.shortcuts import render, redirect, get_object_or_404 | 9 from django.shortcuts import render, redirect, get_object_or_404 |
10 from django.views.generic import DetailView | |
10 from django.views.generic import ListView | 11 from django.views.generic import ListView |
11 from django.views.decorators.http import require_POST | 12 from django.views.decorators.http import require_POST |
12 from django.utils.decorators import method_decorator | 13 from django.utils.decorators import method_decorator |
13 from django.contrib import messages | 14 from django.contrib import messages |
14 | 15 |
38 form = UploadForm(user=request.user) | 39 form = UploadForm(user=request.user) |
39 | 40 |
40 return render(request, 'user_photos/upload_form.html', { | 41 return render(request, 'user_photos/upload_form.html', { |
41 'enabled': uploads_enabled, | 42 'enabled': uploads_enabled, |
42 'form': form, | 43 'form': form, |
44 'V3_DESIGN': True, | |
43 }, | 45 }, |
44 status=200 if uploads_enabled else 503) | 46 status=200 if uploads_enabled else 503) |
45 | 47 |
46 | 48 |
47 def upload_ajax(request): | 49 def upload_ajax(request): |
142 return Photo.objects.filter(user=self.gallery_owner).order_by('-upload_date') | 144 return Photo.objects.filter(user=self.gallery_owner).order_by('-upload_date') |
143 | 145 |
144 def get_context_data(self, **kwargs): | 146 def get_context_data(self, **kwargs): |
145 context = super(GalleryView, self).get_context_data(**kwargs) | 147 context = super(GalleryView, self).get_context_data(**kwargs) |
146 context['gallery_owner'] = self.gallery_owner | 148 context['gallery_owner'] = self.gallery_owner |
149 context['V3_DESIGN'] = True | |
150 context['page'] = context['page_obj'] | |
147 return context | 151 return context |
148 | 152 |
149 @method_decorator(login_required) | 153 @method_decorator(login_required) |
150 def dispatch(self, *args, **kwargs): | 154 def dispatch(self, *args, **kwargs): |
151 return super(GalleryView, self).dispatch(*args, **kwargs) | 155 return super(GalleryView, self).dispatch(*args, **kwargs) |
156 | |
157 | |
158 class PhotoView(DetailView): | |
159 """A DetailView for displaying a user's photo""" | |
160 | |
161 model = Photo | |
162 | |
163 def get_context_data(self, **kwargs): | |
164 context = super(PhotoView, self).get_context_data(**kwargs) | |
165 context['V3_DESIGN'] = True | |
166 return context | |
152 | 167 |
153 | 168 |
154 @login_required | 169 @login_required |
155 @require_POST | 170 @require_POST |
156 def delete(request): | 171 def delete(request): |
226 else: | 241 else: |
227 ret['error_msg'] = 'Image linking is temporarily disabled' | 242 ret['error_msg'] = 'Image linking is temporarily disabled' |
228 status_code = 403 | 243 status_code = 403 |
229 | 244 |
230 return JsonResponse(ret, status=status_code) | 245 return JsonResponse(ret, status=status_code) |
231 |