def filter_fields(data, schema, subscriber_fields):
    data = OrderedDict([(x[0], data[x[0]])
                        for x in getFieldsInOrder(schema) if x[0] in data], )
    fields = [f for f in data if not (is_file_data(data[f]))]
    # remove standard fields (in subscriber schema)
    fields = [f for f in fields if f not in subscriber_fields]
    # remove empties
    fields = [f for f in fields if data[f]]
    ret = OrderedDict([(f, data[f]) for f in fields])
    return ret
Example #2
0
 def onSuccess(self, fields, request):
     """
     saves data  in Postgresdb.
     """
     data = OrderedDict()
     columns = self.getColumns()
     for tup in columns:
         if tup[1] in ('Float', 'Decimal') and self.decimal_separator:
             # treat both '.' and ',' as decimal separator
             # overriding form widget behaviour, convenient for forms on mobile!
             val = request.form['form.widgets.{}'.format(tup[0])].replace(
                 ',', '.'
             )
             if val == u'':
                 val = None
             else:
                 val = float(val)
         else:
             val = fields[tup[0]]
         data[tup[0]] = (val, tup[1])
     if self.ExtraData:
         for f in self.ExtraData:
             if f == 'dt':
                 data[f] = (str(DateTime()), 'Datetime')
             else:
                 data[f] = (getattr(request, f, ''), 'Text')
     context = get_context(self)
     ret = self.InsertDB(context, data)
Example #3
0
    def get_header_info(self,
                        fields,
                        request,
                        context,
                        from_addr=None,
                        to_addr=None,
                        subject=None):
        """Return header info.

        header info is a dictionary

        Keyword arguments:
        request -- (optional) alternate request object to use
        """
        (to, from_addr, reply) = self.get_addresses(fields, request, context)

        headerinfo = OrderedDict()
        headerinfo["To"] = self.secure_header_line(to)
        headerinfo["From"] = self.secure_header_line(from_addr)
        if reply:
            headerinfo["Reply-To"] = self.secure_header_line(reply)
        headerinfo["Subject"] = self.get_subject(fields, request, context)

        # CC
        if isinstance(self.cc_recipients, six.string_types):
            cc_recips = self.cc_recipients
        else:
            cc_recips = [_f for _f in self.cc_recipients if _f]
        if hasattr(self, "ccOverride") and self.ccOverride:
            _cc = get_expression(context, self.ccOverride, fields=fields)
            if _cc:
                cc_recips = _cc

        if cc_recips:
            headerinfo["Cc"] = format_addresses(cc_recips)

        # BCC
        if isinstance(self.bcc_recipients, six.string_types):
            bcc_recips = self.bcc_recipients
        else:
            bcc_recips = [_f for _f in self.bcc_recipients if _f]
        if hasattr(self, "bccOverride") and self.bccOverride:
            _bcc = get_expression(context, self.bccOverride, fields=fields)
            if _bcc:
                bcc_recips = _bcc

        if bcc_recips:
            headerinfo["Bcc"] = format_addresses(bcc_recips)

        for key in getattr(self, "xinfo_headers", []):
            headerinfo["X-{0}".format(key)] = self.secure_header_line(
                request.get(key, "MISSING"))

        return headerinfo
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
    def get_header_info(self,
                        fields,
                        request,
                        context,
                        from_addr=None,
                        to_addr=None,
                        subject=None):
        """Return header info

        header info is a dictionary

        Keyword arguments:
        request -- (optional) alternate request object to use
        """
        (to, from_addr, reply) = self.get_addresses(fields, request, context)

        headerinfo = OrderedDict()
        headerinfo['To'] = self.secure_header_line(to)
        headerinfo['From'] = self.secure_header_line(from_addr)
        if reply:
            headerinfo['Reply-To'] = self.secure_header_line(reply)
        headerinfo['Subject'] = self.get_subject(fields, request, context)

        # CC
        cc_recips = filter(None, self.cc_recipients)
        if hasattr(self, 'ccOverride') and self.ccOverride:
            _cc = get_expression(context, self.ccOverride, fields=fields)
            if _cc:
                cc_recips = _cc

        if cc_recips:
            headerinfo['Cc'] = format_addresses(cc_recips)

        # BCC
        bcc_recips = filter(None, self.bcc_recipients)
        if hasattr(self, 'bccOverride') and self.bccOverride:
            _bcc = get_expression(context, self.bccOverride, fields=fields)
            if _bcc:
                bcc_recips = _bcc

        if bcc_recips:
            headerinfo['Bcc'] = format_addresses(bcc_recips)

        for key in getattr(self, 'xinfo_headers', []):
            headerinfo['X-{0}'.format(key)] = self.secure_header_line(
                request.get(key, 'MISSING'))

        return headerinfo
    def add_subscriber_in_period(self, context, period, subscriber, form,
                                 data):
        request = self.request
        subscriber.first_name = data.get("first_name")
        subscriber.last_name = data.get("last_name")
        subscriber.email = data.get("email")
        subscriber.number_of_people = int(data.get("number_of_people"))
        subscriber.reindexObject()
        period.reindexObject()

        mailer = get_actions(context).get("mailer")
        if not mailer:
            return

        extra_form = DummyFormView(context, request)
        extra_form.schema = form.schema
        extra_form.prefix = "form"
        extra_form._update()
        subscriber_fields = [x[0] for x in getFieldsInOrder(ISubscriber)]
        subscriber_fields.append("period")

        widgets = filter_widgets(extra_form.widgets, subscriber_fields)
        data = filter_fields(data, extra_form.schema, subscriber_fields)
        bodyfield = mailer.body_pt

        extra = {
            "data":
            data,
            "fields":
            OrderedDict([(i, j.title)
                         for i, j in getFieldsInOrder(extra_form.schema)], ),
            "widgets":
            widgets,
            "mailer":
            mailer,
            "body_pre":
            "",
            "body_post":
            "",
            "body_footer":
            "",
        }
        template = ZopePageTemplate(mailer.__name__)
        template.write(bodyfield)
        template = template.__of__(context)
        subscriber.all_informations = RichTextValue(
            template.pt_render(extra_context=extra), )
        subscriber.reindexObject()