Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mypy errors for partials #2492

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions apps/publish/content/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 4 additions & 7 deletions apps/publish/content/resend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand All @@ -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!"))

Expand Down
14 changes: 14 additions & 0 deletions apps/publish/content/utils.py
Original file line number Diff line number Diff line change
@@ -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)]
3 changes: 2 additions & 1 deletion apps/publish/enqueue/enqueue_corrected.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions apps/publish/enqueue/enqueue_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading