Uses for_id_or_404 in views.py

This commit is contained in:
Christopher Neugebauer 2016-04-25 07:14:14 +10:00
parent ca8f67c2f3
commit 9f72b67510

View file

@ -481,10 +481,7 @@ def invoice(request, invoice_id, access_code=None):
access code. access code.
''' '''
invoice_id = int(invoice_id) current_invoice = InvoiceController.for_id_or_404(invoice_id)
inv = commerce.Invoice.objects.get(pk=invoice_id)
current_invoice = InvoiceController(inv)
if not current_invoice.can_view( if not current_invoice.can_view(
user=request.user, user=request.user,
@ -508,9 +505,7 @@ def manual_payment(request, invoice_id):
if not request.user.is_staff: if not request.user.is_staff:
raise Http404() raise Http404()
invoice_id = int(invoice_id) current_invoice = InvoiceController.for_id_or_404(invoice_id)
inv = get_object_or_404(commerce.Invoice, pk=invoice_id)
current_invoice = InvoiceController(inv)
form = forms.ManualPaymentForm( form = forms.ManualPaymentForm(
request.POST or None, request.POST or None,
@ -539,9 +534,7 @@ def refund(request, invoice_id):
if not request.user.is_staff: if not request.user.is_staff:
raise Http404() raise Http404()
invoice_id = int(invoice_id) current_invoice = InvoiceController.for_id_or_404(invoice_id)
inv = get_object_or_404(commerce.Invoice, pk=invoice_id)
current_invoice = InvoiceController(inv)
try: try:
current_invoice.refund() current_invoice.refund()
@ -560,10 +553,7 @@ def credit_note(request, note_id, access_code=None):
if not request.user.is_staff: if not request.user.is_staff:
raise Http404() raise Http404()
note_id = int(note_id) current_note = CreditNoteController.for_id_or_404(note_id)
note = commerce.CreditNote.objects.get(pk=note_id)
current_note = CreditNoteController(note)
apply_form = forms.ApplyCreditNoteForm( apply_form = forms.ApplyCreditNoteForm(
note.invoice.user, note.invoice.user,