annotate libervia/web/pages/g/page_meta.py @ 1618:5d9889f14012 default tip @

server: start major redesign - Add icons to menu items - Switch menu items representation from tuple to dictionary for future extensibility: - Include icon information - Prepare for additional data - Remove "login" from main menu, add login page URL to template data, as it is now a separate right-aligned item
author Goffi <goffi@goffi.org>
date Sat, 26 Oct 2024 23:07:01 +0200
parents 197350e8bf3b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
1 #!/usr/bin/env python3
1239
f511f8fbbf8a fixed shebangs
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
2
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
3
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
4 from libervia.web.server.constants import Const as C
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
5 from libervia.backend.core.i18n import _
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
6 from libervia.web.server import session_iface
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
7 from libervia.backend.core.log import getLogger
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
8
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
9 log = getLogger(__name__)
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
10
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
11 access = C.PAGES_ACCESS_PUBLIC
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
12 template = "invitation/welcome.html"
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
13
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
14
1355
6f342b36871c pages (g): set `interests_map` even in case of errors
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
15 async def parse_url(self, request):
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
16 """check invitation id in URL and start session if needed
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
17
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
18 if a session already exists for an other guest/profile, it will be purged
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
19 """
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
20 try:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
21 invitation_id = self.next_path(request)
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
22 except IndexError:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
23 self.page_error(request)
1599
197350e8bf3b pages(g): fix guest session data:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
24 return
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
25
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
26 web_session, guest_session = self.host.get_session_data(
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
27 request, session_iface.IWebSession, session_iface.IWebGuestSession
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
28 )
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
29 current_id = guest_session.id
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
30
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
31 if current_id is not None and current_id != invitation_id:
1599
197350e8bf3b pages(g): fix guest session data:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
32 # we are already in a guest session, but not the one specified in URL, we reset id
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
33 log.info(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
34 _(
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
35 "killing guest session [{old_id}] because it is connecting with an other ID [{new_id}]"
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
36 ).format(old_id=current_id, new_id=invitation_id)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
37 )
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
38 self.host.purge_session(request)
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
39 web_session, guest_session = self.host.get_session_data(
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
40 request, session_iface.IWebSession, session_iface.IWebGuestSession
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
41 )
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
42 current_id = None # FIXME: id not reset here
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
43 profile = None
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
44
1506
ce879da7fcf7 server: fix `on_signal` callback
Goffi <goffi@goffi.org>
parents: 1355
diff changeset
45 profile = web_session.profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
46 if profile is not None and current_id is None:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
47 log.info(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
48 _(
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
49 "killing current profile session [{profile}] because a guest id is used"
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
50 ).format(profile=profile)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
51 )
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
52 self.host.purge_session(request)
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
53 web_session, guest_session = self.host.get_session_data(
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
54 request, session_iface.IWebSession, session_iface.IWebGuestSession
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
55 )
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
56 profile = None
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
57
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
58 if current_id is None:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
59 log.debug(_("checking invitation [{id}]").format(id=invitation_id))
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
60 try:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
61 data = await self.host.bridge_call("invitation_get", invitation_id)
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
62 except Exception:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
63 self.page_error(request, C.HTTP_FORBIDDEN)
1599
197350e8bf3b pages(g): fix guest session data:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
64 return
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
65 else:
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
66 data = guest_session.data
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
67
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
68 if profile is None:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
69 log.debug(_("connecting profile [{}]").format(profile))
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
70 # we need to connect the profile
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
71 profile = data["guest_profile"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
72 password = data["password"]
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
73 try:
1355
6f342b36871c pages (g): set `interests_map` even in case of errors
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
74 await self.host.connect(request, profile, password)
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
75 except Exception as e:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
76 log.warning(_("Can't connect profile: {msg}").format(msg=e))
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
77 # FIXME: no good error code correspond
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
78 # maybe use a custom one?
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
79 self.page_error(request, code=C.HTTP_SERVICE_UNAVAILABLE)
1599
197350e8bf3b pages(g): fix guest session data:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
80 else:
197350e8bf3b pages(g): fix guest session data:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
81 # a new session is created, we need to store guest session data
197350e8bf3b pages(g): fix guest session data:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
82 __, guest_session = self.host.get_session_data(
197350e8bf3b pages(g): fix guest session data:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
83 request, session_iface.IWebSession, session_iface.IWebGuestSession
197350e8bf3b pages(g): fix guest session data:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
84 )
197350e8bf3b pages(g): fix guest session data:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
85 guest_session.id = invitation_id
197350e8bf3b pages(g): fix guest session data:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
86 guest_session.data = data
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
87
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
88 log.info(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
89 _(
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
90 "guest session started, connected with profile [{profile}]".format(
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
91 profile=profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
92 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
93 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
94 )
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
95
941
aba7208d9d50 pages (g): guest name is added to template data
Goffi <goffi@goffi.org>
parents: 938
diff changeset
96 # we copy data useful in templates
aba7208d9d50 pages (g): guest name is added to template data
Goffi <goffi@goffi.org>
parents: 938
diff changeset
97 template_data = request.template_data
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1100
diff changeset
98 template_data["norobots"] = True
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
99 if "name" in data:
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
100 template_data["name"] = data["name"]
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
101 if "language" in data:
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
102 template_data["locale"] = data["language"]
941
aba7208d9d50 pages (g): guest name is added to template data
Goffi <goffi@goffi.org>
parents: 938
diff changeset
103
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
104 def handle_event_interest(self, interest):
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
105 if C.bool(interest.get("creator", C.BOOL_FALSE)):
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
106 page_name = "event_admin"
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
107 else:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
108 page_name = "event_rsvp"
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
109
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
110 interest["url"] = self.get_page_by_name(page_name).get_url(
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
111 interest.get("service", ""),
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
112 interest.get("node", ""),
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
113 interest.get("item"),
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
114 )
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
115
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
116 if "thumb_url" not in interest and "image" in interest:
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
117 interest["thumb_url"] = interest["image"]
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
118
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
119 def handle_fis_interest(self, interest):
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
120 path = interest.get('path', '')
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
121 path_args = [p for p in path.split('/') if p]
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
122 subtype = interest.get('subtype')
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
123
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
124 if subtype == 'files':
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
125 page_name = "files_view"
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
126 elif interest.get('subtype') == 'photos':
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
127 page_name = "photos_album"
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
128 else:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
129 log.warning("unknown interest subtype: {subtype}".format(subtype=subtype))
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
130 return False
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
131
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
132 interest["url"] = self.get_page_by_name(page_name).get_url(
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
133 interest['service'], *path_args)
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
134
1355
6f342b36871c pages (g): set `interests_map` even in case of errors
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
135 async def prepare_render(self, request):
930
b5490fa65348 pages (g): added g (for guest) page to handle invitations
Goffi <goffi@goffi.org>
parents:
diff changeset
136 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: 1506
diff changeset
137 profile = self.get_profile(request)
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
138
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
139 # interests
1355
6f342b36871c pages (g): set `interests_map` even in case of errors
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
140 template_data['interests_map'] = interests_map = {}
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
141 try:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
142 interests = await self.host.bridge_call(
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
143 "interests_list", "", "", "", profile)
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
144 except Exception:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
145 log.warning(_("Can't get interests list for {profile}").format(
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
146 profile=profile))
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
147 else:
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
148 # we only want known interests (photos and events for now)
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
149 # this dict map namespaces of interest to a callback which can manipulate
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
150 # the data. If it returns False, the interest is skipped
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
151 ns_data = {}
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
152
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
153 for short_name, cb in (('event', handle_event_interest),
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
154 ('fis', handle_fis_interest),
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
155 ):
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
156 try:
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
157 namespace = self.host.ns_map[short_name]
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
158 except KeyError:
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
159 pass
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
160 else:
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
161 ns_data[namespace] = (cb, short_name)
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
162
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
163 for interest in interests:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
164 namespace = interest.get('namespace')
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
165 if namespace not in ns_data:
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
166 continue
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
167 cb, short_name = ns_data[namespace]
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
168 if cb(self, interest) == False:
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
169 continue
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
170 key = interest.get('subtype', short_name)
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
171 interests_map.setdefault(key, []).append(interest)
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
172
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
173 # main URI
1518
eb00d593801d refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
174 guest_session = self.host.get_session_data(request, session_iface.IWebGuestSession)
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
175 main_uri = guest_session.data.get("event_uri")
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
176 if main_uri:
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1506
diff changeset
177 include_url = self.get_page_path_from_uri(main_uri)
1179
bfbfe04209e9 pages (g): retrieve interests for events/photo albums/file sharing + only set "include_url" if "main_uri" is set
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
178 if include_url is not None:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1179
diff changeset
179 template_data["include_url"] = include_url