From 69f04beb6d43cc9a668a4fc388b39080cfe1c4d2 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 12 Mar 2018 18:27:50 -0500 Subject: [PATCH] Fix text area behavior for email recipient fields --- tailbone/views/email.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tailbone/views/email.py b/tailbone/views/email.py index 58ef43ed..6e12e972 100644 --- a/tailbone/views/email.py +++ b/tailbone/views/email.py @@ -205,6 +205,28 @@ class ProfilesView(MasterView): return kwargs +class RecipientsType(colander.String): + """ + Custom schema type for email recipients. This is used to present the + recipients as a "list" within the text area, i.e. one recipient per line. + Then the list is collapsed to a comma-delimited string for storage. + """ + + def serialize(self, node, appstruct): + if appstruct is colander.null: + return colander.null + recips = parse_list(appstruct) + return '\n'.join(recips) + + def deserialize(self, node, cstruct): + if cstruct == '' and self.allow_empty: + return '' + if not cstruct: + return colander.null + recips = parse_list(cstruct) + return ', '.join(recips) + + class EmailProfileSchema(colander.MappingSchema): prefix = colander.SchemaNode(colander.String()) @@ -215,11 +237,11 @@ class EmailProfileSchema(colander.MappingSchema): replyto = colander.SchemaNode(colander.String(), missing='') - to = colander.SchemaNode(colander.String()) + to = colander.SchemaNode(RecipientsType()) - cc = colander.SchemaNode(colander.String(), missing='') + cc = colander.SchemaNode(RecipientsType(), missing='') - bcc = colander.SchemaNode(colander.String(), missing='') + bcc = colander.SchemaNode(RecipientsType(), missing='') enabled = colander.SchemaNode(colander.Boolean())