FIX calendar sorting

This commit is contained in:
boyska 2017-07-25 01:25:54 +02:00
parent 8c4c27d112
commit 20bc2325cf
No known key found for this signature in database
GPG key ID: 7395DCAE58289CA9
2 changed files with 9 additions and 12 deletions

View file

@ -6,7 +6,6 @@ Templates are self-contained in this directory
from __future__ import print_function from __future__ import print_function
from datetime import datetime, timedelta, time from datetime import datetime, timedelta, time
from collections import defaultdict from collections import defaultdict
import itertools
from flask import current_app, Blueprint, render_template, jsonify, abort, \ from flask import current_app, Blueprint, render_template, jsonify, abort, \
request, redirect, url_for request, redirect, url_for
@ -44,10 +43,10 @@ def events_calendar():
model = current_app.larigira.controller.monitor.model model = current_app.larigira.controller.monitor.model
today = datetime.now().date() today = datetime.now().date()
maxdays = 30 maxdays = 30
# {date: {datetime: [(alarm1,actions1), (alarm2,actions2)]}}
days = defaultdict(lambda: defaultdict(list)) days = defaultdict(lambda: defaultdict(list))
freq_threshold = get_conf()['UI_CALENDAR_FREQUENCY_THRESHOLD'] freq_threshold = get_conf()['UI_CALENDAR_FREQUENCY_THRESHOLD']
for alarm in model.get_all_alarms(): for alarm in model.get_all_alarms():
print('al', alarm.get('nick', alarm))
if freq_threshold and alarm['kind'] == 'frequency' and \ if freq_threshold and alarm['kind'] == 'frequency' and \
FrequencyAlarm(alarm).interval < freq_threshold: FrequencyAlarm(alarm).interval < freq_threshold:
continue continue
@ -56,17 +55,15 @@ def events_calendar():
continue continue
t = datetime.fromtimestamp(int(today.strftime('%s'))) t = datetime.fromtimestamp(int(today.strftime('%s')))
for t in timegenerate(alarm, now=t, howmany=maxdays): for t in timegenerate(alarm, now=t, howmany=maxdays):
print(' t', t)
if t is None or \ if t is None or \
t > datetime.combine(today+timedelta(days=maxdays), time()): t > datetime.combine(today+timedelta(days=maxdays), time()):
break break
days[t.date()][t].append((alarm, actions)) days[t.date()][t].append((alarm, actions))
print(days.keys()) # { weeknum: [day1, day2, day3] }
weeks = defaultdict(list) weeks = defaultdict(list)
for d in sorted(days.keys()): for d in sorted(days.keys()):
weeks[d.isocalendar()[:2]].append(d) weeks[d.isocalendar()[:2]].append(d)
print(weeks)
return render_template('calendar.html', days=days, weeks=weeks) return render_template('calendar.html', days=days, weeks=weeks)
@ -172,7 +169,6 @@ def edit_event(alarmid):
if alarm is None: if alarm is None:
abort(404) abort(404)
allactions = model.get_all_actions() allactions = model.get_all_actions()
print('all', allactions)
actions = tuple(model.get_actions_by_alarm(alarm)) actions = tuple(model.get_actions_by_alarm(alarm))
return render_template('edit_event.html', return render_template('edit_event.html',
alarm=alarm, all_actions=allactions, alarm=alarm, all_actions=allactions,

View file

@ -35,7 +35,7 @@ $(document).tooltip({
{{super()}} {{super()}}
<style> <style>
.soft-highlight { background-color: rgba(230, 230, 118, 0.36); } .soft-highlight { background-color: rgba(230, 230, 118, 0.36); }
time { transition: background-color 500ms; } time { transition: background-color 500ms; font-weight: bold; }
li.alarm .alarm-actions { display: none; } li.alarm .alarm-actions { display: none; }
</style> </style>
{% endblock %} {% endblock %}
@ -45,16 +45,17 @@ li.alarm .alarm-actions { display: none; }
{% block content %} {% block content %}
<div class="container-fluid"> <div class="container-fluid">
{% for week in weeks %} {% for week, weekdays in weeks|dictsort %}
<div class="week row"> <div class="week row" id="week-{{week[0]}}-{{week[1]}}">
{% for day in weeks[week] %} {% for day in weeks[week] %}
<div class="day col-lg-2 col-md-3 col-sm-6 col-xs-12"><h2>{{day}}</h2> <div class="day col-lg-2 col-md-3 col-sm-6 col-xs-12"><h2>{{day}}</h2>
{% for t in days[day] %} {% for t in days[day]|sort %}
<div> <div>
<time>{{t.time()}}</time>
<ul> <ul>
{% for alarm, actions in days[day][t] %} {% for alarm, actions in days[day][t] %}
<li class="alarm" data-alarmid="{{alarm.eid}}">{{alarm.nick}} <li class="alarm" data-alarmid="{{alarm.eid}}">
<time>{{t.time()}}</time>
{{alarm.nick}}
<div class="alarm-actions">{% for a in actions %}{{a.nick}}{%endfor%}</div> <div class="alarm-actions">{% for a in actions %}{{a.nick}}{%endfor%}</div>
</li> </li>
{% endfor %} {% endfor %}