forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: [AXM-297] Add progress to assignments in BlocksInfoInCourseView API #2546
Merged
monteri
merged 4 commits into
glugovgrglib/add_course_access_to_mobile_info_api
from
kireiev/feat/AXM-297/Add_progress_to_assignments
Apr 25, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
159ee63
feat: [AXM-297, AXM-310] Add progress to assignments and total course…
KyryloKireiev 3d70e8c
feat: [AXM-297] Add progress to assignments
KyryloKireiev fa6349c
style: [AXM-297] Try to fix linters (add docstrings)
KyryloKireiev 2f9e155
refactor: [AXM-297] Add typing, refactor methods
KyryloKireiev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
""" | ||
Common constants for the `course_info` API. | ||
""" | ||
|
||
BLOCK_STRUCTURE_CACHE_TIMEOUT = 60 * 60 # 1 hour |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Common utils for the `course_info` API. | ||
""" | ||
|
||
import logging | ||
from typing import List, Optional, Union | ||
|
||
from django.core.cache import cache | ||
|
||
from lms.djangoapps.courseware.access import has_access | ||
from lms.djangoapps.grades.api import CourseGradeFactory | ||
from openedx.core.djangoapps.content.block_structure.api import get_block_structure_manager | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def calculate_progress( | ||
user: 'User', # noqa: F821 | ||
course_id: 'CourseLocator', # noqa: F821 | ||
cache_timeout: int, | ||
) -> Optional[List[Union['ReadSubsectionGrade', 'ZeroSubsectionGrade']]]: # noqa: F821 | ||
""" | ||
Calculate the progress of the user in the course. | ||
""" | ||
is_staff = bool(has_access(user, 'staff', course_id)) | ||
|
||
try: | ||
cache_key = f'course_block_structure_{str(course_id)}_{user.id}' | ||
collected_block_structure = cache.get(cache_key) | ||
if not collected_block_structure: | ||
collected_block_structure = get_block_structure_manager(course_id).get_collected() | ||
cache.set(cache_key, collected_block_structure, cache_timeout) | ||
|
||
course_grade = CourseGradeFactory().read(user, collected_block_structure=collected_block_structure) | ||
|
||
# recalculate course grade from visible grades (stored grade was calculated over all grades, visible or not) | ||
course_grade.update(visible_grades_only=True, has_staff_access=is_staff) | ||
subsection_grades = list(course_grade.subsection_grades.values()) | ||
except Exception as err: # pylint: disable=broad-except | ||
log.warning(f'Could not get grades for the course: {course_id}, error: {err}') | ||
return [] | ||
|
||
return subsection_grades |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably it could be wrapped in the try except with potential log to debug easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I wrapped into try except
calculate_progress
function's logic in utils file