def update(self): """ Update form - see interfaces.IForm """ self.formMaybeForceSSL() super(EasyFormForm, self).update() self.template = self.form_template if self.request.method == 'POST' and \ not self.context.thanksPageOverride: data, errors = self.extractData() if errors: return data = self.updateServerSideData(data) self.thanksPage = True self.template = self.thank_you_template if self.context.showFields: self.fields = self.setThanksFields(self.base_fields) for group in self.groups: group.fields = self.setThanksFields( self.base_groups.get(group.label)) self.mode = DISPLAY_MODE # we need to update the widgets in display mode again super(EasyFormForm, self).update() prologue = self.context.thanksPrologue epilogue = self.context.thanksEpilogue self.thanksPrologue = prologue and dollar_replacer( prologue.output, data) self.thanksEpilogue = epilogue and dollar_replacer( epilogue.output, data) alsoProvides(self.request, IEasyFormThanksPage)
def get_mail_body(self, unsorted_data, request, context): """Returns the mail-body with footer. """ schema = get_schema(context) form = DummyFormView(context, request) form.schema = schema form.prefix = 'form' form._update() widgets = {name: widget.render() for name, widget in form.w.items()} data = filter_fields(self, schema, unsorted_data) bodyfield = self.body_pt # pass both the bare_fields (fgFields only) and full fields. # bare_fields for compatability with older templates, # full fields to enable access to htmlValue if isinstance(self.body_pre, basestring): body_pre = self.body_pre else: body_pre = self.body_pre.output if isinstance(self.body_post, basestring): body_post = self.body_post else: body_post = self.body_post.output if isinstance(self.body_footer, basestring): body_footer = self.body_footer else: body_footer = self.body_footer.output extra = { 'data': data, 'fields': OrderedDict([(i, j.title) for i, j in getFieldsInOrder(schema)]), 'widgets': widgets, 'mailer': self, 'body_pre': body_pre and lnbr(dollar_replacer(body_pre, data)), 'body_post': body_post and lnbr(dollar_replacer(body_post, data)), 'body_footer': body_footer and lnbr(dollar_replacer(body_footer, data)), } template = ZopePageTemplate(self.__name__) template.write(bodyfield) template = template.__of__(context) return template.pt_render(extra_context=extra)
def get_mail_body(self, unsorted_data, request, context): """Returns the mail-body with footer. """ schema = get_schema(context) form = DummyFormView(context, request) form.schema = schema form.prefix = "form" form._update() widgets = filter_widgets(self, form.w) data = filter_fields(self, schema, unsorted_data) bodyfield = self.body_pt # pass both the bare_fields (fgFields only) and full fields. # bare_fields for compatability with older templates, # full fields to enable access to htmlValue if isinstance(self.body_pre, six.string_types): body_pre = self.body_pre else: body_pre = self.body_pre.output if isinstance(self.body_post, six.string_types): body_post = self.body_post else: body_post = self.body_post.output if isinstance(self.body_footer, six.string_types): body_footer = self.body_footer else: body_footer = self.body_footer.output extra = { "data": data, "fields": OrderedDict([(i, j.title) for i, j in getFieldsInOrder(schema)]), "widgets": widgets, "mailer": self, "body_pre": body_pre and lnbr(dollar_replacer(body_pre, data)), "body_post": body_post and lnbr(dollar_replacer(body_post, data)), "body_footer": body_footer and lnbr(dollar_replacer(body_footer, data)), } template = ZopePageTemplate(self.__name__) template.write(bodyfield) template = template.__of__(context) return template.pt_render(extra_context=extra)
def get_subject(self, fields, request, context): """Return subject """ # get subject header nosubject = u'(no subject)' # TODO: translate subject = None if hasattr(self, 'subjectOverride') and self.subjectOverride: # subject has a TALES override subject = get_expression(context, self.subjectOverride, fields=fields).strip() if not subject: subject = getattr(self, 'msg_subject', nosubject) subjectField = fields.get(self.subject_field, None) if subjectField is not None: subject = subjectField else: # we only do subject expansion if there's no field chosen subject = dollar_replacer(subject, fields) if isinstance(subject, basestring): subject = safe_unicode(subject) elif subject and isinstance(subject, (set, tuple, list)): subject = ', '.join([safe_unicode(s) for s in subject]) else: subject = nosubject # transform subject into mail header encoded string email_charset = 'utf-8' msgSubject = self.secure_header_line(subject).encode( email_charset, 'replace') msgSubject = str(Header(msgSubject, email_charset)) return msgSubject
def update(self): """ Update form - see interfaces.IForm """ self.formMaybeForceSSL() super(EasyFormForm, self).update() self.template = self.form_template if ( self.request.method != 'POST' or self.context.thanksPageOverride ): # go with all but default thank you page rendering return data, errors = self.extractData() if errors: # render errors return data = self.updateServerSideData(data) self.thanksPage = True self.template = self.thank_you_template self.fields = self.setThanksFields(self.base_fields, data) for name in list(self.widgets.keys()): if name not in self.fields: del self.widgets[name] for group in self.groups: group.fields = self.setThanksFields( self.base_groups.get(group.label), data ) for name in group.widgets: if name not in group.fields: del group.widgets[name] self.widgets.mode = self.mode = DISPLAY_MODE self.widgets.update() prologue = self.context.thanksPrologue epilogue = self.context.thanksEpilogue self.thanksPrologue = ( prologue and dollar_replacer(prologue.output, data) ) self.thanksEpilogue = ( epilogue and dollar_replacer(epilogue.output, data) ) alsoProvides(self.request, IEasyFormThanksPage)
def update(self): """Update form - see interfaces.IForm """ self.formMaybeForceSSL() super(EasyFormForm, self).update() self.template = self.form_template if self.request.method != "POST" or self.context.thanksPageOverride: # go with all but default thank you page rendering return # If an adapter has already set errors, don't re-run extraction and # validation, just bail out: # (we copy the logic from plone.app.z3cform at templates/macros.pt) if self.widgets.errors or self.status == getattr(self, 'formErrorsMessage', None): return data, errors = self.extractData() if errors: # render errors return data = self.updateServerSideData(data) self.thanksPage = True self.template = self.thank_you_template self.fields = self.setThanksFields(self.base_fields, data) for name in list(self.widgets.keys()): if name not in self.fields: del self.widgets[name] self.widgets.mode = self.mode = DISPLAY_MODE self.widgets.update() for group in self.groups: group.fields = self.setThanksFields(self.base_groups.get(group.label), data) for name in list(group.widgets.keys()): if name not in group.fields: del group.widgets[name] group.widgets.mode = DISPLAY_MODE group.widgets.update() prologue = self.context.thanksPrologue epilogue = self.context.thanksEpilogue self.thanksPrologue = prologue and dollar_replacer(prologue.output, data) self.thanksEpilogue = epilogue and dollar_replacer(epilogue.output, data) alsoProvides(self.request, IEasyFormThanksPage)
def get_subject(self, fields, request, context): """Return subject """ # get subject header nosubject = u'(no subject)' # TODO: translate subject = None if hasattr(self, 'subjectOverride') and self.subjectOverride: # subject has a TALES override subject = get_expression( context, self.subjectOverride, fields=fields ).strip() if not subject: subject = getattr(self, 'msg_subject', nosubject) subjectField = fields.get(self.subject_field, None) if subjectField is not None: subject = subjectField else: # we only do subject expansion if there's no field chosen subject = dollar_replacer(subject, fields) if isinstance(subject, basestring): subject = safe_unicode(subject) elif subject and isinstance(subject, (set, tuple, list)): subject = ', '.join([safe_unicode(s) for s in subject]) else: subject = nosubject # transform subject into mail header encoded string email_charset = 'utf-8' msgSubject = self.secure_header_line( subject).encode(email_charset, 'replace') msgSubject = str(Header(msgSubject, email_charset)) return msgSubject
def get_mail_body(self, unsorted_data, request, context): """Returns the mail-body with footer. """ schema = get_schema(context) form = DummyFormView(context, request) form.schema = schema form.prefix = 'form' form._update() widgets = {name: widget.render() for name, widget in form.w.items()} data = OrderedDict( [x for x in getFieldsInOrder(schema) if x[0] in unsorted_data] ) data.update(unsorted_data) all_data = [ f for f in data # TODO # if not (f.isLabel() or f.isFileField()) and not (getattr(self, # 'showAll', True) and f.getServerSide())] if not (self._is_file_data(data[f])) and not ( getattr(self, 'showAll', True) and IFieldExtender(schema[f]).serverSide ) ] # which data should we show? if getattr(self, 'showAll', True): live_data = all_data else: showFields = getattr(self, 'showFields', []) if showFields is None: showFields = [] live_data = [ f for f in all_data if f in showFields] if not getattr(self, 'includeEmpties', True): all_data = live_data live_data = [f for f in all_data if data[f]] for f in all_data: value = data[f] if value: live_data.append(f) bare_data = OrderedDict([(f, data[f]) for f in live_data]) bodyfield = self.body_pt # pass both the bare_fields (fgFields only) and full fields. # bare_fields for compatability with older templates, # full fields to enable access to htmlValue if isinstance(self.body_pre, basestring): body_pre = self.body_pre else: body_pre = self.body_pre.output if isinstance(self.body_post, basestring): body_post = self.body_post else: body_post = self.body_post.output if isinstance(self.body_footer, basestring): body_footer = self.body_footer else: body_footer = self.body_footer.output extra = { 'data': bare_data, 'fields': OrderedDict([ (i, j.title) for i, j in getFieldsInOrder(schema) ]), 'widgets': widgets, 'mailer': self, 'body_pre': body_pre and lnbr(dollar_replacer(body_pre, data)), 'body_post': body_post and lnbr(dollar_replacer(body_post, data)), 'body_footer': body_footer and lnbr( dollar_replacer(body_footer, data)), } template = ZopePageTemplate(self.__name__) template.write(bodyfield) template = template.__of__(context) return template.pt_render(extra_context=extra)