Skip to content

Commit

Permalink
Merge pull request #30 from plone/datakurre/fix-primary-field-from-query
Browse files Browse the repository at this point in the history
Fix issue where it was not possibly to POST a query string value for a primary field
  • Loading branch information
jensens committed Apr 18, 2019
2 parents a997241 + f5a1a91 commit a82d390
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions news/30.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed issue where creating a Mosaic page with shared content layout with filled rich text fields ended up having empty rich text fields, because the rich text field is marked primary (as it should be), and primary fields were never parsed from query string by default.
12 changes: 9 additions & 3 deletions plone/tiles/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def get_default_request_data(self):
# Try to decode the form data properly if we can
try:
data = decode(self.tile.request.form,
self.tileType.schema, missing=True)
self.tileType.schema,
missing=True, primary=True)
except (ValueError, UnicodeDecodeError,):
LOGGER.exception(u'Could not convert form data to schema')
return self.data.copy()
Expand Down Expand Up @@ -342,7 +343,7 @@ def encode(data, schema, ignore=()):

# Decoding

def decode(data, schema, missing=True):
def decode(data, schema, missing=True, primary=False):
"""Decode a data dict according to a schema. The returned dictionary will
contain only keys matching schema names, and will force type values
appropriately.
Expand All @@ -353,12 +354,17 @@ def decode(data, schema, missing=True):
If missing is True, fields that are in the schema but not in the data will
be set to field.missing_value. Otherwise, they are ignored.
If primary is True, also fields that are marged as primary fields are
decoded from the data. (Primary fields are not decoded by default,
because primary field are mainly used for rich text or binary fields
and data is usually parsed from query string with length limitations.)
"""

decoded = {}

for name, field in getFields(schema).items():
if HAS_RFC822 and IPrimaryField.providedBy(field):
if not primary and HAS_RFC822 and IPrimaryField.providedBy(field):
continue

if name not in data:
Expand Down

0 comments on commit a82d390

Please sign in to comment.