Mercurial > libervia-web
annotate libervia/pages/blog/view/page_meta.py @ 1213:889e8d07e957 0.7.0
0.7.0 « La Commune » release
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 24 Jul 2019 20:43:11 +0200 |
parents | 67ec22356457 |
children | b2d067339de3 |
rev | line source |
---|---|
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python2.7 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
1156
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
3 import unicodedata |
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
4 import re |
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
5 import cgi |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 from libervia.server.constants import Const as C |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 from twisted.words.protocols.jabber import jid |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 from twisted.internet import defer |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 from sat.tools.common import data_objects |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 from libervia.server import session_iface |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 from sat.core.i18n import _ |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 from sat.tools.common.template import safe |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 from sat.tools.common import uri |
1156
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
14 from sat.tools.common import data_format |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 from libervia.server import utils |
1171
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
16 from libervia.server.utils import SubPage |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 from sat.core.log import getLogger |
1156
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
18 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
19 log = getLogger(__name__) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 """generic blog (with service/node provided)""" |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 name = u'blog_view' |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 template = u"blog/articles.html" |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 uri_handlers = {(u'pubsub', u'microblog'): 'microblog_uri'} |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 RE_TEXT_URL = re.compile(ur'[^a-zA-Z,_]+') |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 TEXT_MAX_LEN = 60 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 TEXT_WORD_MIN_LENGHT = 4 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 URL_LIMIT_MARK = 90 # if canonical URL is longer than that, text will not be appended |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 def microblog_uri(self, uri_data): |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 args = [uri_data[u'path'], uri_data[u'node']] |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 if u'item' in uri_data: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 args.extend([u'id', uri_data[u'item']]) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 return self.getURL(*args) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 def parse_url(self, request): |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 """URL is /[service]/[node]/[filter_keyword]/[item]|[other] |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 if [node] is '@', default namespace is used |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 if a value is unset, default one will be used |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 keyword can be one of: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 id: next value is a item id |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 tag: next value is a blog tag |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 """ |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 data = self.getRData(request) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 try: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 service = self.nextPath(request) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 except IndexError: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 data['service'] = u'' |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 try: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 data[u"service"] = jid.JID(service) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 except Exception: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 log.warning(_(u"bad service entered: {}").format(service)) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 self.pageError(request, C.HTTP_BAD_REQUEST) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 try: |
1171
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
61 node = self.nextPath(request) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 except IndexError: |
1171
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
63 node = u'@' |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
64 data['node'] = u'' if node == u'@' else node |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 try: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 filter_kw = data['filter_keyword'] = self.nextPath(request) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 except IndexError: |
1171
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
69 filter_kw = u'@' |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 else: |
1171
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
71 if filter_kw == u'@': |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
72 # No filter, this is used when a subpage is needed, notably Atom feed |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
73 pass |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
74 elif filter_kw == u'id': |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 try: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 data[u'item'] = self.nextPath(request) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 except IndexError: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 self.pageError(request, C.HTTP_BAD_REQUEST) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 # we get one more argument in case text has been added to have a nice URL |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 try: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 self.nextPath(request) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 except IndexError: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 pass |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 elif filter_kw == u'tag': |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 try: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 data[u'tag'] = self.nextPath(request) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 except IndexError: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 self.pageError(request, C.HTTP_BAD_REQUEST) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 # invalid filter keyword |
1171
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
91 log.warning(_(u"invalid filter keyword: {filter_kw}").format( |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
92 filter_kw=filter_kw)) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 self.pageError(request, C.HTTP_BAD_REQUEST) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 |
1171
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
95 # if URL is parsed here, we'll have atom.xml available and we need to |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
96 # add the link to the page |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
97 atom_url = self.getURLByPath( |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
98 SubPage(u'blog_view'), |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
99 service, |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
100 node, |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
101 filter_kw, |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
102 SubPage(u'blog_feed_atom'), |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
103 ) |
1207
67ec22356457
pages (blog/view, u): added atom feed URL to "atom_url" in template
Goffi <goffi@goffi.org>
parents:
1173
diff
changeset
|
104 request.template_data[u'atom_url'] = atom_url |
1171
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
105 request.template_data.setdefault(u'links', []).append({ |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
106 u"href": atom_url, |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
107 u"type": "application/atom+xml", |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
108 u"rel": "alternate", |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
109 u"title": "{service}'s blog".format(service=service)}) |
469d0de8da0e
pages (blog, u): added atom feed link in "links" template data.
Goffi <goffi@goffi.org>
parents:
1156
diff
changeset
|
110 |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 @defer.inlineCallbacks |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 def appendComments(self, blog_items, identities, profile): |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 for blog_item in blog_items: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 if identities is not None: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 author = blog_item.author_jid |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 if not author: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 log.warning(_(u"no author found for item {item_id}").format(item_id=blog_item.id)) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 if author not in identities: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 identities[author] = yield self.host.bridgeCall(u'identityGet', author, profile) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 for comment_data in blog_item.comments: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 service = comment_data[u'service'] |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 node = comment_data[u'node'] |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 try: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 comments_data = yield self.host.bridgeCall(u'mbGet', |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 service, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 node, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 C.NO_LIMIT, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 [], |
1137
dfd6545a205a
pages (blog/view, tickets): use of new "order_by" feature.
Goffi <goffi@goffi.org>
parents:
1133
diff
changeset
|
131 {C.KEY_ORDER_BY: C.ORDER_BY_CREATION}, |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 profile) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 except Exception as e: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 log.warning(_(u"Can't get comments at {node} (service: {service}): {msg}").format( |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 service=service, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 node=node, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 msg=e)) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 continue |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 comments = data_objects.BlogItems(comments_data) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 blog_item.appendCommentsItems(comments) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 yield appendComments(self, comments, identities, profile) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 @defer.inlineCallbacks |
1140
e1a953512f72
pages (blog/view): pagination improvments:
Goffi <goffi@goffi.org>
parents:
1137
diff
changeset
|
145 def getBlogItems(self, request, service, node, item_id, extra, profile): |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 try: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 if item_id: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 items_id = [item_id] |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 items_id = [] |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 blog_data = yield self.host.bridgeCall(u'mbGet', |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 service.userhost(), |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 node, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 C.NO_LIMIT, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 items_id, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 extra, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 profile) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 except Exception as e: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 # FIXME: need a better way to test errors in bridge errback |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 if u"forbidden" in unicode(e): |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 self.pageError(request, 401) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 log.warning(_(u"can't retrieve blog for [{service}]: {msg}".format( |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 service = service.userhost(), msg=e))) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 blog_data = ([], {}) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 |
1140
e1a953512f72
pages (blog/view): pagination improvments:
Goffi <goffi@goffi.org>
parents:
1137
diff
changeset
|
167 defer.returnValue(data_objects.BlogItems(blog_data)) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 @defer.inlineCallbacks |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 def prepare_render(self, request): |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 data = self.getRData(request) |
1140
e1a953512f72
pages (blog/view): pagination improvments:
Goffi <goffi@goffi.org>
parents:
1137
diff
changeset
|
172 page_max = data.get(u"page_max", 10) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 # if the comments are not explicitly hidden, we show them |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 service, node, item_id, show_comments = data.get(u'service', u''), data.get(u'node', u''), data.get(u'item'), data.get(u'show_comments', True) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 profile = self.getProfile(request) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 if profile is None: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 profile = C.SERVICE_PROFILE |
1133
122dd136d1ab
pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
178 profile_connected = False |
122dd136d1ab
pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
179 else: |
122dd136d1ab
pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
180 profile_connected = True |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 ## pagination/filtering parameters |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 if item_id: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 extra = {} |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 else: |
1141
02fc28aac2b6
pages: move pagination core from blog to LiberviaPage so it can be reused:
Goffi <goffi@goffi.org>
parents:
1140
diff
changeset
|
186 extra = self.getPubsubExtra(request, page_max=page_max) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 tag = data.get('tag') |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 if tag: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 extra[u'mam_filter_{}'.format(C.MAM_FILTER_CATEGORY)] = tag |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 ## main data ## |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 # we get data from backend/XMPP here |
1140
e1a953512f72
pages (blog/view): pagination improvments:
Goffi <goffi@goffi.org>
parents:
1137
diff
changeset
|
193 items = yield getBlogItems(self, request, service, node, item_id, extra, profile) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 ## navigation ## |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 # no let's fill service, node and pagination URLs |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 template_data = request.template_data |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 if u'service' not in template_data: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 template_data[u'service'] = service |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 if u'node' not in template_data: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 template_data[u'node'] = node |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 target_profile = template_data.get(u'target_profile') |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 if items: |
1141
02fc28aac2b6
pages: move pagination core from blog to LiberviaPage so it can be reused:
Goffi <goffi@goffi.org>
parents:
1140
diff
changeset
|
205 if not item_id: |
02fc28aac2b6
pages: move pagination core from blog to LiberviaPage so it can be reused:
Goffi <goffi@goffi.org>
parents:
1140
diff
changeset
|
206 self.setPagination(request, items.metadata) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 if item_id: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 # if item id has been specified in URL and it's not found, |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 # we must return an error |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 self.pageError(request, C.HTTP_NOT_FOUND) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 ## identities ## |
1133
122dd136d1ab
pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
214 # identities are used to show nice nickname or avatars |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 ## Comments ## |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 # if comments are requested, we need to take them |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 if show_comments: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 yield appendComments(self, items, identities, profile) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 ## URLs ## |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 # We will fill items_http_uri and tags_http_uri in template_data with suitable urls |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 # if we know the profile, we use it instead of service + blog (nicer url) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 if target_profile is None: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 blog_base_url_item = self.getPageByName(u'blog_view').getURL(service.full(), node or u'@', u'id') |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 blog_base_url_tag = self.getPageByName(u'blog_view').getURL(service.full(), node or u'@', u'tag') |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 blog_base_url_item = self.getURLByNames([(u'user', [target_profile]), (u'user_blog', [u'id'])]) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 blog_base_url_tag = self.getURLByNames([(u'user', [target_profile]), (u'user_blog', [u'tag'])]) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 # we also set the background image if specified by user |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 bg_img = yield self.host.bridgeCall(u'asyncGetParamA', u'Background', u'Blog page', u'value', -1, template_data[u'target_profile']) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 if bg_img: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 template_data['dynamic_style'] = safe(u""" |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 :root { |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 --bg-img: url("%s"); |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 } |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 """ % cgi.escape(bg_img, True)) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 template_data[u'items'] = data[u'items'] = items |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 if request.args.get('reverse') == ['1']: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 template_data[u'items'].items.reverse() |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 template_data[u'items_http_uri'] = items_http_uri = {} |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 template_data[u'tags_http_uri'] = tags_http_uri = {} |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 for item in items: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 blog_canonical_url = u'/'.join([blog_base_url_item, utils.quote(item.id)]) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 if len(blog_canonical_url) > URL_LIMIT_MARK: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 blog_url = blog_canonical_url |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 # we add text from title or body at the end of URL |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 # to make it more human readable |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 text = item.title or item.content |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 # we change special chars to ascii one, trick found at https://stackoverflow.com/a/3194567 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 text = unicodedata.normalize('NFD', text).encode('ascii', 'ignore') |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 text = RE_TEXT_URL.sub(u' ', text).lower() |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 text = u'-'.join([t for t in text.split() if t and len(t)>=TEXT_WORD_MIN_LENGHT]) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 while len(text) > TEXT_MAX_LEN: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 if u'-' in text: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 text = text.rsplit(u'-', 1)[0] |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 text = text[:TEXT_MAX_LEN] |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 if text: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 blog_url = blog_canonical_url + u'/' + text |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 blog_url = blog_canonical_url |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 items_http_uri[item.id] = self.host.getExtBaseURL(request, blog_url) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 for tag in item.tags: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 if tag not in tags_http_uri: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 tag_url = u'/'.join([blog_base_url_tag, utils.quote(tag)]) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 tags_http_uri[tag] = self.host.getExtBaseURL(request, tag_url) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 # if True, page should display a comment box |
1133
122dd136d1ab
pages (blog/view): allow commenting when profile is connected
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
276 template_data[u'allow_commenting'] = data.get(u'allow_commenting', profile_connected) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 # last but not least, we add a xmpp: link to the node |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 uri_args = {u'path': service.full()} |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 if node: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 uri_args[u'node'] = node |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 if item_id: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 uri_args[u'item'] = item_id |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 template_data[u'xmpp_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', **uri_args) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 @defer.inlineCallbacks |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 def on_data_post(self, request): |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 profile = self.getProfile(request) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 if profile is None: |
1173
0f37b65fe7c2
server: replaced wrong usage of C.HTTP_UNAUTHORIZED by C.HTTP_FORBIDDEN
Goffi <goffi@goffi.org>
parents:
1171
diff
changeset
|
291 self.pageError(request, C.HTTP_FORBIDDEN) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 type_ = self.getPostedData(request, u'type') |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 if type_ == u'comment': |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 service, node, body = self.getPostedData(request, (u'service', u'node', u'body')) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 if not body: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 self.pageError(request, C.HTTP_BAD_REQUEST) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 comment_data = {u"content": body} |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 try: |
1156
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
300 yield self.host.bridgeCall(u'mbSend', |
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
301 service, |
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
302 node, |
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
303 data_format.serialise(comment_data), |
3048bd137aaf
server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
304 profile) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 except Exception as e: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 if u"forbidden" in unicode(e): |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 self.pageError(request, 401) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 raise e |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 else: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 log.warning(_(u"Unhandled data type: {}").format(type_)) |