Add invoice logo

This commit is contained in:
Raphael Michel
2017-01-21 17:44:47 +01:00
parent ad73c0e05b
commit 598e7c5637
5 changed files with 24 additions and 5 deletions

View File

@@ -14,6 +14,7 @@ from django.utils.translation import pgettext, ugettext as _
from reportlab.lib import pagesizes
from reportlab.lib.styles import ParagraphStyle, StyleSheet1
from reportlab.lib.units import mm
from reportlab.lib.utils import ImageReader
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.platypus import (
@@ -252,6 +253,13 @@ def _invoice_generate_german(invoice, f):
textobject.textLine(date_format(invoice.order.datetime, "DATE_FORMAT"))
canvas.drawText(textobject)
if invoice.event.settings.invoice_logo_image:
logo_file = invoice.event.settings.get('invoice_logo_image', binary_file=True)
canvas.drawImage(ImageReader(logo_file),
95 * mm, (297 - 38) * mm,
width=25 * mm, height=25 * mm,
preserveAspectRatio=True, anchor='n')
textobject = canvas.beginText(125 * mm, (297 - 15) * mm)
textobject.setFont('OpenSansBd', 8)
textobject.textLine(_('Event').upper())

View File

@@ -301,6 +301,10 @@ Your {event} team"""))
'default': None,
'type': File
},
'invoice_logo_image': {
'default': None,
'type': File
},
'frontpage_text': {
'default': '',
'type': LazyI18nString
@@ -361,7 +365,7 @@ class SettingsProxy:
settings[key] = self.get(key)
return settings
def _unserialize(self, value: str, as_type: type) -> Any:
def _unserialize(self, value: str, as_type: type, binary_file=False) -> Any:
if as_type is None and value is not None and value.startswith('file://'):
as_type = File
@@ -377,7 +381,7 @@ class SettingsProxy:
return value == 'True'
elif as_type == File:
try:
fi = default_storage.open(value[7:], 'r')
fi = default_storage.open(value[7:], 'rb' if binary_file else 'r')
fi.url = default_storage.url(value[7:])
return fi
except OSError:
@@ -416,7 +420,7 @@ class SettingsProxy:
raise TypeError('Unable to serialize %s into a setting.' % str(type(value)))
def get(self, key: str, default=None, as_type: type=None):
def get(self, key: str, default=None, as_type: type=None, binary_file=False):
"""
Get a setting specified by key ``key``. Normally, settings are strings, but
if you put non-strings into the settings object, you can request unserialization
@@ -442,7 +446,7 @@ class SettingsProxy:
if value is None and default is not None:
value = default
return self._unserialize(value, as_type)
return self._unserialize(value, as_type, binary_file=binary_file)
def __getitem__(self, key: str) -> Any:
return self.get(key)

View File

@@ -361,6 +361,13 @@ class InvoiceSettingsForm(SettingsForm):
label=_("Invoice language"),
choices=[('__user__', _('The user\'s language'))] + settings.LANGUAGES,
)
invoice_logo_image = ExtFileField(
label=_('Logo image'),
ext_whitelist=(".png", ".jpg", ".svg", ".gif", ".jpeg"),
required=False,
help_text=_('If you provide a logo image, we will not show your events name and date on the invoice'
'the page header. We will show your logo with a maximal height and width of 2.5 cm.')
)
class MailSettingsForm(SettingsForm):

View File

@@ -17,6 +17,7 @@
{% bootstrap_field form.invoice_introductory_text layout="horizontal" %}
{% bootstrap_field form.invoice_additional_text layout="horizontal" %}
{% bootstrap_field form.invoice_footer_text layout="horizontal" %}
{% bootstrap_field form.invoice_logo_image layout="horizontal" %}
</fieldset>
<div class="form-group submit-group">
<button type="submit" class="btn btn-default btn-lg" name="preview" value="preview" formtarget="_blank">