Repository: ocadotechnology/codeforlife-portal

Issue:
Make JS function for sticky subnav
For the moment the JS for the sticky sub-nav bar is executed directly from within the HTML files. The code should be written in an external JS file and then included in the HTML pages which need it. Mentioned in #330.

eg. https://github.com/ocadotechnology/codeforlife-portal/pull/330#discussion-diff-102530788R300


Discussion:

Resolving patch:
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
@@ -214,12 +214,34 @@ def teacher_view_class(request, access_code):
 
     check_user_is_authorised(request, klass)
 
+    if request.method == 'POST':
+        new_students_form = StudentCreationForm(klass, request.POST)
+        if new_students_form.is_valid():
+            name_tokens = []
+            for name in new_students_form.strippedNames:
+                password = generate_password(6)
+                name_tokens.append({'name': name, 'password': password})
+
+                Student.objects.schoolFactory(
+                    klass=klass,
+                    name=name,
+                    password=password)
+
+            return render(request, 'redesign/teach_new/onboarding_print.html',
+                          {'class': klass,
+                           'name_tokens': name_tokens,
+                           'onboarding_done': True,
+                           'query_data': json.dumps(name_tokens)})
+    else:
+        new_students_form = StudentCreationForm(klass)
+
     classes = Class.objects.filter(teacher=teacher)
 
     return render(request, 'redesign/teach_new/class_new.html',
                   {'class': klass,
                    'classes': classes,
                    'students': students,
+                   'new_students_form': new_students_form,
                    'num_students': len(students)})
 
 


Test patch:
diff --git a/portal/tests/pageObjects/portal/teach/class_page_new.py b/portal/tests/pageObjects/portal/teach/class_page_new.py
new file mode 100644
--- /dev/null
+++ b/portal/tests/pageObjects/portal/teach/class_page_new.py
@@ -0,0 +1,59 @@
+# -*- 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 teach_base_page_new import TeachBasePage
+import onboarding_student_list_page
+
+
+class TeachClassPage(TeachBasePage):
+    def __init__(self, browser):
+        super(TeachClassPage, self).__init__(browser)
+
+        assert self.on_correct_page('teach_class_page')
+
+    def type_student_name(self, name):
+        self.browser.find_element_by_id('id_names').send_keys(name + '\n')
+        return self
+
+    def create_students(self):
+        self._click_create_students()
+        return onboarding_student_list_page.OnboardingStudentListPage(self.browser)
+
+    def _click_create_students(self):
+        self.browser.find_element_by_name('new_students').click()
+
+    def student_exists(self, name):
+        return name in self.browser.find_element_by_id('student_table').text
diff --git a/portal/tests/pageObjects/portal/teach/dashboard_page_new.py b/portal/tests/pageObjects/portal/teach/dashboard_page_new.py
--- a/portal/tests/pageObjects/portal/teach/dashboard_page_new.py
+++ b/portal/tests/pageObjects/portal/teach/dashboard_page_new.py
@@ -35,6 +35,7 @@
 # program; modified versions of the program must be marked as such and not
 # identified as the original program.
 from teach_base_page_new import TeachBasePage
+from class_page_new import TeachClassPage
 from selenium.webdriver.support.ui import Select
 
 
@@ -44,6 +45,10 @@ def __init__(self, browser):
 
         assert self.on_correct_page('teach_dashboard_page_new')
 
+    def go_to_class_page(self):
+        self.browser.find_element_by_id('class_button').click()
+        return TeachClassPage(self.browser)
+
     def check_organisation_details(self, details):
         correct = True
 
diff --git a/portal/tests/pageObjects/portal/teach/onboarding_student_list_page.py b/portal/tests/pageObjects/portal/teach/onboarding_student_list_page.py
--- a/portal/tests/pageObjects/portal/teach/onboarding_student_list_page.py
+++ b/portal/tests/pageObjects/portal/teach/onboarding_student_list_page.py
@@ -37,6 +37,7 @@
 from selenium.webdriver.support.ui import Select
 
 from teach_base_page_new import TeachBasePage
+import class_page_new
 
 
 class OnboardingStudentListPage(TeachBasePage):
@@ -47,3 +48,7 @@ def __init__(self, browser):
 
     def student_exists(self, name):
         return name in self.browser.find_element_by_id('student_table').text
+
+    def go_back_to_class(self):
+        self.browser.find_element_by_id("back_to_class_button").click()
+        return class_page_new.TeachClassPage(self.browser)
diff --git a/portal/tests/test_teacher_student_new.py b/portal/tests/test_teacher_student_new.py
--- a/portal/tests/test_teacher_student_new.py
+++ b/portal/tests/test_teacher_student_new.py
@@ -40,7 +40,7 @@
 from utils.teacher_new import signup_teacher_directly
 from utils.organisation_new import create_organisation_directly
 from utils.classes_new import create_class_directly
-from utils.student_new import create_school_student, create_many_school_students
+from utils.student_new import create_school_student, create_many_school_students, create_school_student_directly
 
 from django_selenium_clean import selenium
 
@@ -48,7 +48,7 @@
 class TestTeacherStudent(BaseTest):
     def test_create(self):
         email, password = signup_teacher_directly()
-        org_name, postcode = create_organisation_directly(email)
+        create_organisation_directly(email)
         _, class_name, access_code = create_class_directly(email)
 
         selenium.get(self.live_server_url + "/portal/redesign/home")
@@ -61,7 +61,7 @@ def test_create(self):
 
     def test_create_empty(self):
         email, password = signup_teacher_directly()
-        org_name, postcode = create_organisation_directly(email)
+        create_organisation_directly(email)
         _, class_name, access_code = create_class_directly(email)
 
         selenium.get(self.live_server_url + "/portal/redesign/home")
@@ -71,7 +71,7 @@ def test_create_empty(self):
 
     def test_create_multiple(self):
         email, password = signup_teacher_directly()
-        org_name, postcode = create_organisation_directly(email)
+        create_organisation_directly(email)
         _, class_name, access_code = create_class_directly(email)
 
         selenium.get(self.live_server_url + "/portal/redesign/home")
@@ -84,7 +84,7 @@ def test_create_multiple(self):
 
     def test_create_duplicate(self):
         email, password = signup_teacher_directly()
-        org_name, postcode = create_organisation_directly(email)
+        create_organisation_directly(email)
         _, class_name, access_code = create_class_directly(email)
 
         student_name = 'bob'
@@ -95,3 +95,19 @@ def test_create_duplicate(self):
         page = page.type_student_name(student_name).type_student_name(student_name).create_students_failure()
         assert page.adding_students_failed()
         assert page.duplicate_students(student_name)
+
+    def test_add_to_existing_class(self):
+        email, password = signup_teacher_directly()
+        create_organisation_directly(email)
+        _, class_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).go_to_login_page().login(email, password).go_to_class_page()
+
+        page, new_student_name = create_school_student(page)
+        assert page.student_exists(new_student_name)
+
+        page = page.go_back_to_class()
+
+        assert page.student_exists(new_student_name)