Skip to content

Commit

Permalink
feat: [ACI-742] add badge_incompletion signal and handler for it (#75)
Browse files Browse the repository at this point in the history
* feat: [ACI-742] add badge_incompletion signal and handler for it

* fix: [ACI-742] remove user fetch from credentials app

* feat: [ACI-742] add user identification

---------

Co-authored-by: Andrii <[email protected]>
Co-authored-by: Volodymyr Bergman <[email protected]>
  • Loading branch information
3 people authored Mar 28, 2024
1 parent 4a4d1e5 commit dd77244
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions credentials/apps/badges/services/badge_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from ..models import BadgeTemplate


def get_badge_template_by_id(badge_template_id):
try:
return BadgeTemplate.objects.get(id=badge_template_id)
Expand Down
16 changes: 13 additions & 3 deletions credentials/apps/badges/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

from openedx_events.tooling import OpenEdxPublicSignal, load_all_signals

from .signals import BADGE_PROGRESS_COMPLETE
from apps.core.api import get_user_by_username

from .signals import BADGE_PROGRESS_COMPLETE, BADGE_PROGRESS_INCOMPLETE
from ..services.badge_templates import get_badge_template_by_id
from ..services.user_credentials import create_user_credential
from ..utils import get_badging_event_types
Expand Down Expand Up @@ -51,6 +52,15 @@ def listen_for_completed_badge(sender, username, badge_template_id, **kwargs):

if badge_template.origin == 'openedx':
create_user_credential(username, badge_template)
return


@receiver(BADGE_PROGRESS_INCOMPLETE)
def listen_for_incompleted_badge(sender, username, badge_template_id, **kwargs): # pylint: disable=unused-argument
badge_template = get_badge_template_by_id(badge_template_id)
user = get_user_by_username()

# TODO: add processing for 'credly' origin
if badge_template is None:
return

if user is None:
return
8 changes: 3 additions & 5 deletions credentials/apps/badges/signals/signals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.dispatch import Signal

"""
define internal signals:
- BADGE_REQUIREMENT_FULFILLED - a single specific requirement has finished;
Expand All @@ -7,9 +9,5 @@

from django.dispatch import Signal

# Signal that indicates that user finisher all badge template requirements.
# providing_args=[
# 'username', # String usernam of User
# 'badge_template_id', # Integer ID of finished badge template
# ]
BADGE_PROGRESS_COMPLETE = Signal()
BADGE_PROGRESS_INCOMPLETE = Signal()

0 comments on commit dd77244

Please sign in to comment.