19
19
from .database import Class , Classroom , Document , Entity , LunchMenu , LunchSchedule , Session , SnackMenu , Teacher
20
20
from .errors import ConfigError , ConfigParseError , ConfigReadError , ConfigValidationError
21
21
from .utils .flask import DateConverter , ListConverter
22
- from .utils .ical import create_calendar
22
+ from .utils .ical import create_schedule_calendar , create_school_calendar
23
23
from .utils .url import tokenize_url
24
24
25
25
@@ -115,6 +115,7 @@ def __init__(self, configfile):
115
115
self .convert_date_objects ()
116
116
117
117
self .register_route_converters ()
118
+ self .register_jinja_filters ()
118
119
self .register_commands ()
119
120
self .register_routes ()
120
121
@@ -256,6 +257,16 @@ def register_route_converters(self):
256
257
self .app .url_map .converters ["date" ] = DateConverter
257
258
self .app .url_map .converters ["list" ] = ListConverter
258
259
260
+ def register_jinja_filters (self ):
261
+ """Register all custom Jinja filters."""
262
+
263
+ def format_date (date ):
264
+ return date .strftime ("%d. %m. %Y" )
265
+
266
+ filters = self .app .jinja_env .filters
267
+ filters ["date_format_daily" ] = format_date
268
+ filters ["date_format_weekly" ] = lambda date : f"{ format_date (date )} — { format_date ((date + timedelta (days = 4 )))} "
269
+
259
270
def register_commands (self ):
260
271
"""Register all application commands."""
261
272
@@ -271,7 +282,7 @@ def register_commands(self):
271
282
def register_routes (self ):
272
283
"""Register all application routes."""
273
284
274
- def create_feed (filter , name , type , format ):
285
+ def create_feed (filter , name , type , format , display_date = None , display_date_type = "daily" ):
275
286
query = (
276
287
self .session .query (Document .date , Document .type , Document .url , Document .description )
277
288
.filter (filter )
@@ -285,6 +296,8 @@ def create_feed(filter, name, type, format):
285
296
type = type ,
286
297
entries = query ,
287
298
last_updated = max (model .date for model in query ),
299
+ display_date = display_date ,
300
+ display_date_type = display_date_type ,
288
301
)
289
302
290
303
return (
@@ -433,6 +446,7 @@ def _circulars_get_atom():
433
446
name = "Okrožnice" ,
434
447
type = "circulars" ,
435
448
format = "atom" ,
449
+ display_date = False ,
436
450
)
437
451
438
452
@self .app .route ("/feeds/circulars.rss" )
@@ -442,23 +456,52 @@ def _circulars_get_rss():
442
456
name = "Okrožnice" ,
443
457
type = "circulars" ,
444
458
format = "rss" ,
459
+ display_date = False ,
445
460
)
446
461
447
462
@self .app .route ("/feeds/substitutions.atom" )
448
463
def _substitutions_get_atom ():
449
- return create_feed (filter = Document .type == "substitutions" , name = "Nadomeščanja" , type = "substitutions" , format = "atom" )
464
+ return create_feed (
465
+ filter = Document .type == "substitutions" ,
466
+ name = "Nadomeščanja" ,
467
+ type = "substitutions" ,
468
+ format = "atom" ,
469
+ display_date = True ,
470
+ display_date_type = "daily" ,
471
+ )
450
472
451
473
@self .app .route ("/feeds/substitutions.rss" )
452
474
def _substitutions_get_rss ():
453
- return create_feed (filter = Document .type == "substitutions" , name = "Nadomeščanja" , type = "substitutions" , format = "rss" )
475
+ return create_feed (
476
+ filter = Document .type == "substitutions" ,
477
+ name = "Nadomeščanja" ,
478
+ type = "substitutions" ,
479
+ format = "rss" ,
480
+ display_date = True ,
481
+ display_date_type = "daily" ,
482
+ )
454
483
455
484
@self .app .route ("/feeds/schedules.atom" )
456
485
def _schedules_get_atom ():
457
- return create_feed (filter = Document .type == "lunch-schedule" , name = "Razporedi kosil" , type = "schedules" , format = "atom" )
486
+ return create_feed (
487
+ filter = Document .type == "lunch-schedule" ,
488
+ name = "Razporedi delitve kosila" ,
489
+ type = "schedules" ,
490
+ format = "atom" ,
491
+ display_date = True ,
492
+ display_date_type = "daily" ,
493
+ )
458
494
459
495
@self .app .route ("/feeds/schedules.rss" )
460
496
def _schedules_get_rss ():
461
- return create_feed (filter = Document .type == "lunch-schedule" , name = "Razporedi kosil" , type = "schedules" , format = "rss" )
497
+ return create_feed (
498
+ filter = Document .type == "lunch-schedule" ,
499
+ name = "Razporedi delitve kosila" ,
500
+ type = "schedules" ,
501
+ format = "rss" ,
502
+ display_date = True ,
503
+ display_date_type = "daily" ,
504
+ )
462
505
463
506
@self .app .route ("/feeds/menus.atom" )
464
507
def _menu_get_atom ():
@@ -467,6 +510,8 @@ def _menu_get_atom():
467
510
name = "Jedilniki" ,
468
511
type = "menus" ,
469
512
format = "atom" ,
513
+ display_date = True ,
514
+ display_date_type = "weekly" ,
470
515
)
471
516
472
517
@self .app .route ("/feeds/menus.rss" )
@@ -476,11 +521,13 @@ def _menu_get_rss():
476
521
name = "Jedilniki" ,
477
522
type = "menus" ,
478
523
format = "rss" ,
524
+ display_date = True ,
525
+ display_date_type = "weekly" ,
479
526
)
480
527
481
528
@self .app .route ("/calendar/combined/<list:classes>" )
482
529
def _get_calendar_for_classes (classes ):
483
- return create_calendar (
530
+ return create_school_calendar (
484
531
Class .get_substitutions (self .session , None , classes ),
485
532
Class .get_lessons (self .session , classes ),
486
533
self .config ["hourtimes" ],
@@ -489,7 +536,7 @@ def _get_calendar_for_classes(classes):
489
536
490
537
@self .app .route ("/calendar/timetable/<list:classes>" )
491
538
def _get_calendar_timetable_for_classes (classes ):
492
- return create_calendar (
539
+ return create_school_calendar (
493
540
Class .get_substitutions (self .session , None , classes ),
494
541
Class .get_lessons (self .session , classes ),
495
542
self .config ["hourtimes" ],
@@ -499,14 +546,24 @@ def _get_calendar_timetable_for_classes(classes):
499
546
500
547
@self .app .route ("/calendar/substitutions/<list:classes>" )
501
548
def _get_calendar_substitutions_for_classes (classes ):
502
- return create_calendar (
549
+ return create_school_calendar (
503
550
Class .get_substitutions (self .session , None , classes ),
504
551
Class .get_lessons (self .session , classes ),
505
552
self .config ["hourtimes" ],
506
553
f"Nadomeščanja - { ', ' .join (classes )} - Gimnazija Vič" ,
507
554
timetable = False ,
508
555
)
509
556
557
+ @self .app .route ("/calendar/schedules/<list:classes>" )
558
+ def _get_calendar_schedules_for_classes (classes ):
559
+ return create_schedule_calendar (
560
+ self .session .query (LunchSchedule )
561
+ .join (Class )
562
+ .filter (Class .name .in_ (classes ))
563
+ .order_by (LunchSchedule .time , LunchSchedule .class_ ),
564
+ f"Razporedi delitve kosila - { ', ' .join (classes )} - Gimnazija Vič" ,
565
+ )
566
+
510
567
511
568
def create_app ():
512
569
"""Application factory that accepts a configuration file from environment variable."""
0 commit comments