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
0c0a5a93
Commit
0c0a5a93
authored
Sep 20, 2017
by
Tyler Hallada
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create func for common template context entries
parent
c7bfd69e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
37 deletions
+47
-37
openedx/core/djangoapps/schedules/tasks.py
+4
-37
openedx/core/djangoapps/schedules/template_context.py
+43
-0
No files found.
openedx/core/djangoapps/schedules/tasks.py
View file @
0c0a5a93
...
...
@@ -19,9 +19,9 @@ from edx_ace.recipient import Recipient
from
edx_ace.utils.date
import
deserialize
from
opaque_keys.edx.keys
import
CourseKey
from
edxmako.shortcuts
import
marketing_link
from
openedx.core.djangoapps.schedules.message_type
import
ScheduleMessageType
from
openedx.core.djangoapps.schedules.models
import
Schedule
,
ScheduleConfig
from
openedx.core.djangoapps.schedules.template_context
import
absolute_url
,
get_base_template_context
LOG
=
logging
.
getLogger
(
__name__
)
...
...
@@ -128,11 +128,9 @@ def _recurring_nudge_schedules_for_hour(target_hour, org_list, exclude_orgs=Fals
user_schedules
=
list
(
user_schedules
)
course_id_strs
=
[
str
(
schedule
.
enrollment
.
course_id
)
for
schedule
in
user_schedules
]
def
absolute_url
(
relative_path
):
return
u'{}{}'
.
format
(
settings
.
LMS_ROOT_URL
,
urlquote
(
relative_path
))
first_schedule
=
user_schedules
[
0
]
template_context
=
{
template_context
=
get_base_template_context
()
template_context
.
update
({
'student_name'
:
user
.
profile
.
name
,
'course_name'
:
first_schedule
.
enrollment
.
course
.
display_name
,
...
...
@@ -140,36 +138,5 @@ def _recurring_nudge_schedules_for_hour(target_hour, org_list, exclude_orgs=Fals
# This is used by the bulk email optout policy
'course_ids'
:
course_id_strs
,
# Platform information
'homepage_url'
:
encode_url
(
marketing_link
(
'ROOT'
)),
'dashboard_url'
:
absolute_url
(
dashboard_relative_url
),
'template_revision'
:
settings
.
EDX_PLATFORM_REVISION
,
'platform_name'
:
settings
.
PLATFORM_NAME
,
'contact_mailing_address'
:
settings
.
CONTACT_MAILING_ADDRESS
,
'social_media_urls'
:
encode_urls_in_dict
(
getattr
(
settings
,
'SOCIAL_MEDIA_FOOTER_URLS'
,
{})),
'mobile_store_urls'
:
encode_urls_in_dict
(
getattr
(
settings
,
'MOBILE_STORE_URLS'
,
{})),
}
})
yield
(
user
,
first_schedule
.
enrollment
.
course
.
language
,
template_context
)
def
encode_url
(
url
):
# Sailthru has a bug where URLs that contain "+" characters in their path components are misinterpreted
# when GA instrumentation is enabled. We need to percent-encode the path segments of all URLs that are
# injected into our templates to work around this issue.
parsed_url
=
urlparse
(
url
)
modified_url
=
parsed_url
.
_replace
(
path
=
urlquote
(
parsed_url
.
path
))
return
modified_url
.
geturl
()
def
absolute_url
(
relative_path
):
root
=
settings
.
LMS_ROOT_URL
.
rstrip
(
'/'
)
relative_path
=
relative_path
.
lstrip
(
'/'
)
return
encode_url
(
u'{root}/{path}'
.
format
(
root
=
root
,
path
=
relative_path
))
def
encode_urls_in_dict
(
mapping
):
urls
=
{}
for
key
,
value
in
mapping
.
iteritems
():
urls
[
key
]
=
encode_url
(
value
)
return
urls
openedx/core/djangoapps/schedules/template_context.py
0 → 100644
View file @
0c0a5a93
from
urlparse
import
urlparse
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
django.utils.http
import
urlquote
from
edxmako.shortcuts
import
marketing_link
def
get_base_template_context
():
"""Dict with entries needed for all templates that use the base template"""
return
{
# Platform information
'homepage_url'
:
encode_url
(
marketing_link
(
'ROOT'
)),
'dashboard_url'
:
absolute_url
(
reverse
(
'dashboard'
)),
'template_revision'
:
settings
.
EDX_PLATFORM_REVISION
,
'platform_name'
:
settings
.
PLATFORM_NAME
,
'contact_mailing_address'
:
settings
.
CONTACT_MAILING_ADDRESS
,
'social_media_urls'
:
encode_urls_in_dict
(
getattr
(
settings
,
'SOCIAL_MEDIA_FOOTER_URLS'
,
{})),
'mobile_store_urls'
:
encode_urls_in_dict
(
getattr
(
settings
,
'MOBILE_STORE_URLS'
,
{})),
}
def
encode_url
(
url
):
# Sailthru has a bug where URLs that contain "+" characters in their path components are misinterpreted
# when GA instrumentation is enabled. We need to percent-encode the path segments of all URLs that are
# injected into our templates to work around this issue.
parsed_url
=
urlparse
(
url
)
modified_url
=
parsed_url
.
_replace
(
path
=
urlquote
(
parsed_url
.
path
))
return
modified_url
.
geturl
()
def
absolute_url
(
relative_path
):
root
=
settings
.
LMS_ROOT_URL
.
rstrip
(
'/'
)
relative_path
=
relative_path
.
lstrip
(
'/'
)
return
encode_url
(
u'{root}/{path}'
.
format
(
root
=
root
,
path
=
relative_path
))
def
encode_urls_in_dict
(
mapping
):
urls
=
{}
for
key
,
value
in
mapping
.
iteritems
():
urls
[
key
]
=
encode_url
(
value
)
return
urls
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