Skip to content

Commit

Permalink
Don't show delete page in control panel if deletion is impossible
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Feb 11, 2016
1 parent fe6bcd2 commit 6b25dea
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/pretix/control/views/vouchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ def get_object(self, queryset=None) -> Voucher:
except Voucher.DoesNotExist:
raise Http404(_("The requested voucher does not exist."))

def get_context_data(self, *args, **kwargs) -> dict:
context = super().get_context_data(*args, **kwargs)
context['allowed'] = not self.get_object().is_ordered()
return context
def get(self, request, *args, **kwargs):
if self.get_object().is_ordered():
messages.error(request, _('A voucher can not be deleted if it already has been redeemed.'))
return HttpResponseRedirect(self.get_success_url())
super().get(request, *args, **kwargs)

@transaction.atomic()
def delete(self, request, *args, **kwargs):
Expand Down

0 comments on commit 6b25dea

Please sign in to comment.