Fix for find_markdown_fields project hook

Original commit 3b59d3ee9aacae517b06bf25346efa3f2dae0fe7
Breaking commit 32e25ce129612010a4c14dfee0d21d1a93666108

The breaking commit was actually meant to remove the need for this
hook logic entirely, by relying on a custom validator instead.
This works for nodes, but it currently does not work for projects.
The issue needs to be further investigated via T63006.
This commit is contained in:
Francesco Siddi 2019-03-27 12:11:57 +01:00
parent 9c1e345252
commit 1525ceafd5

View File

@ -253,26 +253,30 @@ def parse_markdown(project, original=None):
schema = current_app.config['DOMAIN']['projects']['schema'] schema = current_app.config['DOMAIN']['projects']['schema']
def find_markdown_fields(schema, project): def find_markdown_fields(schema, project):
"""Find and process all makrdown validated fields.""" """Find and process all Markdown coerced fields.
for k, v in schema.items():
if not isinstance(v, dict): - look for fields with a 'coerce': 'markdown' property
- parse the name of the field and generate the sibling field name (_<field_name>_html -> <field_name>)
- parse the content of the <field_name> field as markdown and save it in _<field_name>_html
"""
for field_name, field_value in schema.items():
if not isinstance(field_value, dict):
continue
if field_value.get('coerce') != 'markdown':
continue
if field_name not in project:
continue continue
if v.get('validator') == 'markdown': # Construct markdown source field name (strip the leading '_' and the trailing '_html')
# If there is a match with the validator: markdown pair, assign the sibling source_field_name = field_name[1:-5]
# property (following the naming convention _<property>_html) html = pillar.markdown.markdown(project[source_field_name])
# the processed value. project[field_name] = html
if k in project:
html = pillar.markdown.markdown(project[k]) if isinstance(project, dict) and field_name in project:
field_name = pillar.markdown.cache_field_name(k) find_markdown_fields(field_value, project[field_name])
project[field_name] = html
if isinstance(project, dict) and k in project:
find_markdown_fields(v, project[k])
find_markdown_fields(schema, project) find_markdown_fields(schema, project)
return 'ok'
def parse_markdowns(items): def parse_markdowns(items):
for item in items: for item in items: