Mercurial > libervia-web
comparison libervia/web/pages/calendar/page_meta.py @ 1518:eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 02 Jun 2023 16:49:28 +0200 |
parents | libervia/pages/calendar/page_meta.py@106bae41f5c8 |
children | 08342aca8c1e |
comparison
equal
deleted
inserted
replaced
1517:b8ed9726525b | 1518:eb00d593801d |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 | |
4 from libervia.backend.core.i18n import _ | |
5 from libervia.backend.core.log import getLogger | |
6 from libervia.backend.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.web.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.get_profile(request) | |
24 template_data = request.template_data | |
25 # template_data["url_event_new"] = self.get_sub_page_url(request, "event_new") | |
26 if profile is not None: | |
27 try: | |
28 events = data_format.deserialise( | |
29 await self.host.bridge_call("events_get", "", "", [], "", 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.expose_to_scripts( | |
48 request, | |
49 calendar_start=calendar_start, | |
50 calendar_end=calendar_end, | |
51 tz_name=tz_name, | |
52 ) |