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
4dd55609
Commit
4dd55609
authored
Jun 10, 2015
by
Matt Drayer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8430 from edx/asadiqbal08/SOL-971
SOL-971
parents
03490908
302d7a01
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
195 additions
and
6 deletions
+195
-6
common/djangoapps/microsite_configuration/microsite.py
+1
-0
lms/djangoapps/certificates/tests/test_views.py
+166
-1
lms/djangoapps/certificates/views.py
+28
-5
No files found.
common/djangoapps/microsite_configuration/microsite.py
View file @
4dd55609
...
...
@@ -126,6 +126,7 @@ def _set_current_microsite(microsite_config_key, subdomain, domain):
"""
config
=
settings
.
MICROSITE_CONFIGURATION
[
microsite_config_key
]
.
copy
()
config
[
'subdomain'
]
=
subdomain
config
[
'microsite_config_key'
]
=
microsite_config_key
config
[
'site_domain'
]
=
domain
CURRENT_REQUEST_CONFIGURATION
.
data
=
config
...
...
lms/djangoapps/certificates/tests/test_views.py
View file @
4dd55609
...
...
@@ -26,7 +26,8 @@ from certificates.models import (
ExampleCertificate
,
GeneratedCertificate
,
BadgeAssertion
,
CertificateStatuses
CertificateStatuses
,
CertificateHtmlViewConfiguration
)
from
certificates.tests.factories
import
(
...
...
@@ -185,6 +186,170 @@ class UpdateExampleCertificateViewTest(TestCase):
self
.
assertEqual
(
content
[
'return_code'
],
0
)
def
fakemicrosite
(
name
,
default
=
None
):
"""
This is a test mocking function to return a microsite configuration
"""
if
name
==
'microsite_config_key'
:
return
'test_microsite'
else
:
return
default
@attr
(
'shard_1'
)
class
MicrositeCertificatesViewsTests
(
ModuleStoreTestCase
):
"""
Tests for the microsite certificates web/html views
"""
def
setUp
(
self
):
super
(
MicrositeCertificatesViewsTests
,
self
)
.
setUp
()
self
.
client
=
Client
()
self
.
course
=
CourseFactory
.
create
(
org
=
'testorg'
,
number
=
'run1'
,
display_name
=
'refundable course'
)
self
.
course_id
=
self
.
course
.
location
.
course_key
self
.
user
=
UserFactory
.
create
(
email
=
'joe_user@edx.org'
,
username
=
'joeuser'
,
password
=
'foo'
)
self
.
user
.
profile
.
name
=
"Joe User"
self
.
user
.
profile
.
save
()
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
'foo'
)
self
.
cert
=
GeneratedCertificate
.
objects
.
create
(
user
=
self
.
user
,
course_id
=
self
.
course_id
,
verify_uuid
=
uuid4
(),
download_uuid
=
uuid4
(),
grade
=
"0.95"
,
key
=
'the_key'
,
distinction
=
True
,
status
=
'generated'
,
mode
=
'honor'
,
name
=
self
.
user
.
profile
.
name
,
)
def
_certificate_html_view_configuration
(
self
,
configuration_string
,
enabled
=
True
):
"""
This will create a certificate html configuration
"""
config
=
CertificateHtmlViewConfiguration
(
enabled
=
enabled
,
configuration
=
configuration_string
)
config
.
save
()
return
config
def
_add_course_certificates
(
self
,
count
=
1
,
signatory_count
=
0
,
is_active
=
True
):
"""
Create certificate for the course.
"""
signatories
=
[
{
'name'
:
'Signatory_Name '
+
str
(
i
),
'title'
:
'Signatory_Title '
+
str
(
i
),
'organization'
:
'Signatory_Organization '
+
str
(
i
),
'signature_image_path'
:
'/static/certificates/images/demo-sig{}.png'
.
format
(
i
),
'id'
:
i
,
}
for
i
in
xrange
(
signatory_count
)
]
certificates
=
[
{
'id'
:
i
,
'name'
:
'Name '
+
str
(
i
),
'description'
:
'Description '
+
str
(
i
),
'course_title'
:
'course_title_'
+
str
(
i
),
'org_logo_path'
:
'/t4x/orgX/testX/asset/org-logo-{}.png'
.
format
(
i
),
'signatories'
:
signatories
,
'version'
:
1
,
'is_active'
:
is_active
}
for
i
in
xrange
(
count
)
]
self
.
course
.
certificates
=
{
'certificates'
:
certificates
}
self
.
course
.
save
()
self
.
store
.
update_item
(
self
.
course
,
self
.
user
.
id
)
@patch
(
"microsite_configuration.microsite.get_value"
,
fakemicrosite
)
@override_settings
(
FEATURES
=
FEATURES_WITH_CERTS_ENABLED
)
def
test_html_view_for_microsite
(
self
):
test_configuration_string
=
"""{
"default": {
"accomplishment_class_append": "accomplishment-certificate",
"platform_name": "edX",
"company_about_url": "http://www.edx.org/about-us",
"company_privacy_url": "http://www.edx.org/edx-privacy-policy",
"company_tos_url": "http://www.edx.org/edx-terms-service",
"company_verified_certificate_url": "http://www.edx.org/verified-certificate",
"document_stylesheet_url_application": "/static/certificates/sass/main-ltr.css",
"logo_src": "/static/certificates/images/logo-edx.svg",
"logo_url": "http://www.edx.org"
},
"test_microsite": {
"accomplishment_class_append": "accomplishment-certificate",
"platform_name": "platform_microsite",
"company_about_url": "http://www.microsite.org/about-us",
"company_privacy_url": "http://www.microsite.org/edx-privacy-policy",
"company_tos_url": "http://www.microsite.org/microsite-terms-service",
"company_verified_certificate_url": "http://www.microsite.org/verified-certificate",
"document_stylesheet_url_application": "/static/certificates/sass/main-ltr.css",
"logo_src": "/static/certificates/images/logo-microsite.svg",
"logo_url": "http://www.microsite.org",
"company_about_description": "This is special microsite aware company_about_description content",
"company_about_title": "Microsite title"
},
"honor": {
"certificate_type": "Honor Code",
"document_body_class_append": "is-honorcode"
}
}"""
config
=
self
.
_certificate_html_view_configuration
(
configuration_string
=
test_configuration_string
)
self
.
assertEquals
(
config
.
configuration
,
test_configuration_string
)
test_url
=
get_certificate_url
(
user_id
=
self
.
user
.
id
,
course_id
=
self
.
course
.
id
.
to_deprecated_string
()
# pylint: disable=no-member
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
response
=
self
.
client
.
get
(
test_url
)
self
.
assertIn
(
'platform_microsite'
,
response
.
content
)
self
.
assertIn
(
'http://www.microsite.org'
,
response
.
content
)
self
.
assertIn
(
'This is special microsite aware company_about_description content'
,
response
.
content
)
self
.
assertIn
(
'Microsite title'
,
response
.
content
)
@patch
(
"microsite_configuration.microsite.get_value"
,
fakemicrosite
)
def
test_html_view_microsite_configuration_missing
(
self
):
test_configuration_string
=
"""{
"default": {
"accomplishment_class_append": "accomplishment-certificate",
"platform_name": "edX",
"company_about_url": "http://www.edx.org/about-us",
"company_privacy_url": "http://www.edx.org/edx-privacy-policy",
"company_tos_url": "http://www.edx.org/edx-terms-service",
"company_verified_certificate_url": "http://www.edx.org/verified-certificate",
"document_stylesheet_url_application": "/static/certificates/sass/main-ltr.css",
"logo_src": "/static/certificates/images/logo-edx.svg",
"logo_url": "http://www.edx.org",
"company_about_description": "This should not survive being overwritten by static content"
},
"honor": {
"certificate_type": "Honor Code",
"document_body_class_append": "is-honorcode"
}
}"""
config
=
self
.
_certificate_html_view_configuration
(
configuration_string
=
test_configuration_string
)
self
.
assertEquals
(
config
.
configuration
,
test_configuration_string
)
test_url
=
get_certificate_url
(
user_id
=
self
.
user
.
id
,
course_id
=
self
.
course
.
id
.
to_deprecated_string
()
# pylint: disable=no-member
)
self
.
_add_course_certificates
(
count
=
1
,
signatory_count
=
2
)
response
=
self
.
client
.
get
(
test_url
)
self
.
assertIn
(
'edX'
,
response
.
content
)
self
.
assertNotIn
(
'platform_microsite'
,
response
.
content
)
self
.
assertNotIn
(
'http://www.microsite.org'
,
response
.
content
)
self
.
assertNotIn
(
'This should not survive being overwritten by static content'
,
response
.
content
)
@attr
(
'shard_1'
)
class
CertificatesViewsTests
(
ModuleStoreTestCase
,
EventTrackingTestCase
):
"""
...
...
lms/djangoapps/certificates/views.py
View file @
4dd55609
"""URL handlers related to certificate handling by LMS"""
from
microsite_configuration
import
microsite
from
datetime
import
datetime
from
uuid
import
uuid4
from
django.shortcuts
import
redirect
,
get_object_or_404
...
...
@@ -284,7 +285,7 @@ def _update_certificate_context(context, course, user, user_certificate):
"""
# Populate dynamic output values using the course/certificate data loaded above
user_fullname
=
user
.
profile
.
name
platform_name
=
context
.
get
(
'platform_name'
)
platform_name
=
microsite
.
get_value
(
"platform_name"
,
settings
.
PLATFORM_NAME
)
certificate_type
=
context
.
get
(
'certificate_type'
)
context
[
'username'
]
=
user
.
username
...
...
@@ -460,18 +461,24 @@ def render_html_view(request, user_id, course_id):
# Create the initial view context, bootstrapping with Django settings and passed-in values
context
=
{}
context
[
'platform_name'
]
=
settings
.
PLATFORM_NAME
context
[
'platform_name'
]
=
microsite
.
get_value
(
"platform_name"
,
settings
.
PLATFORM_NAME
)
context
[
'course_id'
]
=
course_id
# Update the view context with the default ConfigurationModel settings
configuration
=
CertificateHtmlViewConfiguration
.
get_config
()
context
.
update
(
configuration
.
get
(
'default'
,
{}))
# if we are in a microsite, then let's first see if there is an override
# section in our config
config_key
=
microsite
.
get_value
(
'microsite_config_key'
,
'default'
)
# if there is no special microsite override, then let's use default
if
config_key
not
in
configuration
:
config_key
=
'default'
context
.
update
(
configuration
.
get
(
config_key
,
{}))
# Translators: 'All rights reserved' is a legal term used in copyrighting to protect published content
reserved
=
_
(
"All rights reserved"
)
context
[
'copyright_text'
]
=
'© {year} {platform_name}. {reserved}.'
.
format
(
year
=
settings
.
COPYRIGHT_YEAR
,
platform_name
=
settings
.
PLATFORM_NAME
,
platform_name
=
context
.
get
(
'platform_name'
)
,
reserved
=
reserved
)
...
...
@@ -487,7 +494,7 @@ def render_html_view(request, user_id, course_id):
# Translators: This line appears as a byline to a header image and describes the purpose of the page
context
[
'logo_subtitle'
]
=
_
(
"Certificate Validation"
)
context
[
'logo_alt'
]
=
settings
.
PLATFORM_NAME
context
[
'logo_alt'
]
=
context
.
get
(
'platform_name'
)
invalid_template_path
=
'certificates/invalid.html'
# Kick the user back to the "Invalid" screen if the feature is disabled
...
...
@@ -565,6 +572,22 @@ def render_html_view(request, user_id, course_id):
# Append/Override the existing view context values with request-time values
_update_certificate_context
(
context
,
course
,
user
,
user_certificate
)
# Microsites will need to be able to override any hard coded
# content that was put into the context in the
# _update_certificate_context() call above. For example the
# 'company_about_description' talks about edX, which we most likely
# do not want to keep in a microsite
#
# So we need to re-apply any configuration/content that
# we are sourceing from the database. This is somewhat duplicative of
# the code at the beginning of this method, but we
# need the configuration at the top as some error code paths
# require that to be set up early on in the pipeline
#
microsite_config_key
=
microsite
.
get_value
(
'microsite_config_key'
)
if
microsite_config_key
:
context
.
update
(
configuration
.
get
(
microsite_config_key
,
{}))
# Append/Override the existing view context values with any course-specific static values from Advanced Settings
context
.
update
(
course
.
cert_html_view_overrides
)
...
...
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