Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
e66409be
Commit
e66409be
authored
Mar 23, 2015
by
Will Daly
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7444 from edx/will/self-gen-certs-docstring-cleanup
Docstring/messaging cleanup in self-generated certs view.
parents
072dbcd5
65953536
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
21 deletions
+33
-21
lms/djangoapps/courseware/tests/test_views.py
+2
-3
lms/djangoapps/courseware/views.py
+29
-18
lms/static/js/courseware/certificates_api.js
+2
-0
No files found.
lms/djangoapps/courseware/tests/test_views.py
View file @
e66409be
...
@@ -876,7 +876,6 @@ class GenerateUserCertTests(ModuleStoreTestCase):
...
@@ -876,7 +876,6 @@ class GenerateUserCertTests(ModuleStoreTestCase):
mock_send_to_queue
.
return_value
=
(
0
,
"Successfully queued"
)
mock_send_to_queue
.
return_value
=
(
0
,
"Successfully queued"
)
resp
=
self
.
client
.
post
(
self
.
url
)
resp
=
self
.
client
.
post
(
self
.
url
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertIn
(
"Creating certificate"
,
resp
.
content
)
#Verify Google Analytics event fired after generating certificate
#Verify Google Analytics event fired after generating certificate
mock_tracker
.
track
.
assert_called_once_with
(
# pylint: disable=no-member
mock_tracker
.
track
.
assert_called_once_with
(
# pylint: disable=no-member
...
@@ -906,7 +905,7 @@ class GenerateUserCertTests(ModuleStoreTestCase):
...
@@ -906,7 +905,7 @@ class GenerateUserCertTests(ModuleStoreTestCase):
)
)
resp
=
self
.
client
.
post
(
self
.
url
)
resp
=
self
.
client
.
post
(
self
.
url
)
self
.
assertEqual
(
resp
.
status_code
,
HttpResponseBadRequest
.
status_code
)
self
.
assertEqual
(
resp
.
status_code
,
HttpResponseBadRequest
.
status_code
)
self
.
assertIn
(
"C
reating certificate
"
,
resp
.
content
)
self
.
assertIn
(
"C
ertificate is already being created.
"
,
resp
.
content
)
@patch
(
'courseware.grades.grade'
,
Mock
(
return_value
=
{
'grade'
:
'Pass'
,
'percent'
:
0.75
}))
@patch
(
'courseware.grades.grade'
,
Mock
(
return_value
=
{
'grade'
:
'Pass'
,
'percent'
:
0.75
}))
def
test_user_with_passing_existing_downloadable_cert
(
self
):
def
test_user_with_passing_existing_downloadable_cert
(
self
):
...
@@ -920,7 +919,7 @@ class GenerateUserCertTests(ModuleStoreTestCase):
...
@@ -920,7 +919,7 @@ class GenerateUserCertTests(ModuleStoreTestCase):
)
)
resp
=
self
.
client
.
post
(
self
.
url
)
resp
=
self
.
client
.
post
(
self
.
url
)
self
.
assertEqual
(
resp
.
status_code
,
HttpResponseBadRequest
.
status_code
)
self
.
assertEqual
(
resp
.
status_code
,
HttpResponseBadRequest
.
status_code
)
self
.
assertIn
(
"C
reating certificate
"
,
resp
.
content
)
self
.
assertIn
(
"C
ertificate has already been created.
"
,
resp
.
content
)
def
test_user_with_non_existing_course
(
self
):
def
test_user_with_non_existing_course
(
self
):
# If try to access a course with valid key pattern then it will return
# If try to access a course with valid key pattern then it will return
...
...
lms/djangoapps/courseware/views.py
View file @
e66409be
...
@@ -1302,18 +1302,27 @@ def is_course_passed(course, grade_summary=None, student=None, request=None):
...
@@ -1302,18 +1302,27 @@ def is_course_passed(course, grade_summary=None, student=None, request=None):
return
success_cutoff
and
grade_summary
[
'percent'
]
>
success_cutoff
return
success_cutoff
and
grade_summary
[
'percent'
]
>
success_cutoff
@ensure_csrf_cookie
@require_POST
@require_POST
def
generate_user_cert
(
request
,
course_id
):
def
generate_user_cert
(
request
,
course_id
):
"""
"""Start generating a new certificate for the user.
It will check all validation and on clearance will add the new-certificate request into the xqueue.
Args:
Certificate generation is allowed if:
request (django request object): the HTTP request object that triggered this view function
* The user has passed the course, and
course_id (unicode): id associated with the course
* The user does not already have a pending/completed certificate.
Note that if an error occurs during certificate generation
(for example, if the queue is down), then we simply mark the
certificate generation task status as "error" and re-run
the task with a management command. To students, the certificate
will appear to be "generating" until it is re-run.
Args:
request (HttpRequest): The POST request to this view.
course_id (unicode): The identifier for the course.
Returns:
Returns:
returns json response
HttpResponse: 200 on success, 400 if a new certificate cannot be generated.
"""
"""
if
not
request
.
user
.
is_authenticated
():
if
not
request
.
user
.
is_authenticated
():
...
@@ -1325,7 +1334,6 @@ def generate_user_cert(request, course_id):
...
@@ -1325,7 +1334,6 @@ def generate_user_cert(request, course_id):
)
)
student
=
request
.
user
student
=
request
.
user
course_key
=
CourseKey
.
from_string
(
course_id
)
course_key
=
CourseKey
.
from_string
(
course_id
)
course
=
modulestore
()
.
get_course
(
course_key
,
depth
=
2
)
course
=
modulestore
()
.
get_course
(
course_key
,
depth
=
2
)
...
@@ -1337,17 +1345,20 @@ def generate_user_cert(request, course_id):
...
@@ -1337,17 +1345,20 @@ def generate_user_cert(request, course_id):
certificate_status
=
certs_api
.
certificate_downloadable_status
(
student
,
course
.
id
)
certificate_status
=
certs_api
.
certificate_downloadable_status
(
student
,
course
.
id
)
if
not
certificate_status
[
"is_downloadable"
]
and
not
certificate_status
[
"is_generating"
]:
if
certificate_status
[
"is_downloadable"
]:
return
HttpResponseBadRequest
(
_
(
"Certificate has already been created."
))
elif
certificate_status
[
"is_generating"
]:
return
HttpResponseBadRequest
(
_
(
"Certificate is already being created."
))
else
:
# If the certificate is not already in-process or completed,
# then create a new certificate generation task.
# If the certificate cannot be added to the queue, this will
# mark the certificate with "error" status, so it can be re-run
# with a management command. From the user's perspective,
# it will appear that the certificate task was submitted successfully.
certs_api
.
generate_user_certificates
(
student
,
course
.
id
)
certs_api
.
generate_user_certificates
(
student
,
course
.
id
)
_track_successful_certificate_generation
(
student
.
id
,
course
.
id
)
_track_successful_certificate_generation
(
student
.
id
,
course
.
id
)
return
HttpResponse
(
_
(
"Creating certificate"
))
return
HttpResponse
()
# if certificate_status is not is_downloadable and is_generating or
# if any error appears during certificate generation return the message cert is generating.
# with badrequest
# at backend debug the issue and re-submit the task.
return
HttpResponseBadRequest
(
_
(
"Creating certificate"
))
def
_track_successful_certificate_generation
(
user_id
,
course_id
):
# pylint: disable=invalid-name
def
_track_successful_certificate_generation
(
user_id
,
course_id
):
# pylint: disable=invalid-name
...
@@ -1355,7 +1366,7 @@ def _track_successful_certificate_generation(user_id, course_id): # pylint: dis
...
@@ -1355,7 +1366,7 @@ def _track_successful_certificate_generation(user_id, course_id): # pylint: dis
Arguments:
Arguments:
user_id (str): The ID of the user generting the certificate.
user_id (str): The ID of the user generting the certificate.
course_id (
unicode): id associated with the course
course_id (
CourseKey): Identifier for the course.
Returns:
Returns:
None
None
...
...
lms/static/js/courseware/certificates_api.js
View file @
e66409be
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
'use strict'
;
$
(
"#btn_generate_cert"
).
click
(
function
(
e
){
$
(
"#btn_generate_cert"
).
click
(
function
(
e
){
e
.
preventDefault
();
e
.
preventDefault
();
var
post_url
=
$
(
"#btn_generate_cert"
).
data
(
"endpoint"
);
var
post_url
=
$
(
"#btn_generate_cert"
).
data
(
"endpoint"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment