Mercurial > libervia-web
comparison libervia/pages/events/admin/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/events/admin/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 twisted.internet import defer | |
6 from twisted.words.protocols.jabber import jid | |
7 from sat.tools.common.template import safe | |
8 from sat.core.i18n import _ | |
9 from sat.core.log import getLogger | |
10 import time | |
11 import cgi | |
12 import math | |
13 import re | |
14 | |
15 name = u"event_admin" | |
16 access = C.PAGES_ACCESS_PROFILE | |
17 template = u"event/admin.html" | |
18 log = getLogger(u"pages/" + name) | |
19 REG_EMAIL_RE = re.compile(C.REG_EMAIL_RE, re.IGNORECASE) | |
20 | |
21 | |
22 def parse_url(self, request): | |
23 self.getPathArgs( | |
24 request, | |
25 ("event_service", "event_node", "event_id"), | |
26 min_args=2, | |
27 event_service="@jid", | |
28 event_id="", | |
29 ) | |
30 | |
31 | |
32 @defer.inlineCallbacks | |
33 def prepare_render(self, request): | |
34 data = self.getRData(request) | |
35 template_data = request.template_data | |
36 | |
37 ## Event ## | |
38 | |
39 event_service = template_data[u"event_service"] = data["event_service"] | |
40 event_node = template_data[u"event_node"] = data["event_node"] | |
41 event_id = template_data[u"event_id"] = data["event_id"] | |
42 profile = self.getProfile(request) | |
43 event_timestamp, event_data = yield self.host.bridgeCall( | |
44 u"eventGet", | |
45 event_service.userhost() if event_service else "", | |
46 event_node, | |
47 event_id, | |
48 profile, | |
49 ) | |
50 try: | |
51 background_image = event_data.pop("background-image") | |
52 except KeyError: | |
53 pass | |
54 else: | |
55 template_data["dynamic_style"] = safe( | |
56 u""" | |
57 html { | |
58 background-image: url("%s"); | |
59 background-size: 15em; | |
60 } | |
61 """ | |
62 % cgi.escape(background_image, True) | |
63 ) | |
64 template_data["event"] = event_data | |
65 invitees = yield self.host.bridgeCall( | |
66 u"eventInviteesList", | |
67 event_data["invitees_service"], | |
68 event_data["invitees_node"], | |
69 profile, | |
70 ) | |
71 template_data["invitees"] = invitees | |
72 invitees_guests = 0 | |
73 for invitee_data in invitees.itervalues(): | |
74 if invitee_data.get("attend", "no") == "no": | |
75 continue | |
76 try: | |
77 invitees_guests += int(invitee_data.get("guests", 0)) | |
78 except ValueError: | |
79 log.warning( | |
80 _(u"guests value is not valid: {invitee}").format(invitee=invitee_data) | |
81 ) | |
82 template_data["invitees_guests"] = invitees_guests | |
83 template_data["days_left"] = int( | |
84 math.ceil((event_timestamp - time.time()) / (60 * 60 * 24)) | |
85 ) | |
86 | |
87 ## Blog ## | |
88 | |
89 data[u"service"] = jid.JID(event_data[u"blog_service"]) | |
90 data[u"node"] = event_data[u"blog_node"] | |
91 data[u"allow_commenting"] = u"simple" | |
92 | |
93 # we now need blog items, using blog common page | |
94 # this will fill the "items" template data | |
95 blog_page = self.getPageByName(u"blog_view") | |
96 yield blog_page.prepare_render(self, request) | |
97 | |
98 | |
99 @defer.inlineCallbacks | |
100 def on_data_post(self, request): | |
101 profile = self.getProfile(request) | |
102 if not profile: | |
103 log.error(u"got post data without profile") | |
104 self.pageError(request, C.HTTP_INTERNAL_ERROR) | |
105 type_ = self.getPostedData(request, "type") | |
106 if type_ == "blog": | |
107 service, node, title, body, lang = self.getPostedData( | |
108 request, (u"service", u"node", u"title", u"body", u"language") | |
109 ) | |
110 | |
111 if not body.strip(): | |
112 self.pageError(request, C.HTTP_BAD_REQUEST) | |
113 data = {u"content": body} | |
114 if title: | |
115 data[u"title"] = title | |
116 if lang: | |
117 data[u"language"] = lang | |
118 try: | |
119 comments = bool(self.getPostedData(request, u"comments").strip()) | |
120 except KeyError: | |
121 pass | |
122 else: | |
123 if comments: | |
124 data[u"allow_comments"] = C.BOOL_TRUE | |
125 | |
126 try: | |
127 yield self.host.bridgeCall(u"mbSend", service, node, data, profile) | |
128 except Exception as e: | |
129 if u"forbidden" in unicode(e): | |
130 self.pageError(request, C.HTTP_UNAUTHORIZED) | |
131 else: | |
132 raise e | |
133 elif type_ == "event": | |
134 service, node, event_id, jids, emails = self.getPostedData( | |
135 request, (u"service", u"node", u"event_id", u"jids", u"emails") | |
136 ) | |
137 for invitee_jid_s in jids.split(): | |
138 try: | |
139 invitee_jid = jid.JID(invitee_jid_s) | |
140 except RuntimeError as e: | |
141 log.warning( | |
142 _(u"this is not a valid jid: {jid}").format(jid=invitee_jid_s) | |
143 ) | |
144 continue | |
145 yield self.host.bridgeCall( | |
146 "eventInvite", invitee_jid.userhost(), service, node, event_id, profile | |
147 ) | |
148 for email_addr in emails.split(): | |
149 if not REG_EMAIL_RE.match(email_addr): | |
150 log.warning( | |
151 _(u"this is not a valid email address: {email}").format( | |
152 email=email_addr | |
153 ) | |
154 ) | |
155 continue | |
156 yield self.host.bridgeCall( | |
157 "eventInviteByEmail", | |
158 service, | |
159 node, | |
160 event_id, | |
161 email_addr, | |
162 {}, | |
163 u"", | |
164 u"", | |
165 u"", | |
166 u"", | |
167 u"", | |
168 u"", | |
169 profile, | |
170 ) | |
171 | |
172 else: | |
173 log.warning(_(u"Unhandled data type: {}").format(type_)) |