+ form = forms.ReadonlyImageEditForm(instance=image)
+ editable = False
+
+ return render(request, "cover/image_detail.html", {
+ "object": image,
+ "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,
+ })