forked from CGM_Public/pretix_original
Add invoice logo
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
from pretix.settings import *
|
from pretix.settings import *
|
||||||
|
|
||||||
|
|
||||||
LOGGING['handlers']['mail_admins']['include_html'] = True
|
LOGGING['handlers']['mail_admins']['include_html'] = True
|
||||||
STATIC_ROOT = '/static'
|
STATIC_ROOT = '/static'
|
||||||
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
|
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from django.utils.translation import pgettext, ugettext as _
|
|||||||
from reportlab.lib import pagesizes
|
from reportlab.lib import pagesizes
|
||||||
from reportlab.lib.styles import ParagraphStyle, StyleSheet1
|
from reportlab.lib.styles import ParagraphStyle, StyleSheet1
|
||||||
from reportlab.lib.units import mm
|
from reportlab.lib.units import mm
|
||||||
|
from reportlab.lib.utils import ImageReader
|
||||||
from reportlab.pdfbase import pdfmetrics
|
from reportlab.pdfbase import pdfmetrics
|
||||||
from reportlab.pdfbase.ttfonts import TTFont
|
from reportlab.pdfbase.ttfonts import TTFont
|
||||||
from reportlab.platypus import (
|
from reportlab.platypus import (
|
||||||
@@ -252,6 +253,13 @@ def _invoice_generate_german(invoice, f):
|
|||||||
textobject.textLine(date_format(invoice.order.datetime, "DATE_FORMAT"))
|
textobject.textLine(date_format(invoice.order.datetime, "DATE_FORMAT"))
|
||||||
canvas.drawText(textobject)
|
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 = canvas.beginText(125 * mm, (297 - 15) * mm)
|
||||||
textobject.setFont('OpenSansBd', 8)
|
textobject.setFont('OpenSansBd', 8)
|
||||||
textobject.textLine(_('Event').upper())
|
textobject.textLine(_('Event').upper())
|
||||||
|
|||||||
@@ -301,6 +301,10 @@ Your {event} team"""))
|
|||||||
'default': None,
|
'default': None,
|
||||||
'type': File
|
'type': File
|
||||||
},
|
},
|
||||||
|
'invoice_logo_image': {
|
||||||
|
'default': None,
|
||||||
|
'type': File
|
||||||
|
},
|
||||||
'frontpage_text': {
|
'frontpage_text': {
|
||||||
'default': '',
|
'default': '',
|
||||||
'type': LazyI18nString
|
'type': LazyI18nString
|
||||||
@@ -361,7 +365,7 @@ class SettingsProxy:
|
|||||||
settings[key] = self.get(key)
|
settings[key] = self.get(key)
|
||||||
return settings
|
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://'):
|
if as_type is None and value is not None and value.startswith('file://'):
|
||||||
as_type = File
|
as_type = File
|
||||||
|
|
||||||
@@ -377,7 +381,7 @@ class SettingsProxy:
|
|||||||
return value == 'True'
|
return value == 'True'
|
||||||
elif as_type == File:
|
elif as_type == File:
|
||||||
try:
|
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:])
|
fi.url = default_storage.url(value[7:])
|
||||||
return fi
|
return fi
|
||||||
except OSError:
|
except OSError:
|
||||||
@@ -416,7 +420,7 @@ class SettingsProxy:
|
|||||||
|
|
||||||
raise TypeError('Unable to serialize %s into a setting.' % str(type(value)))
|
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
|
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
|
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:
|
if value is None and default is not None:
|
||||||
value = default
|
value = default
|
||||||
|
|
||||||
return self._unserialize(value, as_type)
|
return self._unserialize(value, as_type, binary_file=binary_file)
|
||||||
|
|
||||||
def __getitem__(self, key: str) -> Any:
|
def __getitem__(self, key: str) -> Any:
|
||||||
return self.get(key)
|
return self.get(key)
|
||||||
|
|||||||
@@ -361,6 +361,13 @@ class InvoiceSettingsForm(SettingsForm):
|
|||||||
label=_("Invoice language"),
|
label=_("Invoice language"),
|
||||||
choices=[('__user__', _('The user\'s language'))] + settings.LANGUAGES,
|
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):
|
class MailSettingsForm(SettingsForm):
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
{% bootstrap_field form.invoice_introductory_text layout="horizontal" %}
|
{% bootstrap_field form.invoice_introductory_text layout="horizontal" %}
|
||||||
{% bootstrap_field form.invoice_additional_text layout="horizontal" %}
|
{% bootstrap_field form.invoice_additional_text layout="horizontal" %}
|
||||||
{% bootstrap_field form.invoice_footer_text layout="horizontal" %}
|
{% bootstrap_field form.invoice_footer_text layout="horizontal" %}
|
||||||
|
{% bootstrap_field form.invoice_logo_image layout="horizontal" %}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<div class="form-group submit-group">
|
<div class="form-group submit-group">
|
||||||
<button type="submit" class="btn btn-default btn-lg" name="preview" value="preview" formtarget="_blank">
|
<button type="submit" class="btn btn-default btn-lg" name="preview" value="preview" formtarget="_blank">
|
||||||
|
|||||||
Reference in New Issue
Block a user