Expose mail handler and template paths in email config page

This commit is contained in:
Lance Edgar 2023-06-02 14:14:33 -05:00
parent e1685231c2
commit 93b03c9562
2 changed files with 38 additions and 8 deletions

View file

@ -3,6 +3,24 @@
<%def name="form_content()"> <%def name="form_content()">
<h3 class="block is-size-3">General</h3>
<div class="block" style="padding-left: 2rem;">
<b-field label="Mail Handler"
message="Leave blank for default handler.">
<b-input name="rattail.mail.handler"
v-model="simpleSettings['rattail.mail.handler']"
@input="settingsNeedSaved = true">
</b-input>
</b-field>
<b-field label="Template Paths"
message="Leave blank for default paths.">
<b-input name="rattail.mail.templates"
v-model="simpleSettings['rattail.mail.templates']"
@input="settingsNeedSaved = true">
</b-input>
</b-field>
</div>
<h3 class="block is-size-3">Sending</h3> <h3 class="block is-size-3">Sending</h3>
<div class="block" style="padding-left: 2rem;"> <div class="block" style="padding-left: 2rem;">

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,13 +24,9 @@
Email Views Email Views
""" """
from __future__ import unicode_literals, absolute_import
import re import re
import warnings import warnings
import six
from rattail import mail from rattail import mail
from rattail.db import model from rattail.db import model
from rattail.config import parse_list from rattail.config import parse_list
@ -105,7 +101,7 @@ class EmailSettingView(MasterView):
emails = self.email_handler.get_all_emails() emails = self.email_handler.get_all_emails()
else: else:
emails = self.email_handler.get_available_emails() emails = self.email_handler.get_available_emails()
for key, Email in six.iteritems(emails): for key, Email in emails.items():
email = Email(self.rattail_config, key) email = Email(self.rattail_config, key)
data.append(self.normalize(email)) data.append(self.normalize(email))
return data return data
@ -266,9 +262,9 @@ class EmailSettingView(MasterView):
app.save_setting(session, 'rattail.mail.{}.to'.format(key), (data['to'] or '').replace('\n', ', ')) app.save_setting(session, 'rattail.mail.{}.to'.format(key), (data['to'] or '').replace('\n', ', '))
app.save_setting(session, 'rattail.mail.{}.cc'.format(key), (data['cc'] or '').replace('\n', ', ')) app.save_setting(session, 'rattail.mail.{}.cc'.format(key), (data['cc'] or '').replace('\n', ', '))
app.save_setting(session, 'rattail.mail.{}.bcc'.format(key), (data['bcc'] or '').replace('\n', ', ')) app.save_setting(session, 'rattail.mail.{}.bcc'.format(key), (data['bcc'] or '').replace('\n', ', '))
app.save_setting(session, 'rattail.mail.{}.enabled'.format(key), six.text_type(data['enabled']).lower()) app.save_setting(session, 'rattail.mail.{}.enabled'.format(key), str(data['enabled']).lower())
if self.has_perm('configure'): if self.has_perm('configure'):
app.save_setting(session, 'rattail.mail.{}.hidden'.format(key), six.text_type(data['hidden']).lower()) app.save_setting(session, 'rattail.mail.{}.hidden'.format(key), str(data['hidden']).lower())
return data return data
def template_kwargs_view(self, **kwargs): def template_kwargs_view(self, **kwargs):
@ -280,6 +276,12 @@ class EmailSettingView(MasterView):
config = self.rattail_config config = self.rattail_config
return [ return [
# general
{'section': 'rattail.mail',
'option': 'handler'},
{'section': 'rattail.mail',
'option': 'templates'},
# sending # sending
{'section': 'rattail.mail', {'section': 'rattail.mail',
'option': 'record_attempts', 'option': 'record_attempts',
@ -289,6 +291,16 @@ class EmailSettingView(MasterView):
'type': bool}, 'type': bool},
] ]
def configure_get_context(self, *args, **kwargs):
context = super().configure_get_context(*args, **kwargs)
# prettify list of template paths
templates = self.rattail_config.parse_list(
context['simple_settings']['rattail.mail.templates'])
context['simple_settings']['rattail.mail.templates'] = ', '.join(templates)
return context
def toggle_hidden(self): def toggle_hidden(self):
app = self.get_rattail_app() app = self.get_rattail_app()
data = self.request.json_body data = self.request.json_body