diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 5ace414d826e6c93413b72a6e835ff1e7b23264b..877de3bd0967f58668fbae38116c88726ff541ba 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ <project version="4"> <component name="VcsDirectoryMappings"> <mapping directory="$PROJECT_DIR$" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/schoolapps/static/materialize" vcs="Git" /> </component> </project> diff --git a/schoolapps/static/common/style.css b/schoolapps/static/common/style.css index 224529b17e421e2cdc9d1776d7808b8d6fea5e4d..660d196edebe80f097208f70ed528620d4a1916a 100755 --- a/schoolapps/static/common/style.css +++ b/schoolapps/static/common/style.css @@ -552,3 +552,19 @@ i.collapsible-trigger { /*section:not(:last-of-type) {*/ /* border-bottom: solid #bdbdbd 2px;*/ /*}*/ + + +/*++++++++ ++HOLIDAYS+ +++++++++++ */ + +.holiday-badge{ + float: left !important; + position: relative; + margin-left: 0% !important; + left: 50%; + transform: translate(-50%); + width: auto; + height: auto !important; + min-height: 26px; +} \ No newline at end of file diff --git a/schoolapps/timetable/templates/timetable/lesson.html b/schoolapps/timetable/templates/timetable/lesson.html index c7a191a07f0427b1ef47f8989a9feadd1cadf2d6..41ba8ea146776666bbeefece918d4c59c8dba085 100644 --- a/schoolapps/timetable/templates/timetable/lesson.html +++ b/schoolapps/timetable/templates/timetable/lesson.html @@ -4,17 +4,24 @@ {# Every element of the lesson #} {% for element_container in col.elements %} <div style=" - {# Display background color only if no badge exists and it is not the old room #} + + {# Display background color only if no badge exists and it is not the old room and there are no holidays #} {% if not element_container.substitution.table.badge %} {% if not element_container.is_old or type != 1 %} - background-color: {{ element_container.element.subject.hex_color }}; + {% if not element_container.is_hol %} + background-color: {{ element_container.element.subject.hex_color }}; + {% endif %} {% endif %} {% endif %}" {# Add CSS class for sub when it's a sub #} class="{% if element_container.substitution %}{% if element_container.substitution.table.is_event %}lesson-with-event{% else %}lesson-with-sub{% endif %}{% endif %}"> <p> - {% if element_container.substitution %} + {% if element_container.is_hol %} + + {# <p><strong>{ element_container.element.holiday_reason }}</strong></p>span class="badge new blue darken-2">Schulfrei</span>#} + + {% elif element_container.substitution %} {# SUBSTITUTION #} {% if type == 1 and element_container.is_old %} {# When it's the old room, let it empty #} diff --git a/schoolapps/timetable/templates/timetable/myplan.html b/schoolapps/timetable/templates/timetable/myplan.html index c2ae550c914935b62ddd77623a86cbeec67adee0..49385ff63350268bb81d24b31f0671580747e803 100644 --- a/schoolapps/timetable/templates/timetable/myplan.html +++ b/schoolapps/timetable/templates/timetable/myplan.html @@ -34,6 +34,9 @@ <div class="card-content"> <span class="card-title"> {% include "timetable/datepicker.html" %} + {% if holiday %} + <span class="badge new blue center-align holiday-badge">{{ holiday.0 }}</span> + {% endif %} </span> </div> </div> diff --git a/schoolapps/timetable/templates/timetable/plan.html b/schoolapps/timetable/templates/timetable/plan.html index 46c7f6655097cae0818c1f4f3277aca4ec93ebaf..fd42c97e861d880ddf37be88ebb7e30f058d6231 100755 --- a/schoolapps/timetable/templates/timetable/plan.html +++ b/schoolapps/timetable/templates/timetable/plan.html @@ -118,7 +118,7 @@ </div> {% include "timetable/hintsinplan.html" %} - + {# show full timetable on tablets, laptops and pcs #} <div class="timetable-plan hide-on-small-and-down"> @@ -127,26 +127,32 @@ <div class="col s2"> </div> - {# Show short weekdays on tablets #} - {% for short_week_day in short_week_days %} + {# Show short weekdays on tablets #} + {% for day in short_week_days %} <div class="col s2 hide-on-large-only"> <div class="card timetable-title-card"> <div class="card-content"> - <span class="card-title"> - {{ short_week_day }} - </span> + <span class="card-title"> + {{ day.0 }} + </span> + {% if day.1 %} + <span class="badge new blue center-align holiday-badge">{{ day.1.0 }}</span> + {% endif %} </div> </div> </div> {% endfor %} - {# Show long weekdays elsewere #} - {% for long_week_day in long_week_days %} + {# Show long weekdays elsewere #} + {% for day in long_week_days %} <div class="col s2 hide-on-med-only"> <div class="card timetable-title-card"> <div class="card-content"> - <span class="card-title"> - {{ long_week_day.0 }} - </span> + <span class="card-title"> + {{ day.0.0 }} + </span> + {% if day.1 %} + <span class="badge new blue center-align holiday-badge">{{ day.1.0 }}</span> + {% endif %} </div> </div> </div> @@ -187,11 +193,11 @@ {# show 5 seperate ones on mobiles #} <div class="timetable-plan hide-on-med-and-up"> - {% for long_week_day in long_week_days %} + {% for day in long_week_days %} <div class="card timetable-mobile-title-card"> <div class="card-content"> <span class="card-title"> - {{ long_week_day.0 }} + {{ day.0.0 }} </span> </div> </div> @@ -217,7 +223,7 @@ </div> {% for col in row %} - {% if forloop.counter0 == long_week_day.1 %} + {% if forloop.counter0 == long_week_day.0.1 %} <div class="col s8"> {# A lesson #} {% include "timetable/lesson.html" %} diff --git a/schoolapps/timetable/views.py b/schoolapps/timetable/views.py index 57868377a2ee19de12fac6dcc571c4b868cf78dc..319e374d48e522ce57267aa824801fde99876bc6 100755 --- a/schoolapps/timetable/views.py +++ b/schoolapps/timetable/views.py @@ -180,7 +180,7 @@ def plan(request, plan_type, plan_id, regular="", year=timezone.datetime.now().y raise Http404('Plan not found.') # Get plan - plan = get_plan(_type, plan_id, smart=smart, monday_of_week=monday_of_week) + plan, holidays = get_plan(_type, plan_id, smart=smart, monday_of_week=monday_of_week) context = { "smart": smart, @@ -193,8 +193,9 @@ def plan(request, plan_type, plan_id, regular="", year=timezone.datetime.now().y "weeks": get_calendar_weeks(year=year), "selected_week": calendar_week, "selected_year": year, - "short_week_days": SHORT_WEEK_DAYS, - "long_week_days": LONG_WEEK_DAYS, + "short_week_days": zip(SHORT_WEEK_DAYS, holidays), + "long_week_days": zip(LONG_WEEK_DAYS, holidays), + "holidays": holidays, "hints": hints, "hints_b": hints_b, "hints_b_mode": "week", @@ -254,7 +255,11 @@ def my_plan(request, year=None, month=None, day=None): return redirect("timetable_admin_all") # Get plan - plan = get_plan(_type, plan_id, smart=True, monday_of_week=monday_of_week) + plan, holidays = get_plan(_type, plan_id, smart=True, monday_of_week=monday_of_week) + # print(parse_lesson_times()) + + holiday_for_the_day = holidays[date.isoweekday() - 1] + # print(holiday_for_the_day) context = { "type": _type, @@ -267,6 +272,7 @@ def my_plan(request, year=None, month=None, day=None): "date": date, "date_js": int(date.timestamp()) * 1000, "display_date_only": True, + "holiday": holiday_for_the_day, "hints": hints, "hints_b": hints_b, "hints_b_mode": "day", diff --git a/schoolapps/untisconnect/api.py b/schoolapps/untisconnect/api.py index d903d5dd6923a95bbf3152f2955ae343123e7dd3..42b6fe47ec3b000bc9c7b2eaa6ce88885bbe0312 100755 --- a/schoolapps/untisconnect/api.py +++ b/schoolapps/untisconnect/api.py @@ -8,6 +8,7 @@ TYPE_TEACHER = 0 TYPE_ROOM = 1 TYPE_CLASS = 2 +from datetime import date def run_all(obj, filter_term=True): return run_default_filter(run_using(obj).all(), filter_term=filter_term) @@ -380,3 +381,32 @@ def get_all_events_by_date(date): ########## def get_raw_lessons(): return run_all(models.Lesson.objects) + +########### +# HOLIDAY # +########### +class Holiday(object): + def __init__(self): + self.filled = False + self.name = None + self.datefrom = None + self.dateto = None + + def __str__(self): + if self.filled: + return self.name or "Unbekannt" + else: + return "Unbekannt" + + def create(self, db_obj): + self.filled = True + self.name = db_obj.name + self.datefrom = db_obj.datefrom + self.dateto = db_obj.dateto + + +def get_today_holidays(date): + #db_holidays = row_by_row(models.Holiday, Holiday) + d_i = int(date_to_untis_date(date)) + db_rows = run_all(models.Holiday.objects.filter(dateto__gte=d_i, datefrom__lte=d_i), filter_term=False) + return row_by_row_helper(db_rows, Holiday) \ No newline at end of file diff --git a/schoolapps/untisconnect/plan.py b/schoolapps/untisconnect/plan.py index 48a2c123faf29d266850f12b7e9bc139e1bea9a1..81e1a13c825349f994e470892058114e75f27e42 100644 --- a/schoolapps/untisconnect/plan.py +++ b/schoolapps/untisconnect/plan.py @@ -6,6 +6,7 @@ from schoolapps import settings from schoolapps.settings import LESSONS from untisconnect.api import format_classes, TYPE_CLASS, TYPE_TEACHER, TYPE_ROOM from untisconnect.events import get_all_events_by_date +from untisconnect.api import format_classes, get_today_holidays from untisconnect.parse import parse from untisconnect.sub import get_substitutions_by_date_as_dict, TYPE_CANCELLATION, generate_event_table @@ -66,6 +67,8 @@ def get_plan(type, id, smart=False, monday_of_week=None): lessons = parse() times_parsed = parse_lesson_times() + hols_for_weekday = [] + if smart: week_days = [monday_of_week + datetime.timedelta(days=i) for i in range(5)] subs_for_weekday = [] @@ -73,6 +76,11 @@ def get_plan(type, id, smart=False, monday_of_week=None): subs = get_substitutions_by_date_as_dict(week_day) subs_for_weekday.append(subs) + hols = get_today_holidays(week_day) + hols_for_weekday.append(hols) + # print(subs) + # print(len(subs)) + # Init plan array plan = [] already_added_subs_as_ids = [] @@ -155,6 +163,12 @@ def get_plan(type, id, smart=False, monday_of_week=None): if matching_sub["sub"].type == TYPE_CANCELLATION: element_container.is_old = True + # Check for holidays + if smart and hols_for_weekday[time.day - 1]: + element_container.is_hol = True + element_container.element.holiday_reason = hols_for_weekday[time.day - 1][0].name + + if type != TYPE_ROOM or i == room_index: # Add this container object to the LessonContainer object in the plan array plan[time.hour - 1][0][time.day - 1].append(element_container) @@ -219,4 +233,4 @@ def get_plan(type, id, smart=False, monday_of_week=None): for j in range(event.event.from_lesson - 1, event.event.to_lesson): plan[j][0][i].append(element_container) - return plan + return plan, hols_for_weekday