Mercurial > libervia-web
comparison libervia/pages/g/page_meta.py @ 1355:6f342b36871c
pages (g): set `interests_map` even in case of errors
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 17 Sep 2020 08:59:43 +0200 |
parents | f511f8fbbf8a |
children | ce879da7fcf7 |
comparison
equal
deleted
inserted
replaced
1354:4751e9febbbf | 1355:6f342b36871c |
---|---|
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 | 2 |
3 | 3 |
4 from libervia.server.constants import Const as C | 4 from libervia.server.constants import Const as C |
5 from sat.core.i18n import _ | 5 from sat.core.i18n import _ |
6 from twisted.internet import defer | |
7 from libervia.server import session_iface | 6 from libervia.server import session_iface |
8 from sat.core.log import getLogger | 7 from sat.core.log import getLogger |
9 | 8 |
10 log = getLogger(__name__) | 9 log = getLogger(__name__) |
11 | 10 |
12 access = C.PAGES_ACCESS_PUBLIC | 11 access = C.PAGES_ACCESS_PUBLIC |
13 template = "invitation/welcome.html" | 12 template = "invitation/welcome.html" |
14 | 13 |
15 | 14 |
16 @defer.inlineCallbacks | 15 async def parse_url(self, request): |
17 def parse_url(self, request): | |
18 """check invitation id in URL and start session if needed | 16 """check invitation id in URL and start session if needed |
19 | 17 |
20 if a session already exists for an other guest/profile, it will be purged | 18 if a session already exists for an other guest/profile, it will be purged |
21 """ | 19 """ |
22 try: | 20 try: |
56 profile = None | 54 profile = None |
57 | 55 |
58 if current_id is None: | 56 if current_id is None: |
59 log.debug(_("checking invitation [{id}]").format(id=invitation_id)) | 57 log.debug(_("checking invitation [{id}]").format(id=invitation_id)) |
60 try: | 58 try: |
61 data = yield self.host.bridgeCall("invitationGet", invitation_id) | 59 data = await self.host.bridgeCall("invitationGet", invitation_id) |
62 except Exception: | 60 except Exception: |
63 self.pageError(request, C.HTTP_FORBIDDEN) | 61 self.pageError(request, C.HTTP_FORBIDDEN) |
64 else: | 62 else: |
65 guest_session.id = invitation_id | 63 guest_session.id = invitation_id |
66 guest_session.data = data | 64 guest_session.data = data |
71 log.debug(_("connecting profile [{}]").format(profile)) | 69 log.debug(_("connecting profile [{}]").format(profile)) |
72 # we need to connect the profile | 70 # we need to connect the profile |
73 profile = data["guest_profile"] | 71 profile = data["guest_profile"] |
74 password = data["password"] | 72 password = data["password"] |
75 try: | 73 try: |
76 yield self.host.connect(request, profile, password) | 74 await self.host.connect(request, profile, password) |
77 except Exception as e: | 75 except Exception as e: |
78 log.warning(_("Can't connect profile: {msg}").format(msg=e)) | 76 log.warning(_("Can't connect profile: {msg}").format(msg=e)) |
79 # FIXME: no good error code correspond | 77 # FIXME: no good error code correspond |
80 # maybe use a custom one? | 78 # maybe use a custom one? |
81 self.pageError(request, code=C.HTTP_SERVICE_UNAVAILABLE) | 79 self.pageError(request, code=C.HTTP_SERVICE_UNAVAILABLE) |
125 return False | 123 return False |
126 | 124 |
127 interest["url"] = self.getPageByName(page_name).getURL( | 125 interest["url"] = self.getPageByName(page_name).getURL( |
128 interest['service'], *path_args) | 126 interest['service'], *path_args) |
129 | 127 |
130 @defer.inlineCallbacks | 128 async def prepare_render(self, request): |
131 def prepare_render(self, request): | |
132 template_data = request.template_data | 129 template_data = request.template_data |
133 profile = self.getProfile(request) | 130 profile = self.getProfile(request) |
134 | 131 |
135 # interests | 132 # interests |
133 template_data['interests_map'] = interests_map = {} | |
136 try: | 134 try: |
137 interests = yield self.host.bridgeCall( | 135 interests = await self.host.bridgeCall( |
138 "interestsList", "", "", "", profile) | 136 "interestsList", "", "", "", profile) |
139 except Exception: | 137 except Exception: |
140 log.warning(_("Can't get interests list for {profile}").format( | 138 log.warning(_("Can't get interests list for {profile}").format( |
141 profile=profile)) | 139 profile=profile)) |
142 else: | 140 else: |
143 # we only want known interests (photos and events for now) | 141 # we only want known interests (photos and events for now) |
144 # this dict map namespaces of interest to a callback which can manipulate | 142 # this dict map namespaces of interest to a callback which can manipulate |
145 # the data. If it returns False, the interest is skipped | 143 # the data. If it returns False, the interest is skipped |
146 ns_data = {} | 144 ns_data = {} |
147 template_data['interests_map'] = interests_map = {} | |
148 | 145 |
149 for short_name, cb in (('event', handleEventInterest), | 146 for short_name, cb in (('event', handleEventInterest), |
150 ('fis', handleFISInterest), | 147 ('fis', handleFISInterest), |
151 ): | 148 ): |
152 try: | 149 try: |