Skip to content

Commit

Permalink
enable urls from rich text in planning xml [STTNHUB-252] (#1870)
Browse files Browse the repository at this point in the history
* enable urls from rich text in planning xml [STTNHUB-252]

* addressed comment

* Add new method for update the richtext into html

* refactore code via black

* remove unwanted code
  • Loading branch information
devketanpro authored Oct 25, 2023
1 parent ddbb7c7 commit 9a422ae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
10 changes: 10 additions & 0 deletions server/planning/content_profiles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ def get_multilingual_fields(resource: str) -> Set[str]:
)
)
)


def get_editor3_fields(resource: str) -> Set[str]:
content_type = get_planning_schema(resource)
resource_schema = content_type.get("schema") or {}
return set(
field_name
for field_name, field_schema in resource_schema.items()
if (is_field_enabled(field_name, content_type) and ((field_schema or {})).get("field_type", "") == "editor_3")
)
12 changes: 2 additions & 10 deletions server/planning/feed_parsers/events_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
)
from superdesk.errors import ParserError
from superdesk.utc import local_to_utc, utc_to_local
from superdesk.text_utils import plain_text_to_html
from planning.content_profiles.utils import get_planning_schema, is_field_enabled, is_field_editor_3
from planning.content_profiles.utils import get_planning_schema, is_field_enabled
from planning.common import POST_STATE

from . import utils
Expand Down Expand Up @@ -95,7 +94,7 @@ def parse(self, tree: Element, provider=None):
self.parse_content_meta(tree, item)
self.parse_concept(tree, item)
self.parse_event_details(tree, item)

utils.upgrade_rich_text_fields(item, "event")
return [item]

except Exception as ex:
Expand Down Expand Up @@ -155,10 +154,6 @@ def parse_concept(self, tree, item):

try:
definition = concept.find(self.qname("definition")).text or ""
# if is_field_editor_3("event", "definition_short"):
if is_field_editor_3("definition_short", get_planning_schema("event")):
definition = plain_text_to_html(definition)

item["definition_short"] = definition
except Exception:
pass
Expand Down Expand Up @@ -251,9 +246,6 @@ def parse_registration_details(self, event_details, item):
registration = event_details.find(self.qname("registration"))
if registration is not None and registration.text:
registration_details = registration.text
if is_field_editor_3("registration_details", event_type):
registration_details = plain_text_to_html(registration_details)

item["registration_details"] = registration_details
except Exception:
pass
7 changes: 7 additions & 0 deletions server/planning/feed_parsers/superdesk_planning_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
POST_STATE,
)

from planning.content_profiles.utils import get_planning_schema
from .utils import upgrade_rich_text_fields

utc = pytz.UTC
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -91,6 +94,10 @@ def parse(self, tree: Element, provider=None):
self.parse_news_coverage_set(tree, item)
self.parse_news_coverage_status(tree, item)

upgrade_rich_text_fields(item, "planning")
for coverage in item.get("coverages") or []:
upgrade_rich_text_fields(coverage.get("planning") or {}, "coverage")

return [item]

except Exception as ex:
Expand Down
7 changes: 7 additions & 0 deletions server/planning/feed_parsers/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import re
import pytz
import datetime
from typing import Dict, Any
from planning.content_profiles.utils import get_editor3_fields
from superdesk.text_utils import plain_text_to_html


def has_time(value: str):
Expand All @@ -25,3 +28,7 @@ def parse_duration(value: str) -> datetime.timedelta:
if kwargs:
return datetime.timedelta(**kwargs)
raise ValueError(f"Could not parse duration string {value!r}")


def upgrade_rich_text_fields(item: Dict[str, Any], resource: str):
item.update({field: plain_text_to_html(item[field]) for field in get_editor3_fields(resource) if item.get(field)})

0 comments on commit 9a422ae

Please sign in to comment.