class _ModifyForm(BaseModifyForm): """ ModifyForm (the form used on +modify view), sans the content part. Combined dynamically with the ModifyForm of the Content subclass in Contentful.ModifyForm. Subclasses of Contentful should generally override this instead of ModifyForm. """ meta_form = BaseMetaForm extra_meta_text = JSON.using( label=L_("Extra MetaData (JSON)")).with_properties(rows=ROWS_META, cols=COLS) meta_template = 'modify_meta.html' def _load(self, item): """ Load metadata and data from :item into :self. Used by BaseModifyForm.from_item. """ meta = item.prepare_meta_for_modify(item.meta) # Default value of `policy` argument of Flatland.Dict.set's is # 'strict', which causes KeyError to be thrown when meta contains # meta keys that are not present in self['meta_form']. Setting # policy to 'duck' suppresses this behavior. if 'acl' not in meta: meta['acl'] = "None" self['meta_form'].set(meta, policy='duck') for k in self['meta_form'].field_schema_mapping.keys( ) + IMMUTABLE_KEYS: meta.pop(k, None) self['extra_meta_text'].set(item.meta_dict_to_text(meta)) self['content_form']._load(item.content) def _dump(self, item): """ Dump useful data out of :self. :item contains the old item and should not be the primary data source; but it can be useful in case the data in :self is not sufficient. :returns: a tuple (meta, data, contenttype_guessed, comment), suitable as arguments of the same names to pass to item.modify """ # Since the metadata form for tickets is an incomplete one, we load the # original meta and update it with those from the metadata editor # e.g. we get PARENTID in here meta = item.meta_filter(item.prepare_meta_for_modify(item.meta)) meta.update(self['meta_form'].value) meta.update(item.meta_text_to_dict(self['extra_meta_text'].value)) data, contenttype_guessed = self['content_form']._dump( item.content) comment = self['comment'].value return meta, data, contenttype_guessed, comment