Creating Events Using the Plone Form

I am trying to create an event content type using the Plone form generator. I used this tutorial to do this.

When creating an event content type using the Add New ... menu, you are given two fields to fill in: start and end dates, I would like my form to extract information from these fields and apply it to the type of event content that I use for it creation.

My problem, as I understand it, is described below:

The custom script adapter script contains the following:

obj.setDescription(form['replyto']) 

I see that it gets content to describe the type of event content from the following:

 <input id="replyto" class="" type="text" size="30" name="replyto" /> 

When adding a PFG to the form, the date / time field consists of several <select> inputs, and not just one, as indicated above, I think this means that there is no simple obj.setEndDate() command for this. Although I canโ€™t refer to the boxes of choice, Iโ€™m kind of stuck.

Does anyone know if it is possible to create an event content type and specify a start and end date using Plone Form Gen?

Edit

Using this link I had a problem with the original, but I had problems

I adapted my script (using the link above) to look like this:

 target = context.viewjobs form = request.form from DateTime import DateTime uid = str(DateTime().millis()) loc = form['location-of-event'] target.invokeFactory("Event", id=uid, title=form['topic'], event_url=loc) obj = target[uid] obj.setFormat('text/plain') obj.setText(form['comments']) obj.setDescription(form['replyto']) obj.reindexObject() 

(I used event_url only for verification, as I had no luck with the event_start option).

It fires the event in order, but when I go to view the event I receive:

  Module zope.tales.expressions, line 217, in __call__ Module Products.PageTemplates.Expressions, line 147, in _eval Module zope.tales.expressions, line 124, in _eval Module Products.PageTemplates.Expressions, line 74, in boboAwareZopeTraverse Module OFS.Traversable, line 317, in restrictedTraverse Module OFS.Traversable, line 285, in unrestrictedTraverse __traceback_info__: ([], 'location') 

AttributeError: location

I did not mention the location anywhere in my script, and when I do this, I get the same error.

Any thoughts would be appreciated.

+6
source share
2 answers

You can simplify your code and avoid calling again by doing something like this:

 target = context.viewjobs form = request.form from DateTime import DateTime uid = str(DateTime().millis()) target.invokeFactory( "Event", id=uid, title=form['job-title'], description=form['description-1'], text=form['comments'], location=form['location-of-event'], startDate=form['start-date'], endDate=form['end-date-due-by'] ) 

Regarding the collection of start and end dates. If you use the Date / Time widget and look at the generated HTML code, you will see that there is a hidden input field whose name corresponds to the short name of the widget. This hidden input contains a full textual representation of what was selected by the various select boxes, which gives you the wish that you would achieve using the text box, but without having to rely on the user to use a particular format.

If you're wondering how to find the names of the various fields to indicate in the invokeFactory call, find the python file that defines the type of content you are trying to create. In the case of an event object, this is / Plone / buildout -cache / eggs / Products.ATContentTypes-2.1.8-py2.7.egg / Products / ATContentTypes / content / event.py

Line 32 starts "ATEventSchema = ..." and from there you will see the field names for all parts of the event.

+5
source

I managed to resolve this using a text field and asking users to enter a date in this format: 2013-12-12, then I used obj.setStartDate(form['name-of-field']) and obj.setEndDate(form['name-of-field']) to set this event.

To get around the location trace, I used obj.setLocation() and removed the location string from the call method shown in the script above.

Script for anyone interested:

 target = context.viewjobs form = request.form from DateTime import DateTime uid = str(DateTime().millis()) target.invokeFactory("Event", id=uid, title=form['job-title']) obj = target[uid] obj.setFormat('text/plain') obj.setText(form['comments']) obj.setDescription(form['description-1']) obj.setLocation(form['location-of-event']) obj.setStartDate(form['start-date']) obj.setEndDate(form['end-date-due-by']) obj.reindexObject() 
+1
source

All Articles