annotate libervia/pages/calendar/page_meta.py @ 1515:73c848c2f41e

tasks (brython): fix version retrieval for Brython 3.11 (and 3.10?)
author Goffi <goffi@goffi.org>
date Mon, 22 May 2023 11:57:49 +0200
parents 106bae41f5c8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1508
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from sat.core.i18n import _
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.log import getLogger
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.tools.common import data_format
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from twisted.internet import defer
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 import datetime
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 import time
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 from dateutil import tz
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 from libervia.server.constants import Const as C
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 log = getLogger(__name__)
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 name = "calendar"
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 access = C.PAGES_ACCESS_PROFILE
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 template = "calendar/daily.html"
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 async def prepare_render(self, request):
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1508
diff changeset
23 profile = self.get_profile(request)
1508
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 template_data = request.template_data
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1508
diff changeset
25 # template_data["url_event_new"] = self.get_sub_page_url(request, "event_new")
1508
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 if profile is not None:
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 try:
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 events = data_format.deserialise(
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1508
diff changeset
29 await self.host.bridge_call("events_get", "", "", [], "", profile),
1508
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 type_check=list
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 )
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 except Exception as e:
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 log.warning(_("Can't get events list for {profile}: {reason}").format(
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 profile=profile, reason=e))
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 else:
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 template_data["events"] = events
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 tz_name = template_data["tz_name"] = time.tzname[0]
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 local_tz = tz.tzlocal()
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 today_local = datetime.datetime.now(local_tz).date()
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 calendar_start = template_data["calendar_start"] = datetime.datetime.combine(
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 today_local, datetime.time.min, tzinfo=local_tz
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 ).timestamp()
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 calendar_end = template_data["calendar_end"] = datetime.datetime.combine(
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 today_local, datetime.time.max, tzinfo=local_tz
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 ).timestamp()
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1508
diff changeset
47 self.expose_to_scripts(
1508
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 request,
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 calendar_start=calendar_start,
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 calendar_end=calendar_end,
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 tz_name=tz_name,
ec3ad9abf9f9 pages (calendar): calendar page, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 )