Joe Bigler
Joe Bigler

Reputation: 179

Is there any way to attach the current data (as a .csv file) in PloneFormGen to a mailer?

We use PloneFormGen 1.7.12 using Plone 4.3.3. I have a request to include the current data in the email that the form is sending. We normally give editors access to the data to download, but the people he wants to send these to are not editors and I don't want to give them editor's permissions.

If it can't be added to the mailer, I guess I could create a role and give it just enough permissions for an authenticated user to download data. Would it work to copy the authenticated permissions over to a new role and add the PloneFormGen: Download Saved Input permission as well? I really don't like creating extra roles. In addition we would need to set up accounts for these people.

Upvotes: 4

Views: 220

Answers (2)

Ida
Ida

Reputation: 3965

Not really sure about your requirements, but in case you want to send the single-record in CSV-format as a mail when a form is submitted, you can customize the template of the mailer-adapter, like this:

    <tal:block repeat="field options/wrappedFields | nothing">
        "<span tal:replace="structure python:field.htmlValue(request)" />",
    </tal:block>

Note, that this only works, if the mail's format is HTML, in plain text tal:repeat comes in the way, adding linebreaks between the values.

If you want to give a group of users permissions to view and download a save-adapter, go to PFG's controlpanel (append /prefs_pfg_permits to the site's URL), where it says "Download Saved Input" check the box for "Reader", then assign "Can edit"-permissioins via the sharing-tab of your save-adapter to the users and groups you want to be privileged.

Upvotes: 0

Mathias
Mathias

Reputation: 6839

AFAIK not without coding :-)

  1. Create a new DataSaveAdapter content type

    Best way ist to inherit from the existing one and add a new field:

from Products.PloneFormGen.content.saveDataAdapter import FormSaveDataAdapter


SendDataAdapterSchema = FormSaveDataAdapter.schema.copy() + atapi.Schema((
    atapi.StringField(
        name='csv_recipients',
        required=False,
        widget=atapi.LinesWidget(
            label=_(u'label_csv_recipients', default=u'CSV recipients'),
        )
    )
))

class SendDataAdapter(FormSaveDataAdapter):
    implements(IPloneFormGenActionAdapter)
    ...
    schema = SendDataAdapterSchema
    ...
  1. The SaveDataAdapter provides a onSuccess method, where you can hook in and send your email
class SendDataAdapter(FormSaveDataAdapter):
...

    def onSuccess(self, fields, REQUEST=None, loopstop=False):
        """ saves input data and initiates mail"""
        super(SendDataAdapter, self).onSuccess(fields, REQUEST, loopstop)
        self.send_csv()  # This is where you may implement sending the email.

Of course it needs some work to get it done (registering content type, etc.), but this should point you in the right direction.

Upvotes: 2

Related Questions