Skip to content

Commit

Permalink
Merge 2465c48 into 83e02a8
Browse files Browse the repository at this point in the history
  • Loading branch information
jean committed Jul 26, 2013
2 parents 83e02a8 + 2465c48 commit ffb4541
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
5 changes: 4 additions & 1 deletion Products/CMFPlomino/fields/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def getFieldValue(self, form, doc=None, editmode_obsolete=False,
fieldValue = doc.getItem(fieldName)

elif mode in ["DISPLAY", "COMPUTED"]:
fieldValue = form.computeFieldValue(fieldName, target)
if mode == "DISPLAY" and not self.context.Formula():
fieldValue = doc.getItem(fieldName)
else:
fieldValue = form.computeFieldValue(fieldName, target)

elif mode == "CREATION":
if creation:
Expand Down
47 changes: 38 additions & 9 deletions Products/CMFPlomino/tests/plomino.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,41 @@ A form can contain editable fields and also computed fields::
... title='Title for field2',
... FieldType="TEXT",
... FieldMode="COMPUTED",
... Formula="'My favorite song is '+plominoDocument.field1")
... Formula="plominoDocument.setItem('field4', 'side-effect')\nreturn 'My favorite song is '+plominoDocument.field1")

A form can contain display fields. A display field is computed but the
result is not saved on the document::

>>> id = db.frm1.invokeFactory('PlominoField',
... id='field3',
... title='Title for field3',
... FieldType="TEXT",
... FieldMode="DISPLAY",
... Formula="return plominoDocument.field1.upper()")
>>> db.frm1.field2.at_post_create_script()

If a display field does not specify a formula, it will display the item with
the id corresponding to the field name (if any). Here's a field without
formula, the item value was set by the formula for ``field2``::

>>> id = db.frm1.invokeFactory('PlominoField',
... id='field4',
... title='Title for field4',
... FieldType="TEXT",
... FieldMode="DISPLAY",
... Formula="")
>>> db.frm1.field2.at_post_create_script()

Let's set a layout which contains our fields::

>>> db.frm1.setFormLayout("""2 <p>please enter a value for field1:
... <span class="plominoLabelClass">field1</span>
... <span class="plominoFieldClass">field1</span></p><p>Comment:
... <span class="plominoLabelClass">field2: Label for field2</span>
... <span class="plominoFieldClass">field2</span></p>""")
... <span class="plominoFieldClass">field2</span></p><p>
... <span class="plominoFieldClass">field3</span></p><p>
... <span class="plominoFieldClass">field4</span></p>""")


Documents
---------------
Expand Down Expand Up @@ -143,9 +171,9 @@ Only items which match a form field will be considered::

>>> doc1.setItem('field1', 'where is my mind?')
>>> db.frm1.displayDocument(doc1, editmode=False)
u'2 <p>please enter a value for field1:<span>\n \n \n where is my mind?\n \n</span>\n</p><p>Comment:<span>\n \n \n My favorite song is where is my mind?\n \n</span>\n</p>'
u'2 <p>please enter a value for field1:<span>\n \n \n where is my mind?\n \n</span>\n</p><p>Comment:<span>\n \n \n My favorite song is where is my mind?\n \n</span>\n</p><p><span>\n \n \n WHERE IS MY MIND?\n \n</span>\n</p><p><span>\n \n \n side-effect\n \n</span>\n</p>'
>>> db.frm1.displayDocument(doc1, editmode=True)
u'<input type=\'hidden\' name=\'Form\' value=\'frm1\' />2 <p>please enter a value for field1:<label for=\'field1\'>Title for field1</label><span>\n \n \n <input type="text" name="field1" value="where is my mind?" />\n \n \n</span>\n</p><p>Comment:<label for=\'field2\'>Label for field2</label><span>\n \n \n My favorite song is where is my mind?\n \n</span>\n</p>'
u'<input type=\'hidden\' name=\'Form\' value=\'frm1\' />2 <p>please enter a value for field1:<label for=\'field1\'>Title for field1</label><span>\n \n \n <input type="text" name="field1" value="where is my mind?" />\n \n \n</span>\n</p><p>Comment:<label for=\'field2\'>Label for field2</label><span>\n \n \n My favorite song is where is my mind?\n \n</span>\n</p><p><span>\n \n \n WHERE IS MY MIND?\n \n</span>\n</p><p><span>\n \n \n side-effect\n \n</span>\n</p>'

``Form`` is a reserved item which allows to indicate the document default
form::
Expand Down Expand Up @@ -253,22 +281,23 @@ Views can be exported as CSV:

JSON API
--------
A document can be exported as JSON:

A document can be exported as JSON::

>>> doc11.tojson()
'{"field2": "My favorite song is Rhythm is love", "field1": "Rhythm is love", "Plomino_Authors": ["test-user"], "Form": "frm1"}'
'{"field2": "My favorite song is Rhythm is love", "Plomino_Authors": ["test-user"], "field1": "Rhythm is love", "field4": "side-effect", "Form": "frm1"}'

We can export only one field:
We can export only one field::

>>> doc11.tojson(item="field2")
'"My favorite song is Rhythm is love"'

We can get the lastmodified value:
We can get the ``lastmodified`` value::

>>> doc11.tojson(item="field2", lastmodified=True)
'{"lastmodified": {"datetime": "...", "__datetime__": true}, "data": "My favorite song is Rhythm is love"}'

Views can be exported as JSON:
Views can be exported as JSON::

>>> db.view1.tojson()
'{"aaData": [["...", "London calling"], ["a-document-about-rhythm-is-love", "Rhythm is love"], ["a-document-about-rhythm-is-love-1", "Rhythm is love"], ["...", "bonjour"], ["...", "hello"]], "iTotalRecords": 5, "iTotalDisplayRecords": 5}'
Expand Down

0 comments on commit ffb4541

Please sign in to comment.