Repository: ocadotechnology/codeforlife-portal

Issue:
Teaching resources - links to PDFs & materials



Discussion:

Resolving patch:
diff --git a/portal/urls.py b/portal/urls.py
--- a/portal/urls.py
+++ b/portal/urls.py
@@ -68,7 +68,8 @@
 from portal.views.email_new import verify_email_new, change_email
 from portal.views.home_new import login_view, logout_view_new, register_view
 from portal.views.organisation_new import organisation_fuzzy_lookup_new, organisation_manage_new
-from portal.views.teacher.teach_new import teacher_classes_new, teacher_class_new, teacher_print_reminder_cards_new
+from portal.views.teacher.teach_new import teacher_classes_new, teacher_class_new, \
+    materials_viewer_new, teacher_print_reminder_cards_new
 from portal.views.teacher.dashboard import dashboard_manage
 
 js_info_dict = {
@@ -217,7 +218,8 @@
     url(r'^redesign/about', TemplateView.as_view(template_name='redesign/about_new.html'), name='about_new'),
     url(r'^redesign/help', TemplateView.as_view(template_name='redesign/help-and-support_new.html'), name='help_new'),
     url(r'^redesign/terms', TemplateView.as_view(template_name='redesign/terms_new.html'), name='terms_new'),
-    url(r'^redesign/teach/materials', TemplateView.as_view(template_name='redesign/teach_new/materials_new.html'), name='materials_new'),
+    url(r'^redesign/teach/materials/$', TemplateView.as_view(template_name='redesign/teach_new/materials_new.html'), name='materials_new'),
+    url(r'^redesign/teach/materials/(?P<pdf_name>[a-zA-Z0-9\/\-_]+)$', materials_viewer_new, name='materials_viewer_new'),
     url(r'^redesign/teach/dashboard', dashboard_manage, name='dashboard'),
     url(r'^redesign/teach/class', TemplateView.as_view(template_name='redesign/teach_new/class_new.html'), name='class_new'),
 
diff --git a/portal/views/teacher/teach_new.py b/portal/views/teacher/teach_new.py
--- a/portal/views/teacher/teach_new.py
+++ b/portal/views/teacher/teach_new.py
@@ -56,10 +56,60 @@
 from portal.forms.teach_new import ClassCreationForm, StudentCreationForm
 from portal.permissions import logged_in_as_teacher
 from portal.helpers.generators import generate_access_code, generate_password
+from portal.views.teacher.pdfs import PDF_DATA
+from portal.templatetags.app_tags import cloud_storage
 
 
-@login_required(login_url=reverse_lazy('home_new'))
-@user_passes_test(logged_in_as_teacher, login_url=reverse_lazy('home_new'))
+@login_required(login_url=reverse_lazy('login_new'))
+@user_passes_test(logged_in_as_teacher, login_url=reverse_lazy('login_new'))
+def materials_viewer_new(request, pdf_name):
+
+    def _getLinks():
+        links = PDF_DATA[pdf_name]['links']
+        link_titles = []
+        for link in links:
+            link = link.replace('_', ' ').title()
+
+            if (link[0] == 'K') | (link[1] == 'k'):
+                link = link[:4].upper() + link[4:]
+
+            link_titles.append(link)
+
+        return zip(links, link_titles)
+
+    try:
+        title = PDF_DATA[pdf_name]['title']
+        description = PDF_DATA[pdf_name]['description']
+        url = cloud_storage(PDF_DATA[pdf_name]['url'])
+        page_origin = PDF_DATA[pdf_name]['page_origin']
+
+    except KeyError:
+        raise Http404
+
+    if PDF_DATA[pdf_name]['links'] is not None:
+        links = _getLinks()
+    else:
+        links = None
+
+    if 'video' in PDF_DATA[pdf_name]:
+        video_link = PDF_DATA[pdf_name]['video']
+        video_download_link = cloud_storage(PDF_DATA[pdf_name]['video_download_link'])
+    else:
+        video_link = None
+        video_download_link = None
+
+    return render(request, 'redesign/teach_new/viewer_new.html',
+                  {'title': title,
+                   'description': description,
+                   'url': url,
+                   'links': links,
+                   'video_link': video_link,
+                   'video_download_link': video_download_link,
+                   'page_origin': page_origin})
+
+
+@login_required(login_url=reverse_lazy('login_new'))
+@user_passes_test(logged_in_as_teacher, login_url=reverse_lazy('login_new'))
 def teacher_classes_new(request):
     teacher = request.user.new_teacher
     requests = Student.objects.filter(pending_class_request__teacher=teacher)
@@ -97,8 +147,8 @@ def create_class_new(form, teacher):
     return klass
 
 
-@login_required(login_url=reverse_lazy('home_new'))
-@user_passes_test(logged_in_as_teacher, login_url=reverse_lazy('home_new'))
+@login_required(login_url=reverse_lazy('login_new'))
+@user_passes_test(logged_in_as_teacher, login_url=reverse_lazy('login_new'))
 def teacher_class_new(request, access_code):
     klass = get_object_or_404(Class, access_code=access_code)
     teacher = request.user.new_teacher


Test patch:
diff --git a/portal/tests/pageObjects/portal/base_page.py b/portal/tests/pageObjects/portal/base_page.py
--- a/portal/tests/pageObjects/portal/base_page.py
+++ b/portal/tests/pageObjects/portal/base_page.py
@@ -54,9 +54,6 @@ def wait_for_element_by_id(self, id, wait_seconds=DEFAULT_WAIT_SECONDS):
     def wait_for_element_by_css(self, css, wait_seconds=DEFAULT_WAIT_SECONDS):
         self.wait_for_presence((By.CSS_SELECTOR, css), wait_seconds)
 
-    def wait_for_element_by_xpath(self, xpath, wait_seconds=DEFAULT_WAIT_SECONDS):
-        self.wait_for_presence((By.XPATH, xpath), wait_seconds)
-
     def wait_for_element_to_be_clickable(self, locator, wait_seconds=DEFAULT_WAIT_SECONDS):
         self.wait(EC.element_to_be_clickable(locator), wait_seconds)
 
@@ -131,10 +128,6 @@ def go_to_teach_page(self):
         self.browser.find_element_by_id('teach_button').click()
         return teach_page.TeachPage(self.browser)
 
-    def go_to_login_page(self):
-        self.browser.find_element_by_id('login_button').click()
-        return login_page.LoginPage(self.browser)
-
     def go_to_signup_page(self):
         self.browser.find_element_by_id('signup_button').click()
         return signup_page.SignupPage(self.browser)
@@ -143,6 +136,10 @@ def go_to_terms_page(self):
         self.browser.find_element_by_id('terms_button').click()
         return terms_page.TermsPage(self.browser)
 
+    def go_to_resources_page(self):
+        self.browser.find_element_by_id('resources_button').click()
+        return resources_page.ResourcesPage(self.browser)
+
     def is_on_admin_login_page(self):
         return self.on_correct_page('admin_login')
 
@@ -175,3 +172,4 @@ def was_form_empty(self, formID):
 import login_page
 import signup_page
 import terms_page
+import resources_page
diff --git a/portal/tests/pageObjects/portal/pdf_viewer_page.py b/portal/tests/pageObjects/portal/pdf_viewer_page.py
new file mode 100644
--- /dev/null
+++ b/portal/tests/pageObjects/portal/pdf_viewer_page.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+# Code for Life
+#
+# Copyright (C) 2016, Ocado Innovation Limited
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# ADDITIONAL TERMS – Section 7 GNU General Public Licence
+#
+# This licence does not grant any right, title or interest in any “Ocado” logos,
+# trade names or the trademark “Ocado” or any other trademarks or domain names
+# owned by Ocado Innovation Limited or the Ocado group of companies or any other
+# distinctive brand features of “Ocado” as may be secured from time to time. You
+# must not distribute any modification of this program using the trademark
+# “Ocado” or claim any affiliation or association with Ocado or its employees.
+#
+# You are not authorised to use the name Ocado (or any of its trade names) or
+# the names of any author or contributor in advertising or for publicity purposes
+# pertaining to the distribution of this program, without the prior written
+# authorisation of Ocado.
+#
+# Any propagation, distribution or conveyance of this program must include this
+# copyright notice and these terms. You must not misrepresent the origins of this
+# program; modified versions of the program must be marked as such and not
+# identified as the original program.
+from base_page import BasePage
+
+
+class PDFViewerPage(BasePage):
+    def __init__(self, browser):
+        super(PDFViewerPage, self).__init__(browser)
+
+        assert self.on_correct_page('pdf_viewer_page')
diff --git a/portal/tests/pageObjects/portal/resources_page.py b/portal/tests/pageObjects/portal/resources_page.py
new file mode 100644
--- /dev/null
+++ b/portal/tests/pageObjects/portal/resources_page.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+# Code for Life
+#
+# Copyright (C) 2016, Ocado Innovation Limited
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# ADDITIONAL TERMS – Section 7 GNU General Public Licence
+#
+# This licence does not grant any right, title or interest in any “Ocado” logos,
+# trade names or the trademark “Ocado” or any other trademarks or domain names
+# owned by Ocado Innovation Limited or the Ocado group of companies or any other
+# distinctive brand features of “Ocado” as may be secured from time to time. You
+# must not distribute any modification of this program using the trademark
+# “Ocado” or claim any affiliation or association with Ocado or its employees.
+#
+# You are not authorised to use the name Ocado (or any of its trade names) or
+# the names of any author or contributor in advertising or for publicity purposes
+# pertaining to the distribution of this program, without the prior written
+# authorisation of Ocado.
+#
+# Any propagation, distribution or conveyance of this program must include this
+# copyright notice and these terms. You must not misrepresent the origins of this
+# program; modified versions of the program must be marked as such and not
+# identified as the original program.
+from base_page import BasePage
+import pdf_viewer_page
+
+
+class ResourcesPage(BasePage):
+    def __init__(self, browser):
+        super(ResourcesPage, self).__init__(browser)
+
+        assert self.on_correct_page('resources_page')
+
+    def click_pdf_link(self):
+        self.browser.find_element_by_id('pdf_link').click()
+        return pdf_viewer_page.PDFViewerPage(self.browser)
diff --git a/portal/tests/test_teacher_new.py b/portal/tests/test_teacher_new.py
--- a/portal/tests/test_teacher_new.py
+++ b/portal/tests/test_teacher_new.py
@@ -83,6 +83,26 @@ def test_signup_login_success(self):
         page = page.login_no_school(email, password)
         assert self.is_onboarding_page(page)
 
+    def test_view_resources(self):
+        email, password = signup_teacher_directly()
+        create_organisation_directly(email)
+        klass, name, access_code = create_class_directly(email)
+        create_school_student_directly(access_code)
+        selenium.get(self.live_server_url + "/portal/redesign/home")
+        page = HomePage(selenium)
+        page = page.go_to_login_page()
+        page = page.login(email, password)
+
+        assert self.is_dashboard_page(page)
+
+        page = page.go_to_resources_page()
+
+        assert self.is_resources_page(page)
+
+        page = page.click_pdf_link()
+
+        assert self.is_pdf_viewer_page(page)
+
     def test_edit_details(self):
         email, password = signup_teacher_directly()
         create_organisation_directly(email)
@@ -135,5 +155,11 @@ def test_change_email(self):
     def is_dashboard_page(self, page):
         return page.__class__.__name__ == 'TeachDashboardPage'
 
+    def is_resources_page(self, page):
+        return page.__class__.__name__ == 'ResourcesPage'
+
+    def is_pdf_viewer_page(self, page):
+        return page.__class__.__name__ == 'PDFViewerPage'
+
     def is_onboarding_page(self, page):
         return page.__class__.__name__ == 'OnboardingOrganisationPage'