Skip to content

Commit

Permalink
fix: cohort certificate overrides filter
Browse files Browse the repository at this point in the history
Fix get cohort for an user that as requested to be removed (pending).

fccn/nau-technical#339
  • Loading branch information
igobranco committed Nov 19, 2024
1 parent 3729014 commit 40d1921
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ lint: ## Run linters to check code style
$(TOX) pycodestyle ./nau_openedx_extensions
$(TOX) isort --check-only --diff ./nau_openedx_extensions

isort: ## Fix Python import sort
$(TOX) isort ./nau_openedx_extensions


# Define PIP_COMPILE_OPTS=-v to get more information during make upgrade.
PIP_COMPILE = pip-compile --rebuild --upgrade $(PIP_COMPILE_OPTS)
Expand Down
22 changes: 19 additions & 3 deletions nau_openedx_extensions/edxapp_wrapper/backends/cohort_v1.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
"""
Cohort abstraction backend
"""
from common.djangoapps.student.models import get_user_by_username_or_email # pylint: disable=import-error
import logging
import traceback

from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.db.models import Q
from openedx.core.djangoapps.course_groups.cohorts import \
get_cohort as edxapp_get_cohort # pylint: disable=import-error

log = logging.getLogger(__name__)


def get_cohort(username, course_key):
"""
Get the Course Cohort for the User that belongs the username if available other case return None.
"""
user = get_user_by_username_or_email(username)
return edxapp_get_cohort(user, course_key, assign=False, use_cached=False)
user = None
# pylint: disable=broad-except
try:
user = User.objects.get(Q(username=username))
except Exception as e:
log.error("On get_cohort method error getting user %s, error: %s, stacktrace: %s", username, str(e), traceback.format_exc())
# pylint: disable=broad-except
try:
return edxapp_get_cohort(user, course_key, assign=False, use_cached=False)
except Exception as e:
log.error("On get_cohort method error getting cohort course_key: %s, error: %s, stacktrace: %s", course_key, str(e), traceback.format_exc())
return None

0 comments on commit 40d1921

Please sign in to comment.