annotate src/pages/common/blog/page_meta.py @ 1075:ee1327eb2b84

pages: updated default menu
author Goffi <goffi@goffi.org>
date Sat, 24 Mar 2018 11:25:36 +0100
parents 7dc20bacd3b6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2.7
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from libervia.server.constants import Const as C
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from twisted.words.protocols.jabber import jid
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from twisted.internet import defer
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.tools.common import data_objects
947
92f0eeb6dc72 pages: cache identities identities in session + get identities for comments in blog
Goffi <goffi@goffi.org>
parents: 939
diff changeset
7 from libervia.server import session_iface
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from sat.core.i18n import _
1029
78b7b5ec7ca1 pages (common/blog): if background is set in user preferences, use it
Goffi <goffi@goffi.org>
parents: 1026
diff changeset
9 from sat.tools.common.template import safe
1072
7dc20bacd3b6 pages (common/blog): added xmpp_uri in template_data
Goffi <goffi@goffi.org>
parents: 1057
diff changeset
10 from sat.tools.common import uri
1048
d4290178662c pages (common/blog): fixed bad import
Goffi <goffi@goffi.org>
parents: 1042
diff changeset
11 from libervia.server import utils
1051
d3ac6fb10fd5 pages (common/blog): tranform special characters to their ascii equivalent
Goffi <goffi@goffi.org>
parents: 1048
diff changeset
12 import unicodedata
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
13 import re
1029
78b7b5ec7ca1 pages (common/blog): if background is set in user preferences, use it
Goffi <goffi@goffi.org>
parents: 1026
diff changeset
14 import cgi
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
15 from sat.core.log import getLogger
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
16 log = getLogger('pages/common/blog')
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
17
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
18 """generic blog (with service/node provided)"""
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
19 name = u'blog'
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
20 template = u"blog/articles.html"
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
21 uri_handlers = {(u'pubsub', u'microblog'): 'microblog_uri'}
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
22
1051
d3ac6fb10fd5 pages (common/blog): tranform special characters to their ascii equivalent
Goffi <goffi@goffi.org>
parents: 1048
diff changeset
23 RE_TEXT_URL = re.compile(ur'[^a-zA-Z,_]+')
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
24 TEXT_MAX_LEN = 60
1042
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
25 TEXT_WORD_MIN_LENGHT = 4
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
26 URL_LIMIT_MARK = 90 # if canonical URL is longer than that, text will not be appended
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
27
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
28
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
29 def microblog_uri(self, uri_data):
1038
6b906b1f419a pages: fixed XMPP URIs handling
Goffi <goffi@goffi.org>
parents: 1036
diff changeset
30 args = [uri_data[u'path'], uri_data[u'node']]
6b906b1f419a pages: fixed XMPP URIs handling
Goffi <goffi@goffi.org>
parents: 1036
diff changeset
31 if u'item' in uri_data:
6b906b1f419a pages: fixed XMPP URIs handling
Goffi <goffi@goffi.org>
parents: 1036
diff changeset
32 args.extend([u'id', uri_data[u'item']])
6b906b1f419a pages: fixed XMPP URIs handling
Goffi <goffi@goffi.org>
parents: 1036
diff changeset
33 return self.getURL(*args)
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
34
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
35 def parse_url(self, request):
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
36 """URL is /[service]/[node]/[filter_keyword]/[item]|[other]
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
37
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
38 if [node] is '@', default namespace is used
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
39 if a value is unset, default one will be used
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
40 keyword can be one of:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
41 id: next value is a item id
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
42 tag: next value is a blog tag
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
43 """
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
44 data = self.getRData(request)
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
45
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
46 try:
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
47 service = self.nextPath(request)
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
48 except IndexError:
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
49 data['service'] = u''
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
50 else:
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
51 try:
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
52 data[u"service"] = jid.JID(service)
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
53 except Exception:
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
54 log.warning(_(u"bad service entered: {}").format(service))
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.pageError(request, C.HTTP_BAD_REQUEST)
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
56
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
57 try:
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
58 data['node'] = self.nextPath(request)
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
59 except IndexError:
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
60 data['node'] = u''
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
61 else:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
62 if data['node'] == u'@':
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
63 data['node'] = u''
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
64
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
65 try:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
66 filter_kw = data['filter_keyword'] = self.nextPath(request)
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
67 except IndexError:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
68 pass
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
69 else:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
70 if filter_kw == u'id':
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
71 try:
1024
2ae3b6291456 pages (common/blog): handle tags filtering using "/tag/[tag]" in path
Goffi <goffi@goffi.org>
parents: 1016
diff changeset
72 data[u'item'] = self.nextPath(request)
2ae3b6291456 pages (common/blog): handle tags filtering using "/tag/[tag]" in path
Goffi <goffi@goffi.org>
parents: 1016
diff changeset
73 except IndexError:
2ae3b6291456 pages (common/blog): handle tags filtering using "/tag/[tag]" in path
Goffi <goffi@goffi.org>
parents: 1016
diff changeset
74 self.pageError(request, C.HTTP_BAD_REQUEST)
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
75 # we get one more argument in case text has been added to have a nice URL
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
76 try:
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
77 self.nextPath(request)
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
78 except IndexError:
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
79 pass
1024
2ae3b6291456 pages (common/blog): handle tags filtering using "/tag/[tag]" in path
Goffi <goffi@goffi.org>
parents: 1016
diff changeset
80 elif filter_kw == u'tag':
2ae3b6291456 pages (common/blog): handle tags filtering using "/tag/[tag]" in path
Goffi <goffi@goffi.org>
parents: 1016
diff changeset
81 try:
2ae3b6291456 pages (common/blog): handle tags filtering using "/tag/[tag]" in path
Goffi <goffi@goffi.org>
parents: 1016
diff changeset
82 data[u'tag'] = self.nextPath(request)
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
83 except IndexError:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
84 self.pageError(request, C.HTTP_BAD_REQUEST)
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
85 else:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
86 # invalid filter keyword
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
87 log.warning(_(u"invalid filter keyword: {filter_kw}").format(filter_kw=filter_kw))
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
88 self.pageError(request, C.HTTP_BAD_REQUEST)
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
89
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
90
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
91 @defer.inlineCallbacks
947
92f0eeb6dc72 pages: cache identities identities in session + get identities for comments in blog
Goffi <goffi@goffi.org>
parents: 939
diff changeset
92 def appendComments(self, blog_items, identities, profile):
932
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
93 for blog_item in blog_items:
947
92f0eeb6dc72 pages: cache identities identities in session + get identities for comments in blog
Goffi <goffi@goffi.org>
parents: 939
diff changeset
94 if identities is not None:
92f0eeb6dc72 pages: cache identities identities in session + get identities for comments in blog
Goffi <goffi@goffi.org>
parents: 939
diff changeset
95 author = blog_item.author_jid
1039
6bc7768faa5d pages (common/blog): don't fail if author is missing
Goffi <goffi@goffi.org>
parents: 1038
diff changeset
96 if not author:
6bc7768faa5d pages (common/blog): don't fail if author is missing
Goffi <goffi@goffi.org>
parents: 1038
diff changeset
97 log.warning(_(u"no author found for item {item_id}").format(item_id=blog_item.id))
6bc7768faa5d pages (common/blog): don't fail if author is missing
Goffi <goffi@goffi.org>
parents: 1038
diff changeset
98 else:
6bc7768faa5d pages (common/blog): don't fail if author is missing
Goffi <goffi@goffi.org>
parents: 1038
diff changeset
99 if author not in identities:
6bc7768faa5d pages (common/blog): don't fail if author is missing
Goffi <goffi@goffi.org>
parents: 1038
diff changeset
100 identities[author] = yield self.host.bridgeCall(u'identityGet', author, profile)
932
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
101 for comment_data in blog_item.comments:
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
102 service = comment_data[u'service']
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
103 node = comment_data[u'node']
948
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
104 try:
1040
90b11cd6f28f pages (common/blog): use bridgeCall instead of bridge
Goffi <goffi@goffi.org>
parents: 1039
diff changeset
105 comments_data = yield self.host.bridgeCall(u'mbGet',
948
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
106 service,
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
107 node,
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
108 C.NO_LIMIT,
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
109 [],
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
110 {},
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
111 profile)
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
112 except Exception as e:
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
113 log.warning(_(u"Can't get comments at {node} (service: {service}): {msg}").format(
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
114 service=service,
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
115 node=node,
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
116 msg=e))
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
117 continue
c20ac29d869f pages (common/blog): don't fail if an error is raised while getting comment
Goffi <goffi@goffi.org>
parents: 947
diff changeset
118
932
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
119 comments = data_objects.BlogItems(comments_data)
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
120 blog_item.appendCommentsItems(comments)
947
92f0eeb6dc72 pages: cache identities identities in session + get identities for comments in blog
Goffi <goffi@goffi.org>
parents: 939
diff changeset
121 yield appendComments(self, comments, identities, profile)
932
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
122
1011
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
123 @defer.inlineCallbacks
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
124 def getBlogData(self, request, service, node, item_id, extra, profile):
1011
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
125 try:
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
126 if item_id:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
127 items_id = [item_id]
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
128 else:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
129 items_id = []
1040
90b11cd6f28f pages (common/blog): use bridgeCall instead of bridge
Goffi <goffi@goffi.org>
parents: 1039
diff changeset
130 blog_data = yield self.host.bridgeCall(u'mbGet',
1011
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
131 service.userhost(),
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
132 node,
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
133 C.NO_LIMIT,
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
134 items_id,
1011
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
135 extra,
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
136 profile)
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
137 except Exception as e:
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
138 # FIXME: need a better way to test errors in bridge errback
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
139 if u"forbidden" in unicode(e):
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
140 self.pageError(request, 401)
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
141 else:
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
142 raise e
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
143
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
144 items = data_objects.BlogItems(blog_data)
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
145 defer.returnValue((blog_data, items))
932
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
146
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
147 @defer.inlineCallbacks
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
148 def prepare_render(self, request):
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
149 data = self.getRData(request)
932
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
150 # if the comments are not explicitly hidden, we show them
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
151 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)
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
152 profile = self.getProfile(request)
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
153 if profile is None:
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
154 profile = C.SERVICE_PROFILE
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
155
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
156 ## pagination/filtering parameters
1011
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
157 params = self.getAllPostedData(request, multiple=False)
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
158 if item_id:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
159 extra = {}
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
160 else:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
161 extra = {u'rsm_max': u'10'}
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
162 if u'after' in params:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
163 extra[u'rsm_after'] = params[u'after']
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
164 elif u'before' in params:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
165 extra[u'rsm_before'] = params[u'before']
1024
2ae3b6291456 pages (common/blog): handle tags filtering using "/tag/[tag]" in path
Goffi <goffi@goffi.org>
parents: 1016
diff changeset
166 tag = data.get('tag')
2ae3b6291456 pages (common/blog): handle tags filtering using "/tag/[tag]" in path
Goffi <goffi@goffi.org>
parents: 1016
diff changeset
167 if tag:
2ae3b6291456 pages (common/blog): handle tags filtering using "/tag/[tag]" in path
Goffi <goffi@goffi.org>
parents: 1016
diff changeset
168 extra[u'mam_filter_{}'.format(C.MAM_FILTER_CATEGORY)] = tag
928
ee243d48100e pages (common): added common hierarchy for reusable pages (blog is the first)
Goffi <goffi@goffi.org>
parents:
diff changeset
169
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
170 ## main data ##
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
171 # we get data from backend/XMPP here
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
172 blog_data, items = yield getBlogData(self, request, service, node, item_id, extra, profile)
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
173
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
174 ## navigation ##
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
175 # no let's fill service, node and pagination URLs
947
92f0eeb6dc72 pages: cache identities identities in session + get identities for comments in blog
Goffi <goffi@goffi.org>
parents: 939
diff changeset
176 template_data = request.template_data
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
177 if u'service' not in template_data:
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
178 template_data[u'service'] = service
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
179 if u'node' not in template_data:
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
180 template_data[u'node'] = node
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
181 target_profile = template_data.get(u'target_profile')
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
182
1011
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
183 if items:
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
184 if not item_id:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
185 last_id = items[-1].id
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
186 template_data['older_url'] = self.getParamURL(request, after=last_id)
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
187 if u'before' in params or u'after' in params:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
188 first_id = items[0].id
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
189 template_data['newer_url'] = self.getParamURL(request, before=first_id)
1011
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
190 else:
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
191 if item_id:
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
192 # if item id has been specified in URL and it's not found,
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
193 # we must return an error
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
194 self.pageError(request, C.HTTP_NOT_FOUND)
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
195
1011
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
196 # no items, we have requested items before last post, or blog is empty
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
197 extra = {u'rsm_max': u'10'}
1016
fc1c913cc9d1 pages (blog_new, common/blog): various blog improvments:
Goffi <goffi@goffi.org>
parents: 1011
diff changeset
198 blog_data, items = yield getBlogData(self, request, service, node, None, extra, profile)
1011
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
199 if items:
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
200 last_id = items[-1].id
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
201 template_data['older_url'] = self.getParamURL(request, after=last_id)
fe08a5c95b27 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
Goffi <goffi@goffi.org>
parents: 996
diff changeset
202
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
203 ## identities ##
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
204 # identities are use to show nice nickname or avatars
947
92f0eeb6dc72 pages: cache identities identities in session + get identities for comments in blog
Goffi <goffi@goffi.org>
parents: 939
diff changeset
205 identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities
932
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
206
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
207 ## Comments ##
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
208 # if comments are requested, we need to take them
932
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
209 if show_comments:
947
92f0eeb6dc72 pages: cache identities identities in session + get identities for comments in blog
Goffi <goffi@goffi.org>
parents: 939
diff changeset
210 yield appendComments(self, items, identities, profile)
932
af6a62e21053 pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
Goffi <goffi@goffi.org>
parents: 928
diff changeset
211
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
212 ## URLs ##
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
213 # We will fill items_http_uri and tags_http_uri in template_data with suitable urls
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
214 # if we know the profile, we use it instead of service + blog (nicer url)
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
215 if target_profile is None:
1042
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
216 blog_base_url_item = self.getPageByName(u'blog_view').getURL(service.full(), node or u'@', u'id')
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
217 blog_base_url_tag = self.getPageByName(u'blog_view').getURL(service.full(), node or u'@', u'tag')
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
218 else:
1042
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
219 blog_base_url_item = self.getURLByNames([(u'user', [target_profile]), (u'user_blog', [u'id'])])
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
220 blog_base_url_tag = self.getURLByNames([(u'user', [target_profile]), (u'user_blog', [u'tag'])])
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
221 # we also set the background image if specified by user
1029
78b7b5ec7ca1 pages (common/blog): if background is set in user preferences, use it
Goffi <goffi@goffi.org>
parents: 1026
diff changeset
222 bg_img = yield self.host.bridgeCall(u'asyncGetParamA', u'Background', u'Blog page', u'value', -1, template_data[u'target_profile'])
78b7b5ec7ca1 pages (common/blog): if background is set in user preferences, use it
Goffi <goffi@goffi.org>
parents: 1026
diff changeset
223 if bg_img:
78b7b5ec7ca1 pages (common/blog): if background is set in user preferences, use it
Goffi <goffi@goffi.org>
parents: 1026
diff changeset
224 template_data['dynamic_style'] = safe(u"""
78b7b5ec7ca1 pages (common/blog): if background is set in user preferences, use it
Goffi <goffi@goffi.org>
parents: 1026
diff changeset
225 :root {
78b7b5ec7ca1 pages (common/blog): if background is set in user preferences, use it
Goffi <goffi@goffi.org>
parents: 1026
diff changeset
226 --bg-img: url("%s");
78b7b5ec7ca1 pages (common/blog): if background is set in user preferences, use it
Goffi <goffi@goffi.org>
parents: 1026
diff changeset
227 }
78b7b5ec7ca1 pages (common/blog): if background is set in user preferences, use it
Goffi <goffi@goffi.org>
parents: 1026
diff changeset
228 """ % cgi.escape(bg_img, True))
933
e4c13a995e0b pages (common/blog): data post (i.e. new comments) is now handled
Goffi <goffi@goffi.org>
parents: 932
diff changeset
229
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
230 template_data[u'items'] = data[u'items'] = items
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
231 if request.args.get('reverse') == ['1']:
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
232 template_data[u'items'].items.reverse()
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
233 template_data[u'items_http_uri'] = items_http_uri = {}
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
234 template_data[u'tags_http_uri'] = tags_http_uri = {}
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
235
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
236
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
237 for item in items:
1042
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
238 blog_canonical_url = u'/'.join([blog_base_url_item, utils.quote(item.id)])
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
239 if len(blog_canonical_url) > URL_LIMIT_MARK:
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
240 blog_url = blog_canonical_url
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
241 else:
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
242 # we add text from title or body at the end of URL
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
243 # to make it more human readable
1042
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
244 text = item.title or item.content
1051
d3ac6fb10fd5 pages (common/blog): tranform special characters to their ascii equivalent
Goffi <goffi@goffi.org>
parents: 1048
diff changeset
245 # we change special chars to ascii one, trick found at https://stackoverflow.com/a/3194567
d3ac6fb10fd5 pages (common/blog): tranform special characters to their ascii equivalent
Goffi <goffi@goffi.org>
parents: 1048
diff changeset
246 text = unicodedata.normalize('NFD', text).encode('ascii', 'ignore')
1042
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
247 text = RE_TEXT_URL.sub(u' ', text).lower()
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
248 text = u'-'.join([t for t in text.split() if t and len(t)>=TEXT_WORD_MIN_LENGHT])
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
249 while len(text) > TEXT_MAX_LEN:
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
250 if u'-' in text:
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
251 text = text.rsplit(u'-', 1)[0]
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
252 else:
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
253 text = text[:TEXT_MAX_LEN]
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
254 if text:
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
255 blog_url = blog_canonical_url + u'/' + text
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
256 else:
1042
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
257 blog_url = blog_canonical_url
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
258
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
259 items_http_uri[item.id] = self.host.getExtBaseURL(request, blog_url)
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
260 for tag in item.tags:
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
261 if tag not in tags_http_uri:
1042
f7d45c989c05 pages (common/blog): use more friendly URLs
Goffi <goffi@goffi.org>
parents: 1040
diff changeset
262 tag_url = u'/'.join([blog_base_url_tag, utils.quote(tag)])
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
263 tags_http_uri[tag] = self.host.getExtBaseURL(request, tag_url)
1057
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
264
50ba8947a6e8 common/blog: "service" and "node" are now set in template_data
Goffi <goffi@goffi.org>
parents: 1051
diff changeset
265 # if True, page should display a comment box
1036
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
266 template_data[u'allow_commenting'] = data.get(u'allow_commenting', False)
f5661761b1b9 pages (common/blog): URL improvments:
Goffi <goffi@goffi.org>
parents: 1029
diff changeset
267
1072
7dc20bacd3b6 pages (common/blog): added xmpp_uri in template_data
Goffi <goffi@goffi.org>
parents: 1057
diff changeset
268 # last but not least, we add a xmpp: link to the node
7dc20bacd3b6 pages (common/blog): added xmpp_uri in template_data
Goffi <goffi@goffi.org>
parents: 1057
diff changeset
269 uri_args = {u'path': service.full()}
7dc20bacd3b6 pages (common/blog): added xmpp_uri in template_data
Goffi <goffi@goffi.org>
parents: 1057
diff changeset
270 if node:
7dc20bacd3b6 pages (common/blog): added xmpp_uri in template_data
Goffi <goffi@goffi.org>
parents: 1057
diff changeset
271 uri_args[u'node'] = node
7dc20bacd3b6 pages (common/blog): added xmpp_uri in template_data
Goffi <goffi@goffi.org>
parents: 1057
diff changeset
272 if item_id:
7dc20bacd3b6 pages (common/blog): added xmpp_uri in template_data
Goffi <goffi@goffi.org>
parents: 1057
diff changeset
273 uri_args[u'item'] = item_id
7dc20bacd3b6 pages (common/blog): added xmpp_uri in template_data
Goffi <goffi@goffi.org>
parents: 1057
diff changeset
274 template_data[u'xmpp_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', **uri_args)
7dc20bacd3b6 pages (common/blog): added xmpp_uri in template_data
Goffi <goffi@goffi.org>
parents: 1057
diff changeset
275
933
e4c13a995e0b pages (common/blog): data post (i.e. new comments) is now handled
Goffi <goffi@goffi.org>
parents: 932
diff changeset
276
e4c13a995e0b pages (common/blog): data post (i.e. new comments) is now handled
Goffi <goffi@goffi.org>
parents: 932
diff changeset
277 @defer.inlineCallbacks
e4c13a995e0b pages (common/blog): data post (i.e. new comments) is now handled
Goffi <goffi@goffi.org>
parents: 932
diff changeset
278 def on_data_post(self, request):
e4c13a995e0b pages (common/blog): data post (i.e. new comments) is now handled
Goffi <goffi@goffi.org>
parents: 932
diff changeset
279 profile = self.getProfile(request)
e4c13a995e0b pages (common/blog): data post (i.e. new comments) is now handled
Goffi <goffi@goffi.org>
parents: 932
diff changeset
280 if profile is None:
e4c13a995e0b pages (common/blog): data post (i.e. new comments) is now handled
Goffi <goffi@goffi.org>
parents: 932
diff changeset
281 self.pageError(request, C.HTTP_UNAUTHORIZED)
939
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
282 type_ = self.getPostedData(request, u'type')
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
283 if type_ == u'comment':
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
284 service, node, body = self.getPostedData(request, (u'service', u'node', u'body'))
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
285
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
286 if not body:
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
287 self.pageError(request, C.HTTP_BAD_REQUEST)
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
288 comment_data = {u"content": body}
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
289 try:
1040
90b11cd6f28f pages (common/blog): use bridgeCall instead of bridge
Goffi <goffi@goffi.org>
parents: 1039
diff changeset
290 yield self.host.bridgeCall(u'mbSend', service, node, comment_data, profile)
939
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
291 except Exception as e:
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
292 if u"forbidden" in unicode(e):
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
293 self.pageError(request, 401)
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
294 else:
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
295 raise e
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
296 else:
1375b96f4309 pages (common/blog): check posted data type for comments
Goffi <goffi@goffi.org>
parents: 933
diff changeset
297 log.warning(_(u"Unhandled data type: {}").format(type_))