Repository navigation
[SE-4473] Add progress bar views #89
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e4852d1
feat: Add progress bar views
pkulkark 5c22fdb
fix: refactor based on review comments
pkulkark f5ae7ff
fix: move internal function position
pkulkark cf89926
fix: Add styling to html elements
pkulkark ebe81ad
fix: update username in request to aviod permission denied
pkulkark 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
4 changes: 4 additions & 0 deletions
4
completion_aggregator/templates/chapter_completion_progress_bar.html
This file contains hidden or 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,4 @@ | ||
| <div id="chapter-progress-wrapper" style="display: flex;"> | ||
| <label for="chapter-progress-bar" style="padding-right: 10px;">Chapter progress:</label> | ||
| <div id="chapter-progress-bar" style="background-color: blue; width: {{chapter_completion_percentage}}%"> </div> | ||
| </div> |
This file contains hidden or 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,4 @@ | ||
| <div id="progress-wrapper"> | ||
| <label for="progress-bar">Course progress:</label> | ||
| <progress id="progress-bar" value="{{completion_percentage}}" max="100"> {{completion_percentage}}% </progress> | ||
| </div> |
This file contains hidden or 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 hidden or 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,54 @@ | ||
| """ | ||
| completion_aggregator App progress bar view | ||
| """ | ||
| from __future__ import absolute_import, unicode_literals | ||
|
|
||
| from django.conf import settings | ||
| from django.contrib.auth.mixins import LoginRequiredMixin | ||
| from django.shortcuts import render | ||
| from django.views.decorators.clickjacking import xframe_options_exempt | ||
| from django.views.generic import TemplateView | ||
| from xblockutils.resources import ResourceLoader | ||
|
|
||
| from .api.v1.views import CompletionDetailView | ||
|
gabor-boros marked this conversation as resolved.
Resolved
|
||
|
|
||
| loader = ResourceLoader(__name__) | ||
|
|
||
|
|
||
| class CompletionProgressBarView(LoginRequiredMixin, TemplateView): | ||
|
gabor-boros marked this conversation as resolved.
Resolved
|
||
| """ | ||
| View to display the progress bar of a student in a course | ||
| """ | ||
| @xframe_options_exempt | ||
| def get(self, request, course_key, chapter_id=None): | ||
| """ | ||
| Fetch progress and render the template. | ||
| """ | ||
| username = request.user.username | ||
| completion_percentage = 0 | ||
| if chapter_id is not None: | ||
| new_req = request.GET.copy() | ||
| new_req['requested_fields'] = "chapter" | ||
| request.GET = new_req | ||
| completion_resp = CompletionDetailView.as_view()(request, course_key).data | ||
| if completion_resp: | ||
| results = completion_resp.get('results') | ||
| for user_completion_dict in results: | ||
| if user_completion_dict.get('username') == username: | ||
| if chapter_id is not None: | ||
| chapters = user_completion_dict['chapter'] | ||
| for chapter in chapters: | ||
| block_id = chapter['block_key'].split('@')[-1] | ||
| if block_id == chapter_id: | ||
| completion_percentage = float(chapter['completion']['percent']) * 100 | ||
| else: | ||
| completion_percentage = float(user_completion_dict['completion']['percent']) * 100 | ||
|
|
||
| if chapter_id is not None: | ||
| return render(request, 'chapter_completion_progress_bar.html', { | ||
| 'chapter_completion_percentage': completion_percentage, | ||
| }) | ||
| else: | ||
| return render(request, 'completion_progress_bar.html', { | ||
| 'completion_percentage': completion_percentage, | ||
| }) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.