Skip to content

Commit 1e27ea7

Browse files
authored
Merge pull request #375 – Make it possible to override session's start/end time
#375
2 parents d0ac172 + ab10ab9 commit 1e27ea7

File tree

4 files changed

+90
-16
lines changed

4 files changed

+90
-16
lines changed

naucse/models.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,14 @@ def merge_dict(base, patch):
317317
return result
318318

319319

320+
def time_from_string(time_string):
321+
hour, minute = time_string.split(':')
322+
hour = int(hour)
323+
minute = int(minute)
324+
tzinfo = dateutil.tz.gettz(_TIMEZONE)
325+
return datetime.time(hour, minute, tzinfo=tzinfo)
326+
327+
320328
class Session(Model):
321329
"""An ordered collection of materials"""
322330
def __init__(self, root, path, base_course, info, index, course=None):
@@ -341,21 +349,44 @@ def __str__(self):
341349
date = DataProperty(info, default=None)
342350
description = DataProperty(info, default=None)
343351

344-
def _time(self, key, default_time):
345-
if self.date and default_time:
346-
return datetime.datetime.combine(self.date, default_time)
352+
def _time(self, time):
353+
if self.date and time:
354+
return datetime.datetime.combine(self.date, time)
355+
return None
356+
357+
def _session_time(self, key):
358+
sesion_time = self.info.get('time')
359+
if sesion_time:
360+
return time_from_string(sesion_time[key])
347361
return None
348362

363+
@reify
364+
def has_irregular_time(self):
365+
"""True iff the session has its own start or end time, the course has
366+
a default start or end time, and either of those does not match."""
367+
368+
irregular_start = self.course.default_start_time is not None \
369+
and self._time(self.course.default_start_time) != self.start_time
370+
irregular_end = self.course.default_end_time is not None \
371+
and self._time(self.course.default_end_time) != self.end_time
372+
return irregular_start or irregular_end
373+
349374
@reify
350375
def start_time(self):
376+
session_time = self._session_time('start')
377+
if session_time:
378+
return self._time(session_time)
351379
if self.course:
352-
return self._time('start', self.course.default_start_time)
380+
return self._time(self.course.default_start_time)
353381
return None
354382

355383
@reify
356384
def end_time(self):
385+
session_time = self._session_time('end')
386+
if session_time:
387+
return self._time(session_time)
357388
if self.course:
358-
return self._time('end', self.course.default_end_time)
389+
return self._time(self.course.default_end_time)
359390
return None
360391

361392
@reify
@@ -471,12 +502,7 @@ def end_date(self):
471502
def _default_time(self, key):
472503
default_time = self.info.get('default_time')
473504
if default_time:
474-
time_string = default_time[key]
475-
hour, minute = time_string.split(':')
476-
hour = int(hour)
477-
minute = int(minute)
478-
tzinfo = dateutil.tz.gettz(_TIMEZONE)
479-
return datetime.time(hour, minute, tzinfo=tzinfo)
505+
return time_from_string(default_time[key])
480506
return None
481507

482508
@reify

naucse/static/css/nausce.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,28 @@ code {
173173
white-space: pre-wrap;
174174
}
175175

176+
/*** Session lists ***/
177+
178+
.session-time-place {
179+
margin-left: 1.5em;
180+
}
181+
182+
.session-time-place .regular-time {
183+
font-size: inherit;
184+
}
185+
186+
.session-time-place small.regular-time {
187+
color: #888;
188+
}
189+
190+
.session-time-place .irregular-time-alert {
191+
color: #888;
192+
}
193+
194+
.session-time-place .irregular-time-alert .icon {
195+
color: #F0AD4E;
196+
}
197+
176198
/*** Material lists ***/
177199

178200
ul.material-list {

naucse/templates/course.html

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,35 @@ <h4>
4141
<a href="{{ session_url(course.slug, session.slug) }}">
4242
{{ session.title }}
4343
</a>
44-
{% if session.date %}
45-
<small>({{ session.date | format_date }})</small>
46-
{% endif %}
4744
</h4>
45+
{% if session.date %}
46+
<div class="session-time-place">
47+
<div>
48+
{{ session.date | format_date -}}
49+
{%- if session.start_time and session.end_time -%}
50+
{%- macro _time() -%}
51+
,
52+
{{ session.start_time | format_time -}}
53+
54+
{{- session.end_time | format_time -}}
55+
{%- endmacro %}
56+
{%- if session.has_irregular_time -%}
57+
<span class="irregular-time">{{ _time() }}</span>
58+
{%- elif course.default_start_time -%}
59+
<small class="regular-time">{{ _time() }}</small>
60+
{%- else -%}
61+
<span class="regular-time">{{ _time() }}</span>
62+
{%- endif -%}
63+
{% endif %}
64+
</div>
65+
{% if session.has_irregular_time %}
66+
<div class="irregular-time-alert">
67+
{{ bytesize_icon('alert') }}
68+
Pozor, změna času konání!
69+
</div>
70+
{% endif %}
71+
</div>
72+
{% endif %}
4873
{% if session.description %}{{ session.description | markdown }}{% endif %}
4974
{{ material_list(session.materials) }}
5075
</div>

naucse/templates/coverpage.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ <h1>
2525
{% endif %}
2626
</h1>
2727

28-
{% if course.place is defined and course.time is defined and course.place != None and course.time != None %}
29-
<div class="details">{{course.place}}, {{course.time}}</div>
28+
{% if course.place is not none and session.start_time is not none %}
29+
<div class="details">{{ course.place }},
30+
{{ session.start_time | format_time }}–{{ session.end_time | format_time }}</div>
3031
{% endif %}
3132

3233
{% if session.description %}{{ session.description | markdown }}{% endif %}

0 commit comments

Comments
 (0)