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
1fe76d7c
Commit
1fe76d7c
authored
Sep 25, 2017
by
McKenzie Welter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
calculated hours of effort for rendering cert template context
parent
bfe2b67e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
18 deletions
+43
-18
lms/djangoapps/certificates/tests/test_webview_views.py
+31
-11
lms/djangoapps/certificates/views/webview.py
+11
-1
openedx/core/lib/edx_api_utils.py
+1
-6
No files found.
lms/djangoapps/certificates/tests/test_webview_views.py
View file @
1fe76d7c
...
@@ -212,6 +212,15 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -212,6 +212,15 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
Tests for the certificates web/html views
Tests for the certificates web/html views
"""
"""
def
setUp
(
self
):
super
(
CertificatesViewsTests
,
self
)
.
setUp
()
self
.
mock_course_run_details
=
{
'content_language'
:
'en'
,
'start'
:
'2013-02-05T05:00:00Z'
,
'end'
:
'2013-03-05T05:00:00Z'
,
'max_effort'
:
'10'
}
@override_settings
(
FEATURES
=
FEATURES_WITH_CERTS_ENABLED
)
@override_settings
(
FEATURES
=
FEATURES_WITH_CERTS_ENABLED
)
def
test_linkedin_share_url
(
self
):
def
test_linkedin_share_url
(
self
):
"""
"""
...
@@ -921,7 +930,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -921,7 +930,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
Tests custom template search and rendering.
Tests custom template search and rendering.
This test should check template matching when org={org}, course={course}, mode={mode}.
This test should check template matching when org={org}, course={course}, mode={mode}.
"""
"""
mock_get_course_run_details
.
return_value
=
{
'content_language'
:
'en'
}
mock_get_course_run_details
.
return_value
=
self
.
mock_course_run_details
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_create_custom_named_template
(
'test_template_1_course'
,
org_id
=
1
,
mode
=
'honor'
,
course_key
=
unicode
(
self
.
course
.
id
))
self
.
_create_custom_named_template
(
'test_template_1_course'
,
org_id
=
1
,
mode
=
'honor'
,
course_key
=
unicode
(
self
.
course
.
id
))
self
.
_create_custom_named_template
(
'test_template_2_course'
,
org_id
=
1
,
mode
=
'verified'
,
course_key
=
unicode
(
self
.
course
.
id
))
self
.
_create_custom_named_template
(
'test_template_2_course'
,
org_id
=
1
,
mode
=
'verified'
,
course_key
=
unicode
(
self
.
course
.
id
))
...
@@ -951,7 +960,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -951,7 +960,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
match org and mode.
match org and mode.
This test should check template matching when org={org}, course=Null, mode={mode}.
This test should check template matching when org={org}, course=Null, mode={mode}.
"""
"""
mock_get_course_run_details
.
return_value
=
{
'content_language'
:
'en'
}
mock_get_course_run_details
.
return_value
=
self
.
mock_course_run_details
othercourse
=
CourseFactory
.
create
(
othercourse
=
CourseFactory
.
create
(
org
=
'cstX'
,
number
=
'cst_22'
,
display_name
=
'custom template course'
org
=
'cstX'
,
number
=
'cst_22'
,
display_name
=
'custom template course'
)
)
...
@@ -984,7 +993,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -984,7 +993,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
Tests custom template search when we have a single template for a organization.
Tests custom template search when we have a single template for a organization.
This test should check template matching when org={org}, course=Null, mode=null.
This test should check template matching when org={org}, course=Null, mode=null.
"""
"""
mock_get_course_run_details
.
return_value
=
{
'content_language'
:
'en'
}
mock_get_course_run_details
.
return_value
=
self
.
mock_course_run_details
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_create_custom_named_template
(
'test_template_1_course'
,
org_id
=
1
,
mode
=
None
)
# Correct template
self
.
_create_custom_named_template
(
'test_template_1_course'
,
org_id
=
1
,
mode
=
None
)
# Correct template
self
.
_create_custom_named_template
(
'test_template_2_course'
,
org_id
=
1
,
mode
=
'verified'
)
# wrong mode
self
.
_create_custom_named_template
(
'test_template_2_course'
,
org_id
=
1
,
mode
=
'verified'
)
# wrong mode
...
@@ -1007,7 +1016,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -1007,7 +1016,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
Tests custom template search if we have a single template for a course mode.
Tests custom template search if we have a single template for a course mode.
This test should check template matching when org=null, course=Null, mode={mode}.
This test should check template matching when org=null, course=Null, mode={mode}.
"""
"""
mock_get_course_run_details
.
return_value
=
{
'content_language'
:
'en'
}
mock_get_course_run_details
.
return_value
=
self
.
mock_course_run_details
mode
=
'honor'
mode
=
'honor'
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_create_custom_named_template
(
'test_template_1_course'
,
org_id
=
None
,
mode
=
mode
)
# Correct template
self
.
_create_custom_named_template
(
'test_template_1_course'
,
org_id
=
None
,
mode
=
mode
)
# Correct template
...
@@ -1039,7 +1048,10 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -1039,7 +1048,10 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
right_language
=
'es'
right_language
=
'es'
wrong_language
=
'fr'
wrong_language
=
'fr'
mock_get_org_id
.
return_value
=
1
mock_get_org_id
.
return_value
=
1
mock_get_course_run_details
.
return_value
=
{
'content_language'
:
'es'
}
course_run_details
=
self
.
mock_course_run_details
course_run_details
.
update
({
'content_language'
:
'es'
})
mock_get_course_run_details
.
return_value
=
course_run_details
CertificateGenerationCourseSetting
.
set_language_specific_templates_enabled_for_course
(
self
.
course
.
id
,
True
)
CertificateGenerationCourseSetting
.
set_language_specific_templates_enabled_for_course
(
self
.
course
.
id
,
True
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
...
@@ -1082,7 +1094,9 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -1082,7 +1094,9 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
right_language
=
'es'
right_language
=
'es'
wrong_language
=
'fr'
wrong_language
=
'fr'
mock_get_org_id
.
return_value
=
1
mock_get_org_id
.
return_value
=
1
mock_get_course_run_details
.
return_value
=
{
'content_language'
:
'es'
}
course_run_details
=
self
.
mock_course_run_details
course_run_details
.
update
({
'content_language'
:
'es'
})
mock_get_course_run_details
.
return_value
=
course_run_details
CertificateGenerationCourseSetting
.
set_language_specific_templates_enabled_for_course
(
self
.
course
.
id
,
True
)
CertificateGenerationCourseSetting
.
set_language_specific_templates_enabled_for_course
(
self
.
course
.
id
,
True
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
...
@@ -1124,7 +1138,9 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -1124,7 +1138,9 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
right_language
=
'es'
right_language
=
'es'
wrong_language
=
'fr'
wrong_language
=
'fr'
mock_get_org_id
.
return_value
=
1
mock_get_org_id
.
return_value
=
1
mock_get_course_run_details
.
return_value
=
{
'content_language'
:
'es'
}
course_run_details
=
self
.
mock_course_run_details
course_run_details
.
update
({
'content_language'
:
'es'
})
mock_get_course_run_details
.
return_value
=
course_run_details
CertificateGenerationCourseSetting
.
set_language_specific_templates_enabled_for_course
(
self
.
course
.
id
,
True
)
CertificateGenerationCourseSetting
.
set_language_specific_templates_enabled_for_course
(
self
.
course
.
id
,
True
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
...
@@ -1165,7 +1181,9 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -1165,7 +1181,9 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
right_language
=
'es'
right_language
=
'es'
wrong_language
=
'fr'
wrong_language
=
'fr'
mock_get_org_id
.
return_value
=
1
mock_get_org_id
.
return_value
=
1
mock_get_course_run_details
.
return_value
=
{
'content_language'
:
'es'
}
course_run_details
=
self
.
mock_course_run_details
course_run_details
.
update
({
'content_language'
:
'es'
})
mock_get_course_run_details
.
return_value
=
course_run_details
CertificateGenerationCourseSetting
.
set_language_specific_templates_enabled_for_course
(
self
.
course
.
id
,
True
)
CertificateGenerationCourseSetting
.
set_language_specific_templates_enabled_for_course
(
self
.
course
.
id
,
True
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
...
@@ -1206,7 +1224,9 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -1206,7 +1224,9 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
right_language
=
'es'
right_language
=
'es'
wrong_language
=
'fr'
wrong_language
=
'fr'
mock_get_org_id
.
return_value
=
1
mock_get_org_id
.
return_value
=
1
mock_get_course_run_details
.
return_value
=
{
'content_language'
:
'es-419'
}
course_run_details
=
self
.
mock_course_run_details
course_run_details
.
update
({
'content_language'
:
'es-419'
})
mock_get_course_run_details
.
return_value
=
course_run_details
CertificateGenerationCourseSetting
.
set_language_specific_templates_enabled_for_course
(
self
.
course
.
id
,
True
)
CertificateGenerationCourseSetting
.
set_language_specific_templates_enabled_for_course
(
self
.
course
.
id
,
True
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
...
@@ -1242,7 +1262,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -1242,7 +1262,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
"""
"""
Tests custom template renders properly with unicode data.
Tests custom template renders properly with unicode data.
"""
"""
mock_get_course_run_details
.
return_value
=
{
'content_language'
:
'en'
}
mock_get_course_run_details
.
return_value
=
self
.
mock_course_run_details
mode
=
'honor'
mode
=
'honor'
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_create_custom_template
(
mode
=
mode
)
self
.
_create_custom_template
(
mode
=
mode
)
...
@@ -1276,7 +1296,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
...
@@ -1276,7 +1296,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase):
"""
"""
Tests certificate template asset display by slug using static.certificate_asset_url method.
Tests certificate template asset display by slug using static.certificate_asset_url method.
"""
"""
mock_get_course_run_details
.
return_value
=
{
'content_language'
:
'en'
}
mock_get_course_run_details
.
return_value
=
self
.
mock_course_run_details
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
self
.
_create_custom_template
(
mode
=
'honor'
)
self
.
_create_custom_template
(
mode
=
'honor'
)
test_url
=
get_certificate_url
(
test_url
=
get_certificate_url
(
...
...
lms/djangoapps/certificates/views/webview.py
View file @
1fe76d7c
...
@@ -5,6 +5,7 @@ Certificate HTML webview.
...
@@ -5,6 +5,7 @@ Certificate HTML webview.
import
logging
import
logging
import
urllib
import
urllib
from
datetime
import
datetime
from
datetime
import
datetime
from
dateutil
import
parser
from
uuid
import
uuid4
from
uuid
import
uuid4
import
pytz
import
pytz
...
@@ -252,7 +253,16 @@ def _update_course_context(request, context, course, course_key, platform_name):
...
@@ -252,7 +253,16 @@ def _update_course_context(request, context, course, course_key, platform_name):
if
CertificateGenerationCourseSetting
.
is_language_specific_templates_enabled_for_course
(
course_key
):
if
CertificateGenerationCourseSetting
.
is_language_specific_templates_enabled_for_course
(
course_key
):
fields
=
[
'start'
,
'end'
,
'max_effort'
,
'content_language'
]
fields
=
[
'start'
,
'end'
,
'max_effort'
,
'content_language'
]
course_run_data
=
get_course_run_details
(
course_key
,
fields
)
course_run_data
=
get_course_run_details
(
course_key
,
fields
)
context
.
update
(
course_run_data
)
if
course_run_data
[
'start'
]
and
course_run_data
[
'end'
]
and
course_run_data
[
'max_effort'
]:
# Calculate duration of the course run in weeks, multiplied by max_effort for total Hours of Effort
try
:
start
=
parser
.
parse
(
course_run_data
[
'start'
])
end
=
parser
.
parse
(
course_run_data
[
'end'
])
max_effort
=
int
(
course_run_data
[
'max_effort'
])
context
[
'hours_of_effort'
]
=
((
end
-
start
)
.
days
/
7
)
*
max_effort
except
ValueError
:
log
.
exception
(
'Error occurred while parsing course run details'
)
context
[
'content_language'
]
=
course_run_data
[
'content_language'
]
def
_update_social_context
(
request
,
context
,
course
,
user
,
user_certificate
,
platform_name
):
def
_update_social_context
(
request
,
context
,
course
,
user
,
user_certificate
,
platform_name
):
...
...
openedx/core/lib/edx_api_utils.py
View file @
1fe76d7c
...
@@ -19,12 +19,7 @@ def get_fields(fields, response):
...
@@ -19,12 +19,7 @@ def get_fields(fields, response):
"""Extracts desired fields from the API response"""
"""Extracts desired fields from the API response"""
results
=
{}
results
=
{}
for
field
in
fields
:
for
field
in
fields
:
try
:
results
[
field
]
=
response
.
get
(
field
)
results
[
field
]
=
response
[
field
]
# TODO: Determine what exception would be raised here if response does not have the specified field
except
:
msg
=
'{resource} does not have the attribute {field}'
.
format
(
resource
,
field
)
log
.
exception
(
msg
)
return
results
return
results
...
...
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