Skip to content

Commit

Permalink
Update pdf invoices to use xhtml2pdf. Closes #180.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenmcd committed Mar 1, 2014
1 parent f8f994f commit f76226c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cartridge/shop/templates/shop/complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
<br>
<form class="order-complete-form" method="post" action="{% url "shop_invoice_resend" order.id %}?next={{ request.path }}">
{% csrf_token %}
{% if has_pdf %}
<a class="btn btn-primary" href="{% url "shop_invoice" order.id %}?format=pdf">{% trans "Download PDF invoice" %}</a>
{% endif %}
<a class="btn btn-default" target="_blank" href="{% url "shop_invoice" order.id %}">{% trans "View invoice in your browser" %}</a>
<input type="submit" class="btn btn-default" value="{% trans "Re-send order email" %}">
</form>
Expand Down
11 changes: 7 additions & 4 deletions cartridge/shop/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
from django.template.loader import get_template
from django.utils.translation import ugettext as _
from django.views.decorators.cache import never_cache

from mezzanine.conf import settings
from mezzanine.utils.importing import import_dotted_path
from mezzanine.utils.views import render, set_cookie, paginate
from mezzanine.utils.urls import next_url

try:
from xhtml2pdf import pisa
except (ImportError, SyntaxError):
pisa = None

from cartridge.shop import checkout
from cartridge.shop.forms import (AddProductForm, CartItemFormSet,
DiscountForm, OrderForm)
Expand Down Expand Up @@ -345,7 +349,7 @@ def complete(request, template="shop/complete.html"):
names[variation.sku] = variation.product.title
for i, item in enumerate(items):
setattr(items[i], "name", names[item.sku])
context = {"order": order, "items": items,
context = {"order": order, "items": items, "has_pdf": pisa is not None,
"steps": checkout.CHECKOUT_STEPS}
return render(request, template, context)

Expand All @@ -369,8 +373,7 @@ def invoice(request, order_id, template="shop/order_invoice.html",
name = slugify("%s-invoice-%s" % (settings.SITE_TITLE, order.id))
response["Content-Disposition"] = "attachment; filename=%s.pdf" % name
html = get_template(template_pdf).render(context)
import ho.pisa
ho.pisa.CreatePDF(html, response)
pisa.CreatePDF(html, response)
return response
return render(request, template, context)

Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@

install_requires=[
"mezzanine >= 3.0.6",
"pisa >= 3.0.33",
"reportlab == 2.7"
"xhtml2pdf",
],

classifiers=[
Expand Down

0 comments on commit f76226c

Please sign in to comment.