|
@@ -67,26 +67,25 @@ def events_list():
|
|
def events_calendar():
|
|
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
|
|
|
|
|
|
+ max_days = 30
|
|
|
|
+ max_occurrences = get_conf()["UI_CALENDAR_OCCURRENCIES_THRESHOLD"]
|
|
# {date: {datetime: [(alarm1,actions1), (alarm2,actions2)]}}
|
|
# {date: {datetime: [(alarm1,actions1), (alarm2,actions2)]}}
|
|
days = defaultdict(lambda: defaultdict(list))
|
|
days = defaultdict(lambda: defaultdict(list))
|
|
- freq_threshold = get_conf()["UI_CALENDAR_FREQUENCY_THRESHOLD"]
|
|
|
|
|
|
+ show_all = (request.args.get('all', '0') == '1')
|
|
for alarm in model.get_all_alarms():
|
|
for alarm in model.get_all_alarms():
|
|
- if (
|
|
|
|
- freq_threshold
|
|
|
|
- and alarm["kind"] == "frequency"
|
|
|
|
- and FrequencyAlarm(alarm).interval < freq_threshold
|
|
|
|
- ):
|
|
|
|
- continue
|
|
|
|
actions = tuple(model.get_actions_by_alarm(alarm))
|
|
actions = tuple(model.get_actions_by_alarm(alarm))
|
|
if not actions:
|
|
if not actions:
|
|
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):
|
|
|
|
- if t is None or t > datetime.combine(
|
|
|
|
- today + timedelta(days=maxdays), time()
|
|
|
|
- ):
|
|
|
|
- break
|
|
|
|
|
|
+ occurrences = [ t for t in timegenerate(alarm, now=t, howmany=max_occurrences +
|
|
|
|
+ 1) if t is not None and t <= datetime.combine(
|
|
|
|
+ today + timedelta(days=max_days), time()
|
|
|
|
+ )]
|
|
|
|
+ if not occurrences:
|
|
|
|
+ continue
|
|
|
|
+ if not show_all and len(occurrences) > max_occurrences:
|
|
|
|
+ continue
|
|
|
|
+ for t in occurrences:
|
|
days[t.date()][t].append((alarm, actions))
|
|
days[t.date()][t].append((alarm, actions))
|
|
|
|
|
|
# { weeknum: [day1, day2, day3] }
|
|
# { weeknum: [day1, day2, day3] }
|
|
@@ -94,7 +93,8 @@ def events_calendar():
|
|
for d in sorted(days.keys()):
|
|
for d in sorted(days.keys()):
|
|
weeks[d.isocalendar()[:2]].append(d)
|
|
weeks[d.isocalendar()[:2]].append(d)
|
|
|
|
|
|
- return render_template("calendar.html", days=days, weeks=weeks)
|
|
|
|
|
|
+ return render_template("calendar.html", days=days, weeks=weeks,
|
|
|
|
+ show_all=show_all)
|
|
|
|
|
|
|
|
|
|
@db.route("/add/time")
|
|
@db.route("/add/time")
|