Added basic homepage
This commit is contained in:
parent
a1349a6a4d
commit
e32098e68c
5 changed files with 92 additions and 20 deletions
|
@ -10,7 +10,8 @@ from pathlib import Path
|
||||||
from datetime import date
|
from datetime import date
|
||||||
import caldav
|
import caldav
|
||||||
|
|
||||||
from .server import app
|
from .server import create_app
|
||||||
|
from .calendar import get_davclient
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Web-based CalDav client')
|
parser = argparse.ArgumentParser(description='Web-based CalDav client')
|
||||||
|
@ -28,6 +29,9 @@ log = logging.getLogger('saturn')
|
||||||
log.info('Starting saturn')
|
log.info('Starting saturn')
|
||||||
|
|
||||||
|
|
||||||
|
davclient = get_davclient(config['caldav'])
|
||||||
|
app = create_app(davclient)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(
|
app.run(
|
||||||
host=config.get('server', 'host', fallback=None),
|
host=config.get('server', 'host', fallback=None),
|
29
saturn/calendar/__init__.py
Normal file
29
saturn/calendar/__init__.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import caldav
|
||||||
|
|
||||||
|
from datetime import date, datetime
|
||||||
|
|
||||||
|
|
||||||
|
def get_davclient(config):
|
||||||
|
return caldav.davclient.DAVClient(
|
||||||
|
config.get('host'),
|
||||||
|
username=config.get('username', fallback=None),
|
||||||
|
password=config.get('password', fallback=None),
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_events(davclient):
|
||||||
|
pri = davclient.principal()
|
||||||
|
|
||||||
|
events = []
|
||||||
|
events_day = []
|
||||||
|
|
||||||
|
for cal in pri.calendars():
|
||||||
|
events += [event.instance.vevent
|
||||||
|
for event in cal.date_search(start=date.today())
|
||||||
|
if type(event.instance.vevent.dtstart.value) == datetime]
|
||||||
|
events_day += [event.instance.vevent
|
||||||
|
for event in cal.date_search(start=date.today())
|
||||||
|
if type(event.instance.vevent.dtstart.value) != datetime]
|
||||||
|
events.sort(key=lambda event:event.dtstart.value)
|
||||||
|
events_day.sort(key=lambda event:event.dtstart.value)
|
||||||
|
|
||||||
|
return events, events_day
|
20
saturn/server/__init__.py
Normal file
20
saturn/server/__init__.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import flask
|
||||||
|
|
||||||
|
from datetime import date, datetime
|
||||||
|
from ..calendar import get_events
|
||||||
|
|
||||||
|
|
||||||
|
def create_app(davclient):
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def home():
|
||||||
|
events, events_day = get_events(davclient)
|
||||||
|
|
||||||
|
return flask.render_template(
|
||||||
|
'index.html',
|
||||||
|
events = events,
|
||||||
|
events_day = events_day,
|
||||||
|
)
|
||||||
|
|
||||||
|
return app
|
38
saturn/server/templates/index.html
Normal file
38
saturn/server/templates/index.html
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang='en'>
|
||||||
|
<head>
|
||||||
|
<title>Saturn</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% for event in events %}
|
||||||
|
<div>
|
||||||
|
<ul>
|
||||||
|
<li>{{ event.dtstart.value }}</li>
|
||||||
|
<li>{{ event.dtend.value }}</li>
|
||||||
|
<li>{{ event.summary.value }}</li>
|
||||||
|
{% if event.description %}
|
||||||
|
<li>{{ event.description.value }}</li>
|
||||||
|
{% endif %}
|
||||||
|
{% if event.location %}
|
||||||
|
<li>{{ event.location.value }}</li>
|
||||||
|
{% endif %}
|
||||||
|
{% if event.rrule %}
|
||||||
|
<li>{{ event.rrule.value }}</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% for event in events_day %}
|
||||||
|
<div>
|
||||||
|
<ul>
|
||||||
|
<li>{{ event.dtstart.value }}</li>
|
||||||
|
<li>{{ event.dtend.value }}</li>
|
||||||
|
<li>{{ event.summary.value }}</li>
|
||||||
|
{% if event.description %}
|
||||||
|
<li>{{ event.description.value }}</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,19 +0,0 @@
|
||||||
import flask
|
|
||||||
|
|
||||||
app = flask.Flask(__name__)
|
|
||||||
|
|
||||||
@app.route('/')
|
|
||||||
def home():
|
|
||||||
return 'Hello World!'
|
|
||||||
#cli = caldav.davclient.DAVClient(
|
|
||||||
# config.get('caldav', 'host'),
|
|
||||||
# username=config.get('caldav', 'username', fallback=None),
|
|
||||||
# password=config.get('caldav', 'password', fallback=None),
|
|
||||||
#)
|
|
||||||
#pri = cli.principal()
|
|
||||||
#
|
|
||||||
#res = ''
|
|
||||||
#for cal in pri.calendars():
|
|
||||||
# for event in cal.date_search(start=date.today()):
|
|
||||||
# res += f'<li>{event.instance.vevent.dtstart.value}</li>'
|
|
||||||
#return f'<ul>{res}</ul>'
|
|
Reference in a new issue