Mercurial > libervia-web
comparison libervia/pages/g/page_meta.py @ 1124:28e3eb3bb217
files reorganisation and installation rework:
- files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory)
- VERSION file is now used, as for other SàT projects
- replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly
- removed check for data_dir if it's empty
- installation tested working in virtual env
- libervia launching script is now in bin/libervia
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 25 Aug 2018 17:59:48 +0200 |
parents | src/pages/g/page_meta.py@cdd389ef97bc |
children | 29eb15062416 |
comparison
equal
deleted
inserted
replaced
1123:63a4b8fe9782 | 1124:28e3eb3bb217 |
---|---|
1 #!/usr/bin/env python2.7 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 from libervia.server.constants import Const as C | |
5 from sat.core.i18n import _ | |
6 from twisted.internet import defer | |
7 from libervia.server import session_iface | |
8 from sat.core.log import getLogger | |
9 | |
10 log = getLogger("pages/g") | |
11 | |
12 access = C.PAGES_ACCESS_PUBLIC | |
13 template = u"invitation/welcome.html" | |
14 | |
15 | |
16 @defer.inlineCallbacks | |
17 def parse_url(self, request): | |
18 """check invitation id in URL and start session if needed | |
19 | |
20 if a session already exists for an other guest/profile, it will be purged | |
21 """ | |
22 try: | |
23 invitation_id = self.nextPath(request) | |
24 except IndexError: | |
25 self.pageError(request) | |
26 | |
27 sat_session, guest_session = self.host.getSessionData( | |
28 request, session_iface.ISATSession, session_iface.ISATGuestSession | |
29 ) | |
30 current_id = guest_session.id | |
31 | |
32 if current_id is not None and current_id != invitation_id: | |
33 log.info( | |
34 _( | |
35 u"killing guest session [{old_id}] because it is connecting with an other ID [{new_id}]" | |
36 ).format(old_id=current_id, new_id=invitation_id) | |
37 ) | |
38 self.host.purgeSession(request) | |
39 sat_session, guest_session = self.host.getSessionData( | |
40 request, session_iface.ISATSession, session_iface.ISATGuestSession | |
41 ) | |
42 current_id = None # FIXME: id non mis à zéro ici | |
43 profile = None | |
44 | |
45 profile = sat_session.profile | |
46 if profile is not None and current_id is None: | |
47 log.info( | |
48 _( | |
49 u"killing current profile session [{profile}] because a guest id is used" | |
50 ).format(profile=profile) | |
51 ) | |
52 self.host.purgeSession(request) | |
53 sat_session, guest_session = self.host.getSessionData( | |
54 request, session_iface.ISATSession, session_iface.ISATGuestSession | |
55 ) | |
56 profile = None | |
57 | |
58 if current_id is None: | |
59 log.debug(_(u"checking invitation [{id}]").format(id=invitation_id)) | |
60 try: | |
61 data = yield self.host.bridgeCall("invitationGet", invitation_id) | |
62 except Exception: | |
63 self.pageError(request, C.HTTP_UNAUTHORIZED) | |
64 else: | |
65 guest_session.id = invitation_id | |
66 guest_session.data = data | |
67 else: | |
68 data = guest_session.data | |
69 | |
70 if profile is None: | |
71 log.debug(_(u"connecting profile [{}]").format(profile)) | |
72 # we need to connect the profile | |
73 profile = data["guest_profile"] | |
74 password = data["password"] | |
75 try: | |
76 yield self.host.connect(request, profile, password) | |
77 except Exception as e: | |
78 log.warning(_(u"Can't connect profile: {msg}").format(msg=e)) | |
79 # FIXME: no good error code correspond | |
80 # maybe use a custom one? | |
81 self.pageError(request, code=C.HTTP_SERVICE_UNAVAILABLE) | |
82 | |
83 log.info( | |
84 _( | |
85 u"guest session started, connected with profile [{profile}]".format( | |
86 profile=profile | |
87 ) | |
88 ) | |
89 ) | |
90 | |
91 # we copy data useful in templates | |
92 template_data = request.template_data | |
93 template_data["norobots"] = True | |
94 if u"name" in data: | |
95 template_data[u"name"] = data[u"name"] | |
96 if u"language" in data: | |
97 template_data[u"locale"] = data[u"language"] | |
98 | |
99 | |
100 def prepare_render(self, request): | |
101 template_data = request.template_data | |
102 guest_session = self.host.getSessionData(request, session_iface.ISATGuestSession) | |
103 main_uri = guest_session.data.get("main_uri") | |
104 template_data[u"include_url"] = self.getPagePathFromURI(main_uri) |