Merge pull request #17145 from edx/waheed/LEARNER-3754-update-my-program-detail-url-for-mobile

Update program detail fragment url for mobile apps.
This commit is contained in:
Waheed Ahmed
2018-01-11 12:42:23 +05:00
committed by GitHub
3 changed files with 42 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
"""
Fragments for rendering programs.
"""
import json
from django.http import Http404
from django.template.loader import render_to_string
from django.utils.translation import get_language_bidi
@@ -30,11 +32,12 @@ class ProgramsFragmentView(EdxFragmentView):
Render the program listing fragment.
"""
user = request.user
mobile_only = json.loads(request.GET.get('mobile_only', 'false'))
programs_config = kwargs.get('programs_config') or ProgramsApiConfig.current()
if not programs_config.enabled or not user.is_authenticated():
raise Http404
meter = ProgramProgressMeter(request.site, user)
meter = ProgramProgressMeter(request.site, user, mobile_only=mobile_only)
context = {
'marketing_url': get_program_marketing_url(programs_config),

View File

@@ -717,6 +717,33 @@ class TestProgramProgressMeter(TestCase):
self.assertEqual(meter.progress(count_only=False), expected)
def test_detail_url_for_mobile_only(self, mock_get_programs):
"""
Verify that correct program detail url is returned for mobile.
"""
course_run_key = generate_course_run_key()
data = [
ProgramFactory(
courses=[
CourseFactory(course_runs=[
CourseRunFactory(key=course_run_key),
]),
]
),
ProgramFactory(),
]
mock_get_programs.return_value = data
self._create_enrollments(course_run_key)
meter = ProgramProgressMeter(self.site, self.user, mobile_only=True)
program_data = meter.engaged_programs[0]
detail_fragment_url = reverse('program_details_fragment_view', kwargs={'program_uuid': program_data['uuid']})
path_id = detail_fragment_url.replace('/dashboard/', '')
expected_url = 'edxapp://enrolled_program_info?path_id={}'.format(path_id)
self.assertEqual(program_data['detail_url'], expected_url)
def _create_course(self, course_price, course_run_count=1, make_entitlement=False):
"""

View File

@@ -43,7 +43,7 @@ def get_program_marketing_url(programs_config):
return urljoin(settings.MKTG_URLS.get('ROOT'), programs_config.marketing_path).rstrip('/')
def attach_program_detail_url(programs):
def attach_program_detail_url(programs, mobile_only=False):
"""Extend program representations by attaching a URL to be used when linking to program details.
Facilitates the building of context to be passed to templates containing program data.
@@ -55,7 +55,14 @@ def attach_program_detail_url(programs):
list, containing extended program dicts
"""
for program in programs:
program['detail_url'] = reverse('program_details_view', kwargs={'program_uuid': program['uuid']})
if mobile_only:
detail_fragment_url = reverse('program_details_fragment_view', kwargs={'program_uuid': program['uuid']})
path_id = detail_fragment_url.replace('/dashboard/', '')
detail_url = 'edxapp://enrolled_program_info?path_id={path_id}'.format(path_id=path_id)
else:
detail_url = reverse('program_details_view', kwargs={'program_uuid': program['uuid']})
program['detail_url'] = detail_url
return programs
@@ -72,7 +79,7 @@ class ProgramProgressMeter(object):
will only inspect this one program, not all programs the user may be
engaged with.
"""
def __init__(self, site, user, enrollments=None, uuid=None):
def __init__(self, site, user, enrollments=None, uuid=None, mobile_only=False):
self.site = site
self.user = user
@@ -99,7 +106,7 @@ class ProgramProgressMeter(object):
if uuid:
self.programs = [get_programs(self.site, uuid=uuid)]
else:
self.programs = attach_program_detail_url(get_programs(self.site))
self.programs = attach_program_detail_url(get_programs(self.site), mobile_only)
def invert_programs(self):
"""Intersect programs and enrollments.