Adding invoice pdf link to Order admin

This commit is contained in:
Víðir Valberg Guðmundsson 2016-05-31 23:23:05 +02:00
parent 9203285299
commit d3bc597f54
4 changed files with 23 additions and 3 deletions

View file

@ -8,6 +8,7 @@ admin.site.register(models.CoinifyAPIInvoice)
admin.site.register(models.CoinifyAPICallback)
admin.site.register(models.Invoice)
@admin.register(models.ProductCategory)
class ProductCategoryAdmin(admin.ModelAdmin):
list_display = [
@ -35,9 +36,9 @@ class TicketInline(admin.TabularInline):
@admin.register(models.Order)
class OrderAdmin(admin.ModelAdmin):
change_form_template = 'admin/change_order_form.html'
list_display = [
'id',
'user',
@ -67,4 +68,4 @@ class OrderAdmin(admin.ModelAdmin):
@admin.register(models.Ticket)
class TicketAdmin(admin.ModelAdmin):
pass
pass

View file

@ -2,6 +2,7 @@ from django.conf import settings
from django.db import models
from django.db.models.aggregates import Sum
from django.contrib.postgres.fields import DateTimeRangeField, JSONField
from django.http import HttpResponse
from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone

View file

@ -0,0 +1,16 @@
{% extends "admin/change_form.html" %}
{% load i18n admin_urls admin_static admin_modify %}
{% block object-tools-items %}
<li>
{% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
<a href="{% add_preserved_filters history_url %}" class="historylink">{% trans "History" %}</a>
</li>
{% if original.paid and original.invoice %}
<li>
{% url 'shop:download_invoice' original.pk|admin_urlquote as invoice_url %}
<a href="{% add_preserved_filters invoice_url %}" class="historylink">{% trans "Invoice PDF" %}</a>
</li>
{% endif %}
{% if has_absolute_url %}<li><a href="{{ absolute_url }}" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif %}
{% endblock %}

View file

@ -39,11 +39,13 @@ from vendor.coinify_api import CoinifyAPI
from vendor.coinify_callback import CoinifyCallback
import json
class EnsureUserOwnsOrderMixin(SingleObjectMixin):
model = Order
def dispatch(self, request, *args, **kwargs):
if self.get_object().user != request.user:
# If the user does not own this ticket OR is not staff
if self.get_object().user != request.user or not request.user.is_staff:
raise Http404("Order not found")
return super(EnsureUserOwnsOrderMixin, self).dispatch(