event calendar

This commit is contained in:
boyska 2017-07-10 13:17:26 +02:00
parent 422f38015c
commit 0778338859
No known key found for this signature in database
GPG key ID: 7395DCAE58289CA9
4 changed files with 99 additions and 1 deletions

View file

@ -29,6 +29,7 @@ def get_conf(prefix='LARIGIRA_'):
conf['LOG_CONFIG'] = False
conf['TMPDIR'] = os.getenv('TMPDIR', '/tmp/')
conf['FILE_PATH_SUGGESTION'] = () # tuple of paths
conf['UI_CALENDAR_FREQUENCY_THRESHOLD'] = 4*60*60 # 4 hours
conf.update(from_envvars(prefix=prefix))
return conf

View file

@ -4,14 +4,19 @@ This module contains a flask blueprint for db administration stuff
Templates are self-contained in this directory
'''
from __future__ import print_function
from datetime import datetime, timedelta, time
from collections import defaultdict
import itertools
from flask import current_app, Blueprint, render_template, jsonify, abort, \
request, redirect, url_for
from larigira.entrypoints_utils import get_avail_entrypoints
from larigira.audiogen import get_audiogenerator
from larigira.timegen import get_timegenerator
from larigira.timegen_every import FrequencyAlarm
from larigira.timegen import get_timegenerator, timegenerate
from larigira import forms
from larigira.config import get_conf
from .suggestions import get_suggestions
db = Blueprint('db', __name__, url_prefix='/db', template_folder='templates')
@ -34,6 +39,38 @@ def events_list():
return render_template('list.html', events=events)
@db.route('/calendar')
def events_calendar():
model = current_app.larigira.controller.monitor.model
today = datetime.now().date()
maxdays = 30
days = defaultdict(lambda: defaultdict(list))
freq_threshold = get_conf()['UI_CALENDAR_FREQUENCY_THRESHOLD']
for alarm in model.get_all_alarms():
print('al', alarm.get('nick', alarm))
if freq_threshold and alarm['kind'] == 'frequency' and \
FrequencyAlarm(alarm).interval < freq_threshold:
continue
actions = tuple(model.get_actions_by_alarm(alarm))
if not actions:
continue
t = datetime.fromtimestamp(int(today.strftime('%s')))
for t in timegenerate(alarm, now=t, howmany=maxdays):
print(' t', t)
if t is None or \
t > datetime.combine(today+timedelta(days=maxdays), time()):
break
days[t.date()][t].append((alarm, actions))
print(days.keys())
weeks = defaultdict(list)
for d in sorted(days.keys()):
weeks[d.isocalendar()[:2]].append(d)
print(weeks)
return render_template('calendar.html', days=days, weeks=weeks)
@db.route('/add/time')
def addtime():
kinds = get_avail_entrypoints('larigira.timeform_create')

View file

@ -0,0 +1,59 @@
{% extends "dbadmin_base.html" %}
{%block scripts%}
{{super()}}
<script type="text/javascript">
$(function() {
$('.button').button({
icons: {
primary: 'ui-icon-pencil'
}
});
$('li.alarm').hover( function() {
var sel = 'li.alarm[data-alarmid="' + $(this).data('alarmid') + '"]'
$(sel).closest('div').find('time').toggleClass('soft-highlight');
});
$('li.alarm').click(function() {
var alarmid = $(this).data('alarmid');
var time = $('<p/>').append($('<a/>').text('Modifica orario evento').attr('href', 'edit/time/' + alarmid));
var audio = $('<p/>').append($('<a/>').text('Modifica audio evento').attr('href', 'edit/event/' + alarmid));
$('<div/>').append(time).append(audio).dialog({modal: true, title: "Evento " + $(this).text()});
});
});
</script>
{%endblock%}
{% block styles%}
{{super()}}
<style>
.soft-highlight { background-color: rgba(230, 230, 118, 0.36); }
time { transition: background-color 500ms; }
</style>
{% endblock %}
{% block title %}Larigira - Calendar{%endblock%}
{% block content %}
<div class="container-fluid">
{% for week in weeks %}
<div class="week row">
{% for day in weeks[week] %}
<div class="day col-lg-2 col-md-3 col-sm-6 col-xs-12"><h2>{{day}}</h2>
{% for t in days[day] %}
<div>
<time>{{t.time()}}</time>
<ul>
{% for alarm, actions in days[day][t] %}
<li class="alarm" data-alarmid="{{alarm.eid}}">{{alarm.nick}}</li>
{% endfor %}
</ul>
</div>
{%endfor %}
</div><!-- day {{day}} -->
{% endfor %}
</div><!-- week {{week}} -->
<hr/>
{%endfor %}
</div><!-- container -->
{% endblock content %}
{# vim: set ts=2 sw=2 noet: #}

View file

@ -40,6 +40,7 @@ $(function() {
<li><a href="{{url_for('db.events_list')}}">List</a></li>
<li><a href="{{url_for('db.addtime')}}">Add time</a></li>
<li><a href="{{url_for('db.addaudio')}}">Add audio</a></li>
<li><a href="{{url_for('db.events_calendar')}}">Calendar</a></li>
</ul>
</div>{# collapse #}