def post(self, request, *args, **kwargs): if not request.user.is_authenticated(): raise PermissionDenied recipe = get_object_or_404(ImageComparisonRecipe, pk=self.kwargs['selectfor']) if not recipe.comparison.user_can_edit(request.user): raise PermissionDenied form = ImageComparisonRecipeForm(request.POST, prefix='selectrecipedialog', instance=recipe) if form.is_valid(): form.save() messages.success( request, 'Changes to image comparison recipe %s saved successfully.' % recipe.pn) return HttpResponseRedirect( reverse('image_comparison_recipe', args=(recipe.id, ))) else: # FIXME this is ugly because HTML gets escaped messages.error(request, 'Failed to save changes: %s' % form.errors) return self.get(request, *args, **kwargs)
def get_context_data(self, **kwargs): context = super(ImageCompareRecipeSelectDetailView, self).get_context_data(**kwargs) recipe = get_object_or_404(ImageComparisonRecipe, pk=self.kwargs['selectfor']) if not recipe.comparison.user_can_view(self.request.user): raise PermissionDenied context['select_for'] = recipe context['existing_cover_recipe'] = recipe.get_cover_recipe() comparison_form = ImageComparisonRecipeForm( prefix='selectrecipedialog', instance=recipe) comparison_form.fields['cover_pn'].widget = forms.HiddenInput() comparison_form.fields['cover_layerbranch'].widget = forms.HiddenInput( ) context['comparison_form'] = comparison_form context['can_edit'] = False context['image_comparison'] = True return context