diff --git a/apps/publish/content/common.py b/apps/publish/content/common.py index cd6ab7f439..8c35f54d00 100644 --- a/apps/publish/content/common.py +++ b/apps/publish/content/common.py @@ -14,7 +14,6 @@ from copy import copy from copy import deepcopy -from functools import partial from flask import current_app as app from superdesk import get_resource_service @@ -37,7 +36,6 @@ from superdesk.metadata.packages import LINKED_IN_PACKAGES, PACKAGE, PACKAGE_TYPE from superdesk.metadata.utils import item_url from superdesk.notification import push_notification -from superdesk.publish import SUBSCRIBER_TYPES from superdesk.services import BaseService from superdesk.utc import utcnow, get_date from superdesk.workflow import is_workflow_state_transition_valid @@ -139,11 +137,6 @@ class BasePublishService(BaseService): publish_type = "publish" published_state = "published" item_operation = ITEM_PUBLISH - - non_digital = partial(filter, lambda s: s.get("subscriber_type", "") == SUBSCRIBER_TYPES.WIRE) - digital = partial( - filter, lambda s: (s.get("subscriber_type", "") in {SUBSCRIBER_TYPES.DIGITAL, SUBSCRIBER_TYPES.ALL}) - ) package_service = PackageService() def on_update(self, updates, original): diff --git a/apps/publish/content/resend.py b/apps/publish/content/resend.py index f485472a94..d42d6bab04 100644 --- a/apps/publish/content/resend.py +++ b/apps/publish/content/resend.py @@ -8,10 +8,11 @@ # AUTHORS and LICENSE files distributed with this source code, or # at https://www.sourcefabric.org/superdesk/license +import logging + from apps.archive.archive import ArchiveResource, SOURCE as ARCHIVE, remove_is_queued +from apps.publish.content.utils import filter_digital from superdesk.metadata.utils import item_url -import logging -from functools import partial from flask import request, current_app as app from superdesk import get_resource_service, Service, config, signals from superdesk.errors import SuperdeskApiError @@ -39,10 +40,6 @@ class ResendResource(ArchiveResource): class ResendService(Service): - digital = partial( - filter, lambda s: (s.get("subscriber_type", "") in {SUBSCRIBER_TYPES.DIGITAL, SUBSCRIBER_TYPES.ALL}) - ) - def create(self, docs, **kwargs): doc = docs[0] if len(docs) > 0 else {} article_id = request.view_args["original_id"] @@ -67,7 +64,7 @@ def _validate_subscribers(self, subscriber_ids, article): raise SuperdeskApiError.badRequestError(message=_("No active subscribers found!")) if is_genre(article, BROADCAST_GENRE): - digital_subscribers = list(self.digital(subscribers)) + digital_subscribers = filter_digital(subscribers) if len(digital_subscribers) > 0: raise SuperdeskApiError.badRequestError(_("Only wire subscribers can receive broadcast stories!")) diff --git a/apps/publish/content/utils.py b/apps/publish/content/utils.py new file mode 100644 index 0000000000..22659b9ded --- /dev/null +++ b/apps/publish/content/utils.py @@ -0,0 +1,14 @@ +from typing import Dict, List +from superdesk.publish import SUBSCRIBER_TYPES + + +def is_digital(subscriber: Dict) -> bool: + return subscriber.get("subscriber_type", "") in {SUBSCRIBER_TYPES.DIGITAL, SUBSCRIBER_TYPES.ALL} + + +def filter_digital(subscribers: List[Dict]) -> List[Dict]: + return [s for s in subscribers if is_digital(s)] + + +def filter_non_digital(subscribers: List[Dict]) -> List[Dict]: + return [s for s in subscribers if not is_digital(s)] diff --git a/apps/publish/enqueue/enqueue_corrected.py b/apps/publish/enqueue/enqueue_corrected.py index 0a5b0dad80..7cfca3a833 100644 --- a/apps/publish/enqueue/enqueue_corrected.py +++ b/apps/publish/enqueue/enqueue_corrected.py @@ -8,6 +8,7 @@ # AUTHORS and LICENSE files distributed with this source code, or # at https://www.sourcefabric.org/superdesk/license +from apps.publish.content.utils import filter_non_digital from superdesk import get_resource_service from superdesk.metadata.item import CONTENT_STATE from eve.utils import config @@ -56,7 +57,7 @@ def get_subscribers(self, doc, target_media_type): if len(subscribers_yet_to_receive) > 0: # Step 3 if doc.get("target_regions"): - subscribers_yet_to_receive = list(self.non_digital(subscribers_yet_to_receive)) + subscribers_yet_to_receive = filter_non_digital(subscribers_yet_to_receive) # Step 4 subscribers_yet_to_receive, codes = self.filter_subscribers( doc, subscribers_yet_to_receive, target_media_type diff --git a/apps/publish/enqueue/enqueue_service.py b/apps/publish/enqueue/enqueue_service.py index 175a106ce1..b753d3c77b 100644 --- a/apps/publish/enqueue/enqueue_service.py +++ b/apps/publish/enqueue/enqueue_service.py @@ -25,6 +25,7 @@ from superdesk.publish import SUBSCRIBER_TYPES from superdesk.publish.publish_queue import PUBLISHED_IN_PACKAGE from superdesk.publish.formatters import get_formatter +from apps.publish.content.utils import filter_digital, filter_non_digital from apps.publish.content.common import BasePublishService from copy import deepcopy from eve.utils import config, ParsedRequest @@ -45,10 +46,6 @@ class EnqueueService: publish_type = "publish" published_state = "published" - non_digital = partial(filter, lambda s: s.get("subscriber_type", "") == SUBSCRIBER_TYPES.WIRE) - digital = partial( - filter, lambda s: (s.get("subscriber_type", "") in {SUBSCRIBER_TYPES.DIGITAL, SUBSCRIBER_TYPES.ALL}) - ) package_service = PackageService() filters = None @@ -313,8 +310,8 @@ def resend(self, doc, subscribers): :return: """ subscriber_codes = self._get_subscriber_codes(subscribers) - wire_subscribers = list(self.non_digital(subscribers)) - digital_subscribers = list(self.digital(subscribers)) + wire_subscribers = filter_non_digital(subscribers) + digital_subscribers = filter_digital(subscribers) for subscriber in wire_subscribers: subscriber["api_enabled"] = len(subscriber.get("api_products") or []) > 0