Projects Bug: Projects page not showing project description
Cache field _description_html was never updated when a project was inserted/updated. Added a eve hook similar to how this cache works with Nodes.
This commit is contained in:
@@ -9,6 +9,7 @@ def setup_app(app, api_prefix):
|
||||
app.on_replace_projects += hooks.override_is_private_field
|
||||
app.on_replace_projects += hooks.before_edit_check_permissions
|
||||
app.on_replace_projects += hooks.protect_sensitive_fields
|
||||
app.on_replace_projects += hooks.parse_markdown
|
||||
|
||||
app.on_update_projects += hooks.override_is_private_field
|
||||
app.on_update_projects += hooks.before_edit_check_permissions
|
||||
@@ -19,6 +20,8 @@ def setup_app(app, api_prefix):
|
||||
|
||||
app.on_insert_projects += hooks.before_inserting_override_is_private_field
|
||||
app.on_insert_projects += hooks.before_inserting_projects
|
||||
app.on_insert_projects += hooks.parse_markdowns
|
||||
|
||||
app.on_inserted_projects += hooks.after_inserting_projects
|
||||
|
||||
app.on_fetched_item_projects += hooks.before_returning_project_permissions
|
||||
|
@@ -3,6 +3,7 @@ import logging
|
||||
|
||||
from flask import request, abort
|
||||
|
||||
import pillar
|
||||
from pillar import current_app
|
||||
from pillar.api.node_types.asset import node_type_asset
|
||||
from pillar.api.node_types.comment import node_type_comment
|
||||
@@ -246,3 +247,33 @@ def project_node_type_has_method(response):
|
||||
def projects_node_type_has_method(response):
|
||||
for project in response['_items']:
|
||||
project_node_type_has_method(project)
|
||||
|
||||
|
||||
def parse_markdown(project, original=None):
|
||||
schema = current_app.config['DOMAIN']['projects']['schema']
|
||||
|
||||
def find_markdown_fields(schema, project):
|
||||
"""Find and process all makrdown validated fields."""
|
||||
for k, v in schema.items():
|
||||
if not isinstance(v, dict):
|
||||
continue
|
||||
|
||||
if v.get('validator') == 'markdown':
|
||||
# If there is a match with the validator: markdown pair, assign the sibling
|
||||
# property (following the naming convention _<property>_html)
|
||||
# the processed value.
|
||||
if k in project:
|
||||
html = pillar.markdown.markdown(project[k])
|
||||
field_name = pillar.markdown.cache_field_name(k)
|
||||
project[field_name] = html
|
||||
if isinstance(project, dict) and k in project:
|
||||
find_markdown_fields(v, project[k])
|
||||
|
||||
find_markdown_fields(schema, project)
|
||||
|
||||
return 'ok'
|
||||
|
||||
|
||||
def parse_markdowns(items):
|
||||
for item in items:
|
||||
parse_markdown(item)
|
||||
|
Reference in New Issue
Block a user