From 0ce17fe39bc6254ad4c911bb5810710cdd4ba871 Mon Sep 17 00:00:00 2001
From: HanseGucker <joniweth@gmx.de>
Date: Sun, 6 Jan 2019 17:11:01 +0100
Subject: [PATCH] Last bugs

---
 .../timetable/templates/timetable/myplan.html |  2 +-
 .../templates/timetable/substitution.html     | 60 +------------------
 schoolapps/timetable/views.py                 | 10 ++--
 schoolapps/untisconnect/api.py                |  6 +-
 schoolapps/untisconnect/plan.py               | 12 ++--
 5 files changed, 19 insertions(+), 71 deletions(-)

diff --git a/schoolapps/timetable/templates/timetable/myplan.html b/schoolapps/timetable/templates/timetable/myplan.html
index 8d0ac5933..4e0ef9400 100644
--- a/schoolapps/timetable/templates/timetable/myplan.html
+++ b/schoolapps/timetable/templates/timetable/myplan.html
@@ -15,7 +15,7 @@
     </div>
     {#    <h5>{{ date|date:"l, j. F Y" }}</h5>#}
     <div class="row">
-        <div class="timetable-plan col s12 m6">
+        <div class="timetable-plan col s12 m12 l6">
 
             {#  Week days #}
             <div class="row">
diff --git a/schoolapps/timetable/templates/timetable/substitution.html b/schoolapps/timetable/templates/timetable/substitution.html
index c33db779c..3dca3e138 100755
--- a/schoolapps/timetable/templates/timetable/substitution.html
+++ b/schoolapps/timetable/templates/timetable/substitution.html
@@ -1,49 +1,8 @@
 {% include 'partials/header.html' %}
 
-<script type="text/javascript">
-    function updateDatepicker() {
-        $("#date").val(formatDate(activeDate));
-    }
-
-    function update() {
-        console.log("Render new.");
-
-        updateDatepicker();
-    }
-
-    function loadNew() {
-        window.location.href = "/timetable/substitutions/" + formatDateForDjango(activeDate);
-    }
-
-    function onDateBeforeClick() {
-        activeDate.setDate(activeDate.getDate() - 1);
-        update();
-        loadNew();
-    }
-
-    function onDateNextClick() {
-        activeDate.setDate(activeDate.getDate() + 1);
-        update();
-        loadNew();
-    }
 
-    function onDateChanged() {
-        var str = $("#date").val();
-        var split = str.split(".")
-        activeDate = new Date(split[2], split[1] - 1, split[0]);
-        update();
-        loadNew();
-    }
-
-    var activeDate = new Date({{ date_js }});
-
-    $(document).ready(function () {
-        $("#date-before").click(onDateBeforeClick);
-        $("#date-next").click(onDateNextClick);
-        $("#date").change(onDateChanged);
-
-        update();
-    })
+<script type="text/javascript">
+    var dest = "/timetable/substitutions/";
 </script>
 
 <main>
@@ -51,20 +10,7 @@
 
     <div class="row no-print">
         <div class="col s12 m6 l4 xl3">
-            <div class="col s2">
-                <a class="waves-effect waves-teal btn-flat btn-flat-medium right" id="date-before">
-                    <i class="material-icons center">navigate_before</i>
-                </a>
-
-            </div>
-            <div class="col s8">
-                <input type="text" class="datepicker center-align" id="date">
-            </div>
-            <div class="col s2">
-                <a class="waves-effect waves-teal btn-flat btn-flat-medium left" id="date-next">
-                    <i class="material-icons center">navigate_next</i>
-                </a>
-            </div>
+            {% include "timetable/datepicker.html" %}
         </div>
         <div class="col l4 xl6">
         </div>
diff --git a/schoolapps/timetable/views.py b/schoolapps/timetable/views.py
index fcd5e91e2..91b5aa970 100755
--- a/schoolapps/timetable/views.py
+++ b/schoolapps/timetable/views.py
@@ -85,7 +85,7 @@ def plan(request, plan_type, plan_id, smart="", year=timezone.datetime.now().yea
         smart = False
 
     monday_of_week = get_calendar_week(calendar_week, year)["first_day"]
-    print(monday_of_week)
+    # print(monday_of_week)
 
     if plan_type == 'teacher':
         _type = TYPE_TEACHER
@@ -136,16 +136,16 @@ def my_plan(request, year=None, day=None, month=None):
         shortcode = request.user.username
         el = get_teacher_by_shortcode(shortcode)
         plan_id = el.id
-        print(el)
+        # print(el)
     elif _type == UserInformation.STUDENT:
         _type = TYPE_CLASS
         _name = UserInformation.user_classes(request.user)[0]
-        print(_name)
+        # print(_name)
         el = get_class_by_name(_name)
         plan_id = el.id
     else:
         redirect("timetable_admin_all")
-    print(monday_of_week)
+    # print(monday_of_week)
 
     plan = get_plan(_type, plan_id, smart=True, monday_of_week=monday_of_week)
     # print(parse_lesson_times())
@@ -161,7 +161,7 @@ def my_plan(request, year=None, day=None, month=None):
         "date": date,
         "date_js": int(date.timestamp()) * 1000
     }
-    print(context["week_day"])
+    # print(context["week_day"])
 
     return render(request, 'timetable/myplan.html', context)
 
diff --git a/schoolapps/untisconnect/api.py b/schoolapps/untisconnect/api.py
index c769ab2d2..96cd58971 100755
--- a/schoolapps/untisconnect/api.py
+++ b/schoolapps/untisconnect/api.py
@@ -86,6 +86,7 @@ def get_teacher_by_id(id):
 
 
 def get_teacher_by_shortcode(shortcode):
+    shortcode = shortcode.upper()
     teacher = run_one(models.Teacher.objects).get(name__icontains=shortcode)
     return one_by_id(teacher, Teacher)
 
@@ -131,7 +132,8 @@ def get_class_by_id(id):
 
 
 def get_class_by_name(name):
-    _class = run_one(models.Class.objects).get(name__icontains=name)
+    name = name[0].upper() + name[1:]
+    _class = run_one(models.Class.objects).filter(name__icontains=name).all()[0]
     return one_by_id(_class, Class)
 
 
@@ -195,7 +197,7 @@ def get_all_corridors():
 
 
 def get_corridor_by_id(id):
-    print(id)
+    # print(id)
     corridor = run_one(models.Corridor.objects, filter_term=False).get(corridor_id=id)
     return one_by_id(corridor, Corridor)
 
diff --git a/schoolapps/untisconnect/plan.py b/schoolapps/untisconnect/plan.py
index 7e20ae942..e20dd18f5 100644
--- a/schoolapps/untisconnect/plan.py
+++ b/schoolapps/untisconnect/plan.py
@@ -67,16 +67,16 @@ def get_plan(type, id, smart=False, monday_of_week=None):
     times_parsed = parse_lesson_times()
 
     if smart:
-        print("Get substitutions for smart plan")
+        # print("Get substitutions for smart plan")
         week_days = [monday_of_week + datetime.timedelta(days=i) for i in range(5)]
-        print(week_days)
+        # print(week_days)
         subs_for_weekday = []
         for week_day in week_days:
-            print(week_day)
+            # print(week_day)
             subs = get_substitutions_by_date_as_dict(week_day)
             subs_for_weekday.append(subs)
-            print(subs)
-            print(len(subs))
+            # print(subs)
+            # print(len(subs))
     # Init plan array
     plan = []
     already_added_subs_as_ids = []
@@ -107,7 +107,7 @@ def get_plan(type, id, smart=False, monday_of_week=None):
                 for time in lesson.times:
                     for j, lroom in enumerate(time.rooms):
                         if lroom.id == id:
-                            print(lroom.name)
+                            # print(lroom.name)
                             found = True
 
             # If the lesson element is important then add it to plan array
-- 
GitLab