+ form = forms.ReadonlyImageEditForm(instance=img)
+ editable = False
+
+ return render(request, "cover/image_detail.html", {
+ "object": Image.objects.get(id=img.id),
+ "form": form,
+ "editable": editable,
+ })
+
+
+def image_file(request, pk):
+ img = get_object_or_404(Image, pk=pk)
+ return HttpResponseRedirect(img.file.url)
+
+
+@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,
+ })