Add new ProblemReportEmail
base class, for simpler email previews
just so some of the template context can be provided automatically. although, this *is* a bit heavy currently - should let caller pass in email handler etc.
This commit is contained in:
parent
736bab2c7d
commit
4c78223eb9
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2019 Lance Edgar
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -36,6 +36,37 @@ from rattail.mail import Email
|
|||
from rattail.util import load_object
|
||||
from rattail.core import Object
|
||||
from rattail.time import make_utc, localtime
|
||||
from rattail.problems import ProblemReport, get_problem_report_handler
|
||||
|
||||
|
||||
class ProblemReportEmail(Email):
|
||||
"""
|
||||
Base class for all "problem report" emails
|
||||
"""
|
||||
abstract = True
|
||||
|
||||
def obtain_sample_data(self, request):
|
||||
data = self.sample_data(request)
|
||||
handler = get_problem_report_handler(self.config)
|
||||
|
||||
if 'report' not in data:
|
||||
reports = handler.get_all_problem_reports()
|
||||
email_key = self.__class__.__name__
|
||||
for report in reports:
|
||||
if report.email_key == email_key:
|
||||
data['report'] = report(self.config)
|
||||
break
|
||||
|
||||
if 'report' not in data:
|
||||
report = ProblemReport(self.config)
|
||||
report.problem_title = "Generic Title (problem report not found)"
|
||||
data['report'] = report
|
||||
|
||||
if 'system_title' not in data:
|
||||
system_key = data['report'].system_key or 'rattail'
|
||||
data['system_title'] = handler.get_system_title(system_key)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class datasync_error_watcher_get_changes(Email):
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2018 Lance Edgar
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -309,7 +309,22 @@ class Email(object):
|
|||
templates = [resource_path(p) for p in templates]
|
||||
self.templates = TemplateLookup(directories=templates)
|
||||
|
||||
def obtain_sample_data(self, request):
|
||||
"""
|
||||
This method is responsible for obtaining the full set of sample data,
|
||||
to be used as context when generating a preview for the email.
|
||||
|
||||
Note, you normally should not override this method! Please see also
|
||||
the :meth:`sample_data()` method.
|
||||
"""
|
||||
return self.sample_data(request)
|
||||
|
||||
def sample_data(self, request):
|
||||
"""
|
||||
This method can return a dict of sample data, to be used as context
|
||||
when generating a preview for the email. Subclasses are welcome to
|
||||
override this method.
|
||||
"""
|
||||
return {}
|
||||
|
||||
def get_enabled(self):
|
||||
|
|
Loading…
Reference in a new issue