-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cohort certificate overrides filter
Fix get cohort for an user that as requested to be removed (pending). fccn/nau-technical#339
- Loading branch information
Showing
2 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 19 additions & 3 deletions
22
nau_openedx_extensions/edxapp_wrapper/backends/cohort_v1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |