forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove: score tab * feat: certificate banner in progress page * fix: makes progress tab a seprate app * fix: template path
- Loading branch information
Showing
11 changed files
with
233 additions
and
148 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
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,25 @@ | ||
""" | ||
Progress Tab App Config | ||
""" | ||
from django.apps import AppConfig | ||
from edx_django_utils.plugins import PluginURLs, PluginSettings | ||
from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType | ||
|
||
|
||
class ProgressTabConfig(AppConfig): | ||
name = 'openedx.features.wikimedia_features.progress_tab' | ||
|
||
plugin_app = { | ||
PluginURLs.CONFIG: { | ||
ProjectType.LMS: { | ||
PluginURLs.NAMESPACE: 'progress_tab', | ||
PluginURLs.REGEX: '^progress_tab/', | ||
PluginURLs.RELATIVE_PATH: 'urls', | ||
}, | ||
}, | ||
PluginSettings.CONFIG: { | ||
ProjectType.LMS: { | ||
SettingsType.COMMON: {PluginSettings.RELATIVE_PATH: 'settings.common'}, | ||
}, | ||
} | ||
} |
Empty file.
8 changes: 8 additions & 0 deletions
8
openedx/features/wikimedia_features/progress_tab/settings/common.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
"""Settings""" | ||
|
||
|
||
def plugin_settings(settings): | ||
""" | ||
Required Common settings | ||
""" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.conf.urls import url, include | ||
|
||
from .views import WikimediaProgressFragmentView | ||
|
||
app_name = 'progress_tab' | ||
|
||
urlpatterns = [ | ||
url( | ||
r'progress_fragment_view$', | ||
WikimediaProgressFragmentView.as_view(), | ||
name='progress_fragment_view' | ||
), | ||
] |
139 changes: 139 additions & 0 deletions
139
openedx/features/wikimedia_features/progress_tab/views.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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
from opaque_keys.edx.keys import CourseKey | ||
from django.template.loader import render_to_string | ||
from web_fragments.fragment import Fragment | ||
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView | ||
from completion.models import BlockCompletion | ||
from openedx.features.course_experience.utils import get_course_outline_block_tree | ||
from lms.djangoapps.courseware.courses import get_course_blocks_completion_summary, get_course_with_access | ||
from lms.djangoapps.courseware.views.views import get_cert_data | ||
from lms.djangoapps.grades.api import CourseGradeFactory | ||
from common.djangoapps.student.models import CourseEnrollment | ||
|
||
class WikimediaProgressFragmentView(EdxFragmentView): | ||
""" | ||
View to render Wikimedia course progress tab | ||
""" | ||
def _get_grade_dict(self, course_grade): | ||
""" | ||
Extract grade dict in following format from edX grade classes for subsections and problem components. | ||
{ | ||
"subsection1_block_id": { | ||
"score": 1/2, | ||
"graded": True | ||
}, | ||
"problem1_block_id": { | ||
"score": 1/1, | ||
"graded": True | ||
}, | ||
"problem2_block_id": { | ||
"score": 0/1, | ||
"graded": True | ||
} | ||
} | ||
""" | ||
data = {} | ||
if not course_grade: | ||
return data | ||
|
||
for chapter in course_grade.chapter_grades.values(): | ||
subsections = chapter.get('sections', []) | ||
for subsection in subsections: | ||
subsection_grade = subsection.graded_total | ||
subsection_score = "-" | ||
if subsection_grade and subsection_grade.possible: | ||
subsection_score = "{}/{}".format(round(subsection_grade.earned), round(subsection_grade.possible)) | ||
data.update({str(subsection.location): { | ||
'score': subsection_score, | ||
'graded': subsection_grade.graded | ||
}}) | ||
for problem_location, problem_grade in subsection.problem_scores.items(): | ||
data.update({str(problem_location): { | ||
'score': "{}/{}".format(round(problem_grade.earned), round(problem_grade.possible)), | ||
'graded': problem_grade.graded, | ||
}}) | ||
return data | ||
|
||
def _update_context_with_score_and_progress(self, block, grade_dict): | ||
""" | ||
Update given block dict with grade and progress percentage info. | ||
""" | ||
if not block: | ||
return | ||
|
||
block_grade_data = grade_dict.get(block.get('id')) | ||
if block_grade_data: | ||
block.update(block_grade_data) | ||
|
||
progress = 0 | ||
unit_count = 0 | ||
children = block.get('children', []) | ||
if not len(children): | ||
# Mark Excluded xblocks as completed | ||
if block.get('type') in ['discussion']: | ||
block.update({'complete': True, 'is_excluded_block': True}) | ||
|
||
if block.get('complete'): | ||
progress = 100 | ||
|
||
# handle case of empty sections/subsections/units | ||
if block.get('type') not in ['course', 'chapter', 'vertical', 'sequential']: | ||
unit_count = 1 | ||
|
||
block.update({ | ||
'progress': progress, | ||
'unit_count': unit_count, | ||
}) | ||
|
||
for child in children: | ||
self._update_context_with_score_and_progress(child, grade_dict) | ||
if not child.get('is_excluded_block', False): | ||
progress += child.get('progress', 0) * child.get('unit_count', 0) | ||
unit_count += child.get('unit_count', 0) | ||
|
||
if children and unit_count: | ||
block.update({ | ||
'progress': round(progress/unit_count, 1), | ||
'unit_count': unit_count | ||
}) | ||
|
||
def render_to_fragment(self, request, course_id=None, **kwargs): | ||
""" | ||
Render wikimedia course progress to a fragment. | ||
Args: | ||
request: The Django request. | ||
course_id: The id of the course in question. | ||
Returns: | ||
Fragment: The fragment representing the Wikimedia course progress | ||
""" | ||
course_key = CourseKey.from_string(course_id) | ||
user = request.user | ||
show_score_tab = False | ||
cert_data = None | ||
enrollment_mode, _ = CourseEnrollment.enrollment_mode_for_user(user, course_key) | ||
|
||
try: | ||
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True) | ||
if hasattr(course, 'enable_score_tab_on_progress_page'): | ||
show_score_tab = course.enable_score_tab_on_progress_page | ||
course_grade = CourseGradeFactory().read(user, course) | ||
grade_dict = self._get_grade_dict(course_grade) | ||
cert_data = get_cert_data(user, course, enrollment_mode, course_grade) | ||
except Exception as err: | ||
grade_dict = {} | ||
|
||
course_outline_context = get_course_outline_block_tree(request, course_id, user) | ||
self._update_context_with_score_and_progress(course_outline_context, grade_dict) | ||
html = render_to_string( | ||
"wikimedia_general/wikimedia_progress_fragment.html", | ||
{ | ||
"course_id": course_id, | ||
"data": course_outline_context, | ||
"show_score_tab": show_score_tab, | ||
"certificate_data": cert_data, | ||
}, | ||
) | ||
|
||
fragment = Fragment(html) | ||
self.add_fragment_resource_urls(fragment) | ||
return fragment |
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.