Exemplo n.º 1
0
 def handleSubmit(self, action):
     data, errors = self.extractData()
     if errors:
         self.status = self.formErrorsMessage
         return
     data = self.updateServerSideData(data)
     errors = self.processActions(data)
     if errors:
         return self.setErrorsMessage(errors)
     thanksPageOverride = self.context.thanksPageOverride
     if thanksPageOverride:
         thanksPageOverrideAction = self.context.thanksPageOverrideAction
         thanksPage = get_expression(self.context, thanksPageOverride)
         if thanksPageOverrideAction == 'redirect_to':
             self.request.response.redirect(thanksPage)
         elif thanksPageOverrideAction == 'traverse_to':
             thanksPage = self.context.restrictedTraverse(
                 thanksPage.encode('utf-8'))
             thanksPage = mapply(
                 thanksPage, self.request.args, self.request).encode('utf-8')
             self.request.response.write(thanksPage)
     else:
         self.thanksPage = True
         replacer = DollarVarReplacer(data).sub
         self.thanksPrologue = self.context.thanksPrologue and replacer(
             self.context.thanksPrologue.output)
         self.thanksEpilogue = self.context.thanksEpilogue and replacer(
             self.context.thanksEpilogue.output)
         if not self.context.showAll:
             self.fields = self.setThanksFields(self.base_fields)
             for group in self.groups:
                 group.fields = self.setThanksFields(
                     self.base_groups.get(group.label))
         self.setDisplayMode(DISPLAY_MODE)
         self.updateActions()
Exemplo n.º 2
0
    def get_subject(self, fields, request, context):
        """Return subject
        """
        # get subject header
        nosubject = '(no subject)'
        if hasattr(
                self,
                'subjectOverride') and self.subjectOverride and get_expression(
                    context, self.subjectOverride):
            # subject has a TALES override
            subject = get_expression(context, self.subjectOverride).strip()
        else:
            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 = DollarVarReplacer(fields).sub(subject)

        return subject
Exemplo n.º 3
0
    def get_mail_body(self, fields, request, context):
        """Returns the mail-body with footer.
        """

        schema = get_fields(context)
        all_fields = [
            f for f in fields
            # TODO
            # if not (f.isLabel() or f.isFileField()) and not (getattr(self,
            # 'showAll', True) and f.getServerSide())]
            if not (self._is_file_data(fields[f]))
            and not (getattr(self, 'showAll', True)
                     and IFieldExtender(schema[f]).serverSide)
        ]

        # which fields should we show?
        if getattr(self, 'showAll', True):
            live_fields = all_fields
        else:
            showFields = getattr(self, 'showFields', [])
            if showFields is None:
                showFields = []

            live_fields = [f for f in all_fields if f in showFields]

        if not getattr(self, 'includeEmpties', True):
            all_fields = live_fields
            live_fields = [f for f in all_fields if fields[f]]
            for f in all_fields:
                value = fields[f]
                if value:
                    live_fields.append(f)

        # bare_fields = [schema[f] for f in live_fields]
        bare_fields = OrderedDict([(f, fields[f]) for f in live_fields])
        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
        replacer = DollarVarReplacer(fields).sub
        extra = {
            'data':
            bare_fields,
            'fields':
            OrderedDict([(i, j.title) for i, j in getFieldsInOrder(schema)]),
            'mailer':
            self,
            'body_pre':
            self.body_pre and replacer(self.body_pre),
            'body_post':
            self.body_post and replacer(self.body_post),
            'body_footer':
            self.body_footer and replacer(self.body_footer),
        }
        template = ZopePageTemplate(self.__name__)
        template.write(bodyfield)
        template = template.__of__(context)
        body = template.pt_render(extra_context=extra)

        # if isinstance(body, unicode):
        # body = body.encode("utf-8")

        # keyid = getattr(self, 'gpg_keyid', None)
        # encryption = gpg and keyid

        # if encryption:
        # bodygpg = gpg.encrypt(body, keyid)
        # if bodygpg.strip():
        # body = bodygpg

        return body