Mercurial > libervia-web
comparison src/pages/forums/view/page_meta.py @ 1058:2290b6ec3991
pages (forums): first draft
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 30 Jan 2018 08:15:04 +0100 |
parents | |
children | 880ea673aaff |
comparison
equal
deleted
inserted
replaced
1057:50ba8947a6e8 | 1058:2290b6ec3991 |
---|---|
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 sat.core.i18n import _ | |
7 from sat.core.log import getLogger | |
8 log = getLogger('pages/forums/view') | |
9 | |
10 name = u"forum_view" | |
11 access = C.PAGES_ACCESS_PUBLIC | |
12 template = u"forum/view.html" | |
13 | |
14 | |
15 def parse_url(self, request): | |
16 self.getPathArgs(request, ['service', 'node'], 2, | |
17 service = u'jid') | |
18 | |
19 @defer.inlineCallbacks | |
20 def prepare_render(self, request): | |
21 data = self.getRData(request) | |
22 data['show_comments'] = False | |
23 blog_page = self.getPageByName(u'blog') | |
24 request.args['before'] = [''] | |
25 request.args['reverse'] = ['1'] | |
26 yield blog_page.prepare_render(self, request) | |
27 request.template_data[u'login_url'] = self.getPageRedirectURL(request) | |
28 | |
29 @defer.inlineCallbacks | |
30 def on_data_post(self, request): | |
31 profile = self.getProfile(request) | |
32 if profile is None: | |
33 self.pageError(request, C.HTTP_UNAUTHORIZED) | |
34 type_ = self.getPostedData(request, u'type') | |
35 if type_ == u'comment': | |
36 service, node, body = self.getPostedData(request, (u'service', u'node', u'body')) | |
37 | |
38 if not body: | |
39 self.pageError(request, C.HTTP_BAD_REQUEST) | |
40 mb_data = {u"content": body} | |
41 try: | |
42 yield self.host.bridgeCall(u'mbSend', service, node, mb_data, profile) | |
43 except Exception as e: | |
44 if u"forbidden" in unicode(e): | |
45 self.pageError(request, 401) | |
46 else: | |
47 raise e | |
48 else: | |
49 log.warning(_(u"Unhandled data type: {}").format(type_)) |