Repository: apluslms/a-plus

Issue:
A+ front page
The A+ front page should display the name of the course instance in addition to the course name and code; Multiple instances of the same course are hard to separate in the A+ front page because the only different parts are the open/close dates and the image. Course instances have names, so that should be displayed in the front page too. Jaakko has some ideas; contact him!


Discussion:
Juha suggested that it would be nice if courses stayed on the front page somewhat longer than they are open. Students and teachers still frequently visit a course one or two months after it has ended, to check grades and for other reasons.
I had ideas that the front page could have search and filters, so e.g., FiTech student could easily find courses that are available. In addition, we could create page for courses (404 now), whcih would list all instances, shoiwng the active and future in addition past intances. Per course page is #17 .
Also this issue seems to be related #11
This issue will focus on:
1. Adding the instance name to the module-box on Front page.  
2. Dividing the front page into two sections for students and staff:
- In the upper section there should be all the courses the student is currently enrolled in OR a staff member (assistant/teacher) is currently teaching. These should show 1 month after the set ending time.
- In the bottom section there should be all the currently ongoing courses regardless whether student has enrolled in them or not. These will have the same cut-off point timewise as now, thus only currently active are showing.

The ideas about filters, search and page for different instances will continue on to separate issue after this one has been closed.  

Resolving patch:
diff --git a/course/views.py b/course/views.py
--- a/course/views.py
+++ b/course/views.py
@@ -33,17 +33,42 @@ def get_common_objects(self):
         self.welcome_text = settings_text('WELCOME_TEXT')
         self.internal_user_label = settings_text('INTERNAL_USER_LABEL')
         self.external_user_label = settings_text('EXTERNAL_USER_LABEL')
-        self.instances = []
-        prio2 = []
-        treshold = timezone.now() - datetime.timedelta(days=10)
-        for instance in CourseInstance.objects.get_visible(self.request.user)\
-                .filter(ending_time__gte=timezone.now()):
-            if instance.starting_time > treshold:
-                self.instances += [instance]
-            else:
-                prio2 += [instance]
-        self.instances += prio2
-        self.note("welcome_text", "internal_user_label", "external_user_label", "instances")
+        my_instances = []
+        all_instances = []
+        end_threshold = timezone.now() - datetime.timedelta(days=30)
+        user = self.request.user
+        is_logged_in = False
+
+        if user and user.is_authenticated:
+            is_logged_in = True
+            for instance in (CourseInstance.objects
+                .filter(course__teachers=user.userprofile,
+                        ending_time__gte=end_threshold)
+                .all()):
+                my_instances.append(instance)
+
+            for instance in user.userprofile.assisting_courses.all().filter(ending_time__gte=end_threshold):
+                if instance not in my_instances:
+                    my_instances.append(instance)
+            
+            for instance in user.userprofile.enrolled.all().filter(ending_time__gte=end_threshold):
+                if instance not in my_instances:
+                    my_instances.append(instance)
+        
+        all_instances = CourseInstance.objects.get_visible(user).filter(ending_time__gte=end_threshold)
+        all_instances = [c for c in all_instances if c not in my_instances]
+        
+        self.all_instances = all_instances
+        self.my_instances = my_instances
+        self.is_logged_in = is_logged_in
+
+        self.note("welcome_text", 
+            "internal_user_label", 
+            "external_user_label",
+            "my_instances",
+            "all_instances",
+            "is_logged_in",
+        )
 
 
 class ArchiveView(UserProfileView):


Test patch:
diff --git a/selenium_test/test/locators.py b/selenium_test/test/locators.py
--- a/selenium_test/test/locators.py
+++ b/selenium_test/test/locators.py
@@ -8,8 +8,8 @@ class LoginPageLocators(object):
 
 class FirstPageLocators(object):
     BANNER = (By.XPATH, "//*[@class='page-header']/h1")
-    APLUS_TEST_COURSE_INSTANCE_BUTTON = (By.XPATH, "//h3/a[contains(@href, '/aplus1/basic_instance/')]")
-    HOOK_EXAMPLE_BUTTON = (By.XPATH, "//h3/a[contains(@href, '/aplus1/hook_instance/')]")
+    APLUS_TEST_COURSE_INSTANCE_BUTTON = (By.XPATH, "//div[contains(@class, 'card')]/a[contains(@href, '/aplus1/basic_instance/')]//*[contains(@class, 'card-title')]")
+    HOOK_EXAMPLE_BUTTON = (By.XPATH, "//div[contains(@class, 'card')]/a[contains(@href, '/aplus1/hook_instance/')]//*[contains(@class, 'card-title')]")
 
 class BasePageLocators(object):
     COURSE_BANNER = (By.XPATH, "//*[@id='bs-navbar-collapse']/ul[1]/li[1]/a")