comparison libervia/pages/calendar/page_meta.py @ 1508:ec3ad9abf9f9

pages (calendar): calendar page, first draft
author Goffi <goffi@goffi.org>
date Fri, 07 Apr 2023 15:20:40 +0200
parents
children 106bae41f5c8
comparison
equal deleted inserted replaced
1507:ae5158f3c420 1508:ec3ad9abf9f9
1 #!/usr/bin/env python3
2
3
4 from sat.core.i18n import _
5 from sat.core.log import getLogger
6 from sat.tools.common import data_format
7 from twisted.internet import defer
8 import datetime
9 import time
10 from dateutil import tz
11
12 from libervia.server.constants import Const as C
13
14 log = getLogger(__name__)
15
16
17 name = "calendar"
18 access = C.PAGES_ACCESS_PROFILE
19 template = "calendar/daily.html"
20
21
22 async def prepare_render(self, request):
23 profile = self.getProfile(request)
24 template_data = request.template_data
25 # template_data["url_event_new"] = self.getSubPageURL(request, "event_new")
26 if profile is not None:
27 try:
28 events = data_format.deserialise(
29 await self.host.bridgeCall("eventsGet", "", "", [], "", profile),
30 type_check=list
31 )
32 except Exception as e:
33 log.warning(_("Can't get events list for {profile}: {reason}").format(
34 profile=profile, reason=e))
35 else:
36 template_data["events"] = events
37
38 tz_name = template_data["tz_name"] = time.tzname[0]
39 local_tz = tz.tzlocal()
40 today_local = datetime.datetime.now(local_tz).date()
41 calendar_start = template_data["calendar_start"] = datetime.datetime.combine(
42 today_local, datetime.time.min, tzinfo=local_tz
43 ).timestamp()
44 calendar_end = template_data["calendar_end"] = datetime.datetime.combine(
45 today_local, datetime.time.max, tzinfo=local_tz
46 ).timestamp()
47 self.exposeToScripts(
48 request,
49 calendar_start=calendar_start,
50 calendar_end=calendar_end,
51 tz_name=tz_name,
52 )