Skip to content
Snippets Groups Projects
Commit fcc2f44f authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

- Add holidays

- Check "show_plan" permission in dashboard
parent 047778a1
No related branches found
No related tags found
1 merge request!86Merge school-apps
......@@ -40,7 +40,7 @@ class Dashboard extends React.Component {
$.getJSON(API_URL + "/my-plan", (data) => {
console.log(data);
if (data && data.lessons) {
that.setState({lessons: data.lessons});
that.setState({lessons: data.lessons, holiday: data.holiday});
}
});
};
......@@ -164,34 +164,45 @@ class Dashboard extends React.Component {
</span>
{/* Show plan */}
{this.state.lessons && this.state.lessons.length > 0 ? <div className={"timetable-plan"}>
{this.state.lessons.map(function (lesson) {
// Show one lesson row
return <div className="row">
{/* Show time information*/}
<div className="col s4">
<div className="card timetable-title-card">
<div className="card-content">
{/* Lesson number*/}
<span className="card-title left">
{lesson.time.number_format}
</span>
{/* Times */}
<div className="right timetable-time grey-text text-darken-2">
<span>{lesson.time.start_format}</span>
<br/>
<span>{lesson.time.end_format}</span>
{this.state.holiday ? <div className={"card"}>
<div className={"card-content"}>
{/*<i className={"material-icons medium left"}>no_meeting_room</i>*/}
<span
className="badge new blue center-align holiday-badge">{this.state.holiday.name}</span>
<br/>
</div>
</div> :
(this.state.lessons && this.state.lessons.length > 0 ?
<div className={"timetable-plan"}>
{this.state.lessons.map(function (lesson) {
// Show one lesson row
return <div className="row">
{/* Show time information*/}
<div className="col s4">
<div className="card timetable-title-card">
<div className="card-content">
{/* Lesson number*/}
<span className="card-title left">
{lesson.time.number_format}
</span>
{/* Times */}
<div
className="right timetable-time grey-text text-darken-2">
<span>{lesson.time.start_format}</span>
<br/>
<span>{lesson.time.end_format}</span>
</div>
</div>
</div>
</div>
</div>
</div>
{/* Show lesson content (via generated HTML by Django) */}
<div className={"col s8"} dangerouslySetInnerHTML={{__html: lesson.html}}/>
</div>;
})}
</div> : ""}
{/* Show lesson content (via generated HTML by Django) */}
<div className={"col s8"}
dangerouslySetInnerHTML={{__html: lesson.html}}/>
</div>;
})}
</div> : "")}
</div>
<div className="card-action">
<a href={MY_PLAN_URL}>
......@@ -277,7 +288,7 @@ class Dashboard extends React.Component {
<div className="card">
{/* Image with badge and title */}
<div className="card-image">
<span className={"badge-image"}>Aktuelles von der Homepage</span>
<span className={"badge-image z-depth-2"}>Aktuelles von der Homepage</span>
<img src={this.state.newest_article.image_url}
alt={this.state.newest_article.title}/>
<span className="card-title"
......
......@@ -98,7 +98,7 @@ def api_information(request):
}
# If plan is available for user give extra information
if _type is not None:
if _type is not None and request.user.has_perm("timetable.show_plan"):
context["plan"] = {
"type": _type,
"name": el.shortcode if _type == TYPE_TEACHER else el.name,
......@@ -130,14 +130,14 @@ def api_my_plan_html(request):
_type, el = get_type_and_object_of_user(request.user)
# Plan is only for teachers and students available
if _type != TYPE_TEACHER and _type != TYPE_CLASS:
if (_type != TYPE_TEACHER and _type != TYPE_CLASS) or not request.user.has_perm("timetable.show_plan"):
return JsonResponse({"success": False})
# Get calendar week and monday of week
next_weekday = get_next_weekday_with_time()
# Get plan
plan = get_plan_for_day(_type, el.id, next_weekday)
plan, holiday = get_plan_for_day(_type, el.id, next_weekday)
# Serialize plan
lessons = []
......@@ -146,7 +146,8 @@ def api_my_plan_html(request):
lessons.append({"time": time, "html": html})
# Return JSON
return JsonResponse({"success": True, "lessons": lessons})
return JsonResponse(
{"success": True, "lessons": lessons, "holiday": holiday[0].__dict__ if len(holiday) > 0 else None})
def error_404(request, exception):
......
This diff is collapsed.
......@@ -70,7 +70,7 @@ def get_plan(type, id, smart=False, monday_of_week=None):
lessons = parse()
times_parsed = parse_lesson_times()
hols_for_weekday = []
hols_for_weekdays = []
if smart:
week_days = [monday_of_week + datetime.timedelta(days=i) for i in range(5)]
......@@ -80,7 +80,7 @@ def get_plan(type, id, smart=False, monday_of_week=None):
subs_for_weekday.append(subs)
hols = get_today_holidays(week_day)
hols_for_weekday.append(hols)
hols_for_weekdays.append(hols)
# print(subs)
# print(len(subs))
......@@ -168,9 +168,9 @@ def get_plan(type, id, smart=False, monday_of_week=None):
element_container.is_old = True
# Check for holidays
if smart and hols_for_weekday[time.day - 1]:
if smart and hols_for_weekdays[time.day - 1]:
element_container.is_hol = True
element_container.element.holiday_reason = hols_for_weekday[time.day - 1][0].name
element_container.element.holiday_reason = hols_for_weekdays[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
......@@ -236,4 +236,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, hols_for_weekday
return plan, hols_for_weekdays
......@@ -42,4 +42,6 @@ def get_plan_for_day(_type, plan_id, date):
# Get plan
plan, holidays = get_plan(_type, plan_id, smart=True, monday_of_week=monday_of_week)
lessons = [(row[week_day], time) for row, time in plan]
return lessons
holidays_for_date = holidays[week_day]
return lessons, holidays_for_date
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment