Skip to content

Commit

Permalink
[STTNHUB-312] Add planning_ingested signal
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkLark86 committed Jan 18, 2024
1 parent cc6ef7a commit 3136897
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions server/planning/planning/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
from superdesk import Resource
from lxml import etree
from io import BytesIO
from planning.signals import planning_created
from planning.signals import planning_created, planning_ingested

logger = logging.getLogger(__name__)

Expand All @@ -85,6 +85,8 @@ def post_in_mongo(self, docs, **kwargs):
resolve_document_etag(docs, self.datasource)
ids = self.backend.create_in_mongo(self.datasource, docs, **kwargs)
self.on_created(docs)
for doc in docs:
planning_ingested.send(self, item=doc)
return ids

def patch_in_mongo(self, id, document, original):
Expand All @@ -93,6 +95,7 @@ def patch_in_mongo(self, id, document, original):
update_ingest_on_patch(document, original)
response = self.backend.update_in_mongo(self.datasource, id, document, original)
self.on_updated(document, original, from_ingest=True)
planning_ingested.send(self, item=document, original=original)
return response

def is_new_version(self, new_item, old_item):
Expand Down Expand Up @@ -523,13 +526,17 @@ def remove_coverage_entity(self, coverage_entity, original_planning, entity_type

def add_coverages(self, updates, original):
planning_date = original.get("planning_date") or updates.get("planning_date")
original_coverage_ids = [
coverage["coverage_id"] for coverage in original.get("coverages") or [] if coverage.get("coverage_id")
]
for coverage in updates.get("coverages") or []:
coverage_id = coverage.get("coverage_id", "")
if not coverage_id or TEMP_ID_PREFIX in coverage_id:
if not coverage_id or TEMP_ID_PREFIX in coverage_id or coverage_id not in original_coverage_ids:
if "duplicate" in coverage_id:
self.duplicate_xmp_file(coverage)
# coverage to be created
coverage["coverage_id"] = generate_guid(type=GUID_NEWSML)
if not coverage_id or TEMP_ID_PREFIX in coverage_id:
coverage["coverage_id"] = generate_guid(type=GUID_NEWSML)
coverage["firstcreated"] = utcnow()

# Make sure the coverage has a ``scheduled`` date
Expand Down
2 changes: 2 additions & 0 deletions server/planning/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

__all__ = [
"planning_created",
"planning_ingested",
]

signals = blinker.Namespace()

planning_created = signals.signal("planning:created")
planning_ingested = signals.signal("planning:ingested")

0 comments on commit 3136897

Please sign in to comment.