Add documentation on mail methods

This commit is contained in:
Raphael Michel
2017-07-27 15:47:22 +02:00
parent a1535da117
commit 46976900d7
2 changed files with 27 additions and 1 deletions

View File

@@ -2,6 +2,9 @@ Sending Email
============= =============
pretix allows event organizers to configure how they want to send emails to their users in multiple ways. pretix allows event organizers to configure how they want to send emails to their users in multiple ways.
Therefore, all emails should be sent through the following function: Therefore, all emails should be sent through the following function.
If the email you send is related to an order, you should also take a look at the
:py:meth:`~pretix.base.models.Order.send_mail` of the order model.
.. autofunction:: pretix.base.services.mail.mail .. autofunction:: pretix.base.services.mail.mail

View File

@@ -297,6 +297,9 @@ class Order(LoggedModel):
@property @property
def can_user_cancel(self) -> bool: def can_user_cancel(self) -> bool:
"""
Returns whether or not this order can be canceled by the user.
"""
positions = self.positions.all().select_related('item') positions = self.positions.all().select_related('item')
cancelable = all([op.item.allow_cancel for op in positions]) cancelable = all([op.item.allow_cancel for op in positions])
return self.event.settings.cancel_allow_user and cancelable return self.event.settings.cancel_allow_user and cancelable
@@ -310,6 +313,10 @@ class Order(LoggedModel):
@property @property
def ticket_download_date(self): def ticket_download_date(self):
"""
Returns the first date the tickets for this order can be downloaded or ``None`` if there is no
restriction.
"""
dl_date = self.event.settings.get('ticket_download_date', as_type=RelativeDateWrapper) dl_date = self.event.settings.get('ticket_download_date', as_type=RelativeDateWrapper)
if dl_date: if dl_date:
if self.event.has_subevents: if self.event.has_subevents:
@@ -394,6 +401,22 @@ class Order(LoggedModel):
def send_mail(self, subject: str, template: Union[str, LazyI18nString], def send_mail(self, subject: str, template: Union[str, LazyI18nString],
context: Dict[str, Any]=None, log_entry_type: str='pretix.event.order.email.sent', context: Dict[str, Any]=None, log_entry_type: str='pretix.event.order.email.sent',
user: User=None, headers: dict=None, sender: str=None): user: User=None, headers: dict=None, sender: str=None):
"""
Sends an email to the user that placed this order. Basically, this method does two things:
* Call ``pretix.base.services.mail.mail`` with useful values for the ``event``, ``locale``, ``recipient`` and
``order`` parameters.
* Create a ``LogEntry`` with the email contents.
:param subject: Subject of the email
:param template: LazyI18nString or template filename, see ``pretix.base.services.mail.mail`` for more details
:param context: Dictionary to use for rendering the template
:param log_entry_type: Key to be used for the log entry
:param user: Administrative user who triggered this mail to be sent
:param headers: Dictionary with additional mail headers
:param sender: Custom email sender.
"""
from pretix.base.services.mail import SendMailException, mail, render_mail from pretix.base.services.mail import SendMailException, mail, render_mail
recipient = self.email recipient = self.email