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 (INamedFile.providedBy(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:
            live_fields = [
                f for f in all_fields if f in getattr(self, '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 = dict([(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': dict([(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
Exemple #2
0
def installTemplateInZodb(folder, template):
    obj = ZopePageTemplate(template.getId(), template._text,
                           template.content_type)
    obj.expand = 0
    obj.write(template.read())
    id = obj.getId()
    folder._setObject(id, obj)
    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 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()
    def get_mail_body(self, unsorted_data, request, context):
        """Returns the mail-body with footer.
        """

        schema = get_schema(context)
        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
        replacer = DollarVarReplacer(data).sub
        extra = {
            'data': bare_data,
            '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
Exemple #7
0
 def _createZODBClone(self):
     """Create a ZODB (editable) equivalent of this object."""
     obj = ZopePageTemplate(self.getId(), self._text, self.content_type)
     obj.expand = 0
     obj.write(self.read())
     return obj
Exemple #8
0
 def getDefault(self, instance):
     value = ObjectField.getDefault(self, instance)
     zpt = ZopePageTemplate(self.getName())
     zpt.write(value)
     return zpt.__of__(instance)
Exemple #9
0
 def set(self, instance, value, **kwargs):
     if not isinstance(value, ZopePageTemplate):
         zpt = ZopePageTemplate(self.getName())
         zpt.write(value)
         value = zpt
     ObjectField.set(self, instance, value, **kwargs)
Exemple #10
0
 def _createZODBClone(self):
     """Create a ZODB (editable) equivalent of this object."""
     obj = ZopePageTemplate(self.getId(), self._text, self.content_type)
     obj.expand = 0
     obj.write(self.read())
     return obj
Exemple #11
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
Exemple #12
0
 def renderFeedbacktext(self):
     pt = ZopePageTemplate(self.id+'_tmp')
     pt.write(self.feedbacktext)
     return pt.__of__(self)()
Exemple #13
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 = 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)
def installTemplateInZodb(folder, template):
    obj = ZopePageTemplate(template.getId(), template._text, template.content_type)
    obj.expand = 0
    obj.write(template.read())
    id = obj.getId()
    folder._setObject(id, obj)