+
+
+@active_tab('cover')
+def image(request, pk):
+ image = get_object_or_404(Image, pk=pk)
+
+ if request.user.has_perm('cover.change_image'):
+ if request.method == "POST":
+ form = forms.ImageEditForm(request.POST, request.FILES, instance=image)
+ if form.is_valid():
+ form.save()
+ return HttpResponseRedirect(image.get_absolute_url())
+ else:
+ form = forms.ImageEditForm(instance=image)
+ editable = True
+ else:
+ form = forms.ReadonlyImageEditForm(instance=image)
+ editable = False
+
+ return render(request, "cover/image_detail.html", {
+ "object": Image.objects.get(id=image.id),
+ "form": form,
+ "editable": editable,
+ })
+
+
+@active_tab('cover')
+def image_list(request):
+ return render(request, "cover/image_list.html", {
+ 'object_list': Image.objects.all(),
+ 'can_add': request.user.has_perm('cover.add_image'),
+ })
+
+
+@permission_required('cover.add_image')
+@active_tab('cover')
+def add_image(request):
+ form = ff = None
+ if request.method == 'POST':
+ if request.POST.get('form_id') == 'flickr':
+ ff = forms.FlickrForm(request.POST)
+ if ff.is_valid():
+ form = forms.ImageAddForm(ff.cleaned_data)
+ else:
+ form = forms.ImageAddForm(request.POST, request.FILES)
+ if form.is_valid():
+ obj = form.save()
+ return HttpResponseRedirect(obj.get_absolute_url())
+ if form is None:
+ form = forms.ImageAddForm()
+ if ff is None:
+ ff = forms.FlickrForm()
+ return render(request, 'cover/add_image.html', {
+ 'form': form,
+ 'ff': ff,
+ })