Skip to content

Commit

Permalink
refactor: extract signal emitters
Browse files Browse the repository at this point in the history
  • Loading branch information
wowkalucky committed Apr 15, 2024
1 parent f7b687e commit e0feb9d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
3 changes: 1 addition & 2 deletions credentials/apps/badges/issuers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from credentials.apps.badges.credly.data import IssueBadgeData
from credentials.apps.badges.credly.exceptions import CredlyAPIError
from credentials.apps.badges.models import BadgeTemplate, CredlyBadge, CredlyBadgeTemplate, UserCredential
from credentials.apps.badges.processing.progression import notify_badge_awarded
from credentials.apps.badges.processing.regression import notify_badge_revoked
from credentials.apps.badges.signals.signals import notify_badge_awarded, notify_badge_revoked
from credentials.apps.core.api import get_user_by_username
from credentials.apps.credentials.constants import UserCredentialStatus
from credentials.apps.credentials.issuers import AbstractCredentialIssuer
Expand Down
14 changes: 0 additions & 14 deletions credentials/apps/badges/processing/progression.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import logging
from typing import List

from openedx_events.learning.signals import BADGE_AWARDED

from credentials.apps.badges.models import BadgeRequirement


Expand Down Expand Up @@ -51,15 +49,3 @@ def process_requirements(event_type, username, payload_dict):
# process: payload rules
if requirement.apply_rules(payload_dict):
requirement.fulfill(username)


def notify_badge_awarded(user_credential): # pylint: disable=unused-argument
"""
Emit public event about badge template completion.
- username
- badge template ID
"""

badge_data = user_credential.as_badge_data()
BADGE_AWARDED.send_event(badge=badge_data)
13 changes: 0 additions & 13 deletions credentials/apps/badges/processing/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
UserData,
UserPersonalData,
)
from openedx_events.learning.signals import BADGE_REVOKED

from credentials.apps.badges.models import BadgePenalty, CredlyBadgeTemplate, UserCredential
from credentials.apps.badges.signals.signals import BADGE_PROGRESS_INCOMPLETE
Expand Down Expand Up @@ -51,15 +50,3 @@ def process_penalties(event_type, username, payload_dict):
continue
if penalty.apply_rules(payload_dict):
penalty.reset_requirements(username)


def notify_badge_revoked(user_credential): # pylint: disable=unused-argument
"""
Emit public event about badge template regression.
- username
- badge template ID
"""

badge_data = user_credential.as_badge_data()
BADGE_REVOKED.send_event(badge=badge_data)
23 changes: 23 additions & 0 deletions credentials/apps/badges/signals/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from django.dispatch import Signal
from openedx_events.learning.signals import BADGE_AWARDED, BADGE_REVOKED


# a single requirements for a badge template was finished
Expand Down Expand Up @@ -55,3 +56,25 @@ def notify_progress_incomplete(sender, username, badge_template_id):
username=username,
badge_template_id=badge_template_id,
)


def notify_badge_awarded(user_credential): # pylint: disable=unused-argument
"""
Emit public event about badge template completion.
- username
- badge template ID
"""

BADGE_AWARDED.send_event(badge=user_credential.as_badge_data())


def notify_badge_revoked(user_credential): # pylint: disable=unused-argument
"""
Emit public event about badge template regression.
- username
- badge template ID
"""

BADGE_REVOKED.send_event(badge=user_credential.as_badge_data())

0 comments on commit e0feb9d

Please sign in to comment.