Mercurial > libervia-web
annotate libervia/server/blog.py @ 1148:3c7a64adfd42
pages: use absolute path for build_path + added page_url to template (which is getURL() without argument)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Jan 2019 20:15:24 +0100 |
parents | 2af117bfe6cc |
children | 3048bd137aaf |
rev | line source |
---|---|
10 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
1144 | 5 # Copyright (C) 2011-2019 Jérôme Poisson <goffi@goffi.org> |
818 | 6 # Copyright (C) 2013-2016 Adrien Cossa <souliane@mailoo.org> |
10 | 7 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
8 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
9 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
10 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
11 # (at your option) any later version. |
10 | 12 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
13 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
16 # GNU Affero General Public License for more details. |
10 | 17 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
18 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
331
diff
changeset
|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
10 | 20 |
586
3eb3a2c0c011
browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
487
diff
changeset
|
21 from sat.core.i18n import _, D_ |
847
330db23d4a44
server (blog): call fixXHTMLLinks on XHTML content
souliane <souliane@mailoo.org>
parents:
831
diff
changeset
|
22 from sat_frontends.tools.strings import addURLToText, fixXHTMLLinks |
483
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
23 from sat.core.log import getLogger |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
24 |
483
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
25 log = getLogger(__name__) |
898
2d15b484ca33
blog, browser: updated imports to reflect renaming of common.py to common/data_format.py
Goffi <goffi@goffi.org>
parents:
896
diff
changeset
|
26 from sat.tools.common import data_format |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
27 from sat.tools import xml_tools |
728
9d35d75566fb
server_side (blog): clean error message when unknown profile is requested
souliane <souliane@mailoo.org>
parents:
727
diff
changeset
|
28 from dbus.exceptions import DBusException |
388
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
29 from twisted.internet import defer |
10 | 30 from twisted.web import server |
31 from twisted.web.resource import Resource | |
32 from twisted.words.protocols.jabber.jid import JID | |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
33 from twisted.words.xish import domish |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
34 from jinja2 import Environment, PackageLoader |
10 | 35 from datetime import datetime |
388
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
36 import re |
483
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
37 import os |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
38 import sys |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
39 import urllib |
229
e632f77c4219
bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents:
228
diff
changeset
|
40 |
588
c8cca1a373dd
server_side: static blog: convert \n in raw text message to <br/>
souliane <souliane@mailoo.org>
parents:
586
diff
changeset
|
41 from libervia.server.html_tools import sanitizeHtml, convertNewLinesToXHTML |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
446
diff
changeset
|
42 from libervia.server.constants import Const as C |
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
446
diff
changeset
|
43 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
44 NS_ATOM = "http://www.w3.org/2005/Atom" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
45 PARAMS_TO_GET = ( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
46 C.STATIC_BLOG_PARAM_TITLE, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
47 C.STATIC_BLOG_PARAM_BANNER, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
48 C.STATIC_BLOG_PARAM_KEYWORDS, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
49 C.STATIC_BLOG_PARAM_DESCRIPTION, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
50 ) |
854 | 51 re_strip_empty_div = re.compile(r"<div ?/>|<div> *?</div>") |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
52 |
950
67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
53 # TODO: check disco features and use max_items when RSM is not available |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
54 # FIXME: change navigation links handling, this is is fragile |
950
67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
55 # XXX: this page will disappear, LiberviaPage will be used instead |
67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
56 # TODO: delete this page and create a compatibility page for links |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
57 |
827
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
58 |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
59 def getDefaultQueryData(request): |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
60 """Return query data which must be present in all links |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
61 |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
62 @param request(twisted.web.http.Request): request instance comming from render |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
63 @return (dict): a dict with values as expected by urllib.urlencode |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
64 """ |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
65 default_query_data = {} |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
66 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
67 default_query_data["tag"] = request.extra_dict[ |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
68 "mam_filter_{}".format(C.MAM_FILTER_CATEGORY) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
69 ].encode("utf-8") |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
70 except KeyError: |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
71 pass |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
72 return default_query_data |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
73 |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
74 |
827
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
75 def _quote(value): |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
76 """Quote a value for use in url |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
77 |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
78 @param value(unicode): value to quote |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
79 @return (str): quoted value |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
80 """ |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
81 return urllib.quote(value.encode("utf-8"), "") |
827
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
82 |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
83 |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
84 def _unquote(quoted_value): |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
85 """Unquote a value coming from url |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
86 |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
87 @param unquote_value(str): value to unquote |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
88 @return (unicode): unquoted value |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
89 """ |
854 | 90 assert not isinstance(quoted_value, unicode) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
91 return urllib.unquote(quoted_value).decode("utf-8") |
827
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
92 |
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
93 |
893
298fbe562060
blog: escape "&" when encoding URL, so they can be used without escaping in the HTML template
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
94 def _urlencode(query): |
298fbe562060
blog: escape "&" when encoding URL, so they can be used without escaping in the HTML template
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
95 """Same as urllib.urlencode, but use '&' instead of '&'""" |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
96 return "&".join( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
97 [ |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
98 "{}={}".format(urllib.quote_plus(str(k)), urllib.quote_plus(str(v))) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
99 for k, v in query.iteritems() |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
100 ] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
101 ) |
893
298fbe562060
blog: escape "&" when encoding URL, so they can be used without escaping in the HTML template
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
102 |
298fbe562060
blog: escape "&" when encoding URL, so they can be used without escaping in the HTML template
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
103 |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
104 class TemplateProcessor(object): |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
105 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
106 THEME = "default" |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
107 |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
108 def __init__(self, host): |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
109 self.host = host |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
110 |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
111 # add Libervia's themes directory to the python path |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
112 sys.path.append(os.path.dirname(os.path.normpath(self.host.themes_dir))) |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
113 themes = os.path.basename(os.path.normpath(self.host.themes_dir)) |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
114 self.env = Environment(loader=PackageLoader(themes, self.THEME)) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
115 |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
116 def useTemplate(self, request, tpl, data=None): |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
117 theme_url = os.path.join("/", C.THEMES_URL, self.THEME) |
10 | 118 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
119 data_ = { |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
120 "images": os.path.join(theme_url, "images"), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
121 "styles": os.path.join(theme_url, "styles"), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
122 } |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
123 if data: |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
124 data_.update(data) |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
125 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
126 template = self.env.get_template("{}.html".format(tpl)) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
127 return template.render(**data_).encode("utf-8") |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
128 |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
129 |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
130 class MicroBlog(Resource, TemplateProcessor): |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
131 isLeaf = True |
10 | 132 |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
229
diff
changeset
|
133 def __init__(self, host): |
10 | 134 self.host = host |
135 Resource.__init__(self) | |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
136 TemplateProcessor.__init__(self, host) |
484
ae86b32b959c
server side (blog): manage our own avatars cache because existing entity data are not updated
souliane <souliane@mailoo.org>
parents:
483
diff
changeset
|
137 self.avatars_cache = {} |
483
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
138 |
950
67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
139 def _avatarPathToUrl(self, avatar, request, bare_jid_s): |
67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
140 filename = os.path.basename(avatar) |
67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
141 avatar_url = os.path.join(self.host.service_cache_url, filename) |
67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
142 self.avatars_cache[bare_jid_s] = avatar_url |
67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
143 return avatar_url |
746
25984ca4aef2
server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents:
743
diff
changeset
|
144 |
950
67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
145 def getAvatarURL(self, pub_jid, request): |
727
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
146 """Return avatar of a jid if in cache, else ask for it. |
483
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
147 |
727
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
148 @param pub_jid (JID): publisher JID |
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
149 @return: deferred avatar URL (unicode) |
483
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
150 """ |
727
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
151 bare_jid_s = pub_jid.userhost() |
483
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
152 try: |
727
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
153 url = self.avatars_cache[bare_jid_s] |
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
154 except KeyError: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
155 self.avatars_cache[ |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
156 bare_jid_s |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
157 ] = "" # avoid to request the vcard several times |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
158 d = self.host.bridgeCall( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
159 "avatarGet", bare_jid_s, False, False, C.SERVICE_PROFILE |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
160 ) |
950
67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
161 d.addCallback(self._avatarPathToUrl, request, bare_jid_s) |
727
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
162 return d |
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
163 return defer.succeed(url if url else C.DEFAULT_AVATAR_URL) |
10 | 164 |
165 def render_GET(self, request): | |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
166 if not request.postpath or len(request.postpath) > 2: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
167 return self.useTemplate( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
168 request, "static_blog_error", {"message": "You must indicate a nickname"} |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
169 ) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
170 |
827
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
171 prof_requested = _unquote(request.postpath[0]) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
172 |
728
9d35d75566fb
server_side (blog): clean error message when unknown profile is requested
souliane <souliane@mailoo.org>
parents:
727
diff
changeset
|
173 try: |
915
e9e9d9d893a8
server: renamed getProfileName to profileNameGet following core change and new conventions.
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
174 prof_found = self.host.bridge.profileNameGet(prof_requested) |
728
9d35d75566fb
server_side (blog): clean error message when unknown profile is requested
souliane <souliane@mailoo.org>
parents:
727
diff
changeset
|
175 except DBusException: |
9d35d75566fb
server_side (blog): clean error message when unknown profile is requested
souliane <souliane@mailoo.org>
parents:
727
diff
changeset
|
176 prof_found = None |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
177 if not prof_found or prof_found == C.SERVICE_PROFILE: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
178 return self.useTemplate( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
179 request, "static_blog_error", {"message": "Invalid nickname"} |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
180 ) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
181 |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
182 d = defer.Deferred() |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
183 # TODO: jid caching |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
184 self.host.bridge.asyncGetParamA( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
185 "JabberID", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
186 "Connection", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
187 "value", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
188 profile_key=prof_found, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
189 callback=d.callback, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
190 errback=d.errback, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
191 ) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
192 d.addCallback(self.render_gotJID, request, prof_found) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
193 return server.NOT_DONE_YET |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
194 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
195 def render_gotJID(self, pub_jid_s, request, profile): |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
196 pub_jid = JID(pub_jid_s) |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
197 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
198 request.extra_dict = {} # will be used for RSM and MAM |
708
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
199 self.parseURLParams(request) |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
200 if request.item_id: |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
201 # FIXME: this part seems useless |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
202 # we want a specific item |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
203 # item_ids = [request.item_id] |
825
a3e888ac4964
server (blog): removed another max_items
Goffi <goffi@goffi.org>
parents:
824
diff
changeset
|
204 # max_items = 1 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
205 max_items = C.NO_LIMIT # FIXME |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
206 else: |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
207 # max_items = int(request.extra_dict['rsm_max']) # FIXME |
954
7892f1a1e2cf
server (blog): temporary fix for atom feed:
Goffi <goffi@goffi.org>
parents:
950
diff
changeset
|
208 max_items = C.NO_LIMIT |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
209 # TODO: use max_items only when RSM is not available |
586
3eb3a2c0c011
browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
487
diff
changeset
|
210 |
708
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
211 if request.atom: |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
212 request.extra_dict.update(request.mam_extra) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
213 self.getAtom( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
214 pub_jid, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
215 max_items, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
216 request.extra_dict, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
217 request.extra_comments_dict, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
218 request, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
219 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
220 ) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
221 |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
222 elif request.item_id: |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
223 # we can't merge mam_extra now because we'll use item_ids |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
224 self.getItemById( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
225 pub_jid, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
226 request.item_id, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
227 request.extra_dict, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
228 request.extra_comments_dict, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
229 request, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
230 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
231 ) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
232 else: |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
233 request.extra_dict.update(request.mam_extra) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
234 self.getItems( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
235 pub_jid, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
236 max_items, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
237 request.extra_dict, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
238 request.extra_comments_dict, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
239 request, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
240 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
241 ) |
746
25984ca4aef2
server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents:
743
diff
changeset
|
242 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
243 ## URL parsing |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
244 |
708
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
245 def parseURLParams(self, request): |
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
246 """Parse the request URL parameters. |
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
247 |
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
248 @param request: HTTP request |
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
249 """ |
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
250 if len(request.postpath) > 1: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
251 if request.postpath[1] == "atom.xml": # return the atom feed |
708
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
252 request.atom = True |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
253 request.item_id = None |
708
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
254 else: |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
255 request.atom = False |
827
f1fc7245b910
server (blog): moved _quote and _unquote to module functions, and use them in BlogMessage.url
Goffi <goffi@goffi.org>
parents:
826
diff
changeset
|
256 request.item_id = _unquote(request.postpath[1]) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
257 else: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
258 request.item_id = None |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
259 request.atom = False |
708
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
260 |
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
261 self.parseURLParamsRSM(request) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
262 # XXX: request.display_single is True when only one blog post is visible |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
263 request.display_single = (request.item_id is not None) or int( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
264 request.extra_dict["rsm_max"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
265 ) == 1 |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
266 self.parseURLParamsCommentsRSM(request) |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
267 self.parseURLParamsMAM(request) |
708
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
268 |
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
269 def parseURLParamsRSM(self, request): |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
270 """Parse RSM request data from the URL parameters for main items |
708
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
271 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
272 fill request.extra_dict accordingly |
708
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
273 @param request: HTTP request |
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
274 """ |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
275 if request.item_id: # XXX: item_id and RSM are not compatible |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
276 return |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
277 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
278 rsm_max = int(request.args["max"][0]) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
279 if rsm_max > C.STATIC_RSM_MAX_LIMIT: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
280 log.warning(u"Request with rsm_max over limit ({})".format(rsm_max)) |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
281 rsm_max = C.STATIC_RSM_MAX_LIMIT |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
282 request.extra_dict["rsm_max"] = unicode(rsm_max) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
283 except (ValueError, KeyError): |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
284 request.extra_dict["rsm_max"] = unicode(C.STATIC_RSM_MAX_DEFAULT) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
285 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
286 request.extra_dict["rsm_index"] = request.args["index"][0] |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
287 except (ValueError, KeyError): |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
288 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
289 request.extra_dict["rsm_before"] = request.args["before"][0].decode( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
290 "utf-8" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
291 ) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
292 except KeyError: |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
293 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
294 request.extra_dict["rsm_after"] = request.args["after"][0].decode( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
295 "utf-8" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
296 ) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
297 except KeyError: |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
298 pass |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
299 |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
300 def parseURLParamsCommentsRSM(self, request): |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
301 """Parse RSM request data from the URL parameters for comments |
746
25984ca4aef2
server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents:
743
diff
changeset
|
302 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
303 fill request.extra_dict accordingly |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
304 @param request: HTTP request |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
305 """ |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
306 request.extra_comments_dict = {} |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
307 if request.display_single: |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
308 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
309 rsm_max = int(request.args["comments_max"][0]) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
310 if rsm_max > C.STATIC_RSM_MAX_LIMIT: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
311 log.warning(u"Request with rsm_max over limit ({})".format(rsm_max)) |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
312 rsm_max = C.STATIC_RSM_MAX_LIMIT |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
313 request.extra_comments_dict["rsm_max"] = unicode(rsm_max) |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
314 except (ValueError, KeyError): |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
315 request.extra_comments_dict["rsm_max"] = unicode( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
316 C.STATIC_RSM_MAX_COMMENTS_DEFAULT |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
317 ) |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
318 else: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
319 request.extra_comments_dict["rsm_max"] = "0" |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
320 |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
321 def parseURLParamsMAM(self, request): |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
322 """Parse MAM request data from the URL parameters for main items |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
323 |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
324 fill request.extra_dict accordingly |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
325 @param request: HTTP request |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
326 """ |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
327 # XXX: we use a separate dict for MAM as the filters are not used |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
328 # when display_single is set (because it then use item_ids which |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
329 # can't be used with MAM), but it is still used in this case |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
330 # for navigation links. |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
331 request.mam_extra = {} |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
332 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
333 request.mam_extra[ |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
334 "mam_filter_{}".format(C.MAM_FILTER_CATEGORY) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
335 ] = request.args["tag"][0].decode("utf-8") |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
336 except KeyError: |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
337 pass |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
338 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
339 ## Items retrieval |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
340 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
341 def getItemById( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
342 self, pub_jid, item_id, extra_dict, extra_comments_dict, request, profile |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
343 ): |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
344 """ |
746
25984ca4aef2
server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents:
743
diff
changeset
|
345 |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
346 @param pub_jid (jid.JID): publisher JID |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
347 @param item_id(unicode): ID of the item to retrieve |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
348 @param extra_dict (dict): extra configuration for initial items only |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
349 @param extra_comments_dict (dict): extra configuration for comments only |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
350 @param request: HTTP request |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
351 @param profile |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
352 """ |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
353 |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
354 def gotItems(items): |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
355 items, metadata = items |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
356 item = items[0] # assume there's only one item |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
357 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
358 def gotMetadata(result): |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
359 dummy, rsm_metadata = result |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
360 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
361 metadata["rsm_count"] = rsm_metadata["rsm_count"] |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
362 except KeyError: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
363 pass |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
364 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
365 metadata["rsm_index"] = unicode(int(rsm_metadata["rsm_index"]) - 1) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
366 except KeyError: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
367 pass |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
368 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
369 metadata["rsm_first"] = metadata["rsm_last"] = item["id"] |
746
25984ca4aef2
server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents:
743
diff
changeset
|
370 |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
371 def gotComments(comments): |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
372 # at this point we can merge mam dict |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
373 request.extra_dict.update(request.mam_extra) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
374 # build the items as self.getItems would do it (and as self.renderHTML expects them to be) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
375 comments = [ |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
376 ( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
377 item["comments_service"], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
378 item["comments_node"], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
379 "", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
380 comments[0], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
381 comments[1], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
382 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
383 ] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
384 self.renderHTML( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
385 [(item, comments)], metadata, request, pub_jid, profile |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
386 ) |
10 | 387 |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
388 # get the comments |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
389 # max_comments = int(extra_comments_dict['rsm_max']) # FIXME |
954
7892f1a1e2cf
server (blog): temporary fix for atom feed:
Goffi <goffi@goffi.org>
parents:
950
diff
changeset
|
390 max_comments = C.NO_LIMIT |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
391 # TODO: use max_comments only when RSM is not available |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
392 self.host.bridge.mbGet( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
393 item["comments_service"], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
394 item["comments_node"], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
395 max_comments, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
396 [], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
397 extra_comments_dict, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
398 C.SERVICE_PROFILE, |
826
70939916dc80
server (blog): added unhandler errback in getItemById
Goffi <goffi@goffi.org>
parents:
825
diff
changeset
|
399 callback=gotComments, |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
400 errback=lambda failure: self.renderError(failure, request, pub_jid), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
401 ) |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
402 |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
403 # XXX: retrieve RSM information related to the main item. We can't do it while |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
404 # retrieving the item, because item_ids and rsm should not be used together. |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
405 self.host.bridge.mbGet( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
406 pub_jid.userhost(), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
407 "", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
408 0, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
409 [], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
410 {"rsm_max": "1", "rsm_after": item["id"]}, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
411 C.SERVICE_PROFILE, |
826
70939916dc80
server (blog): added unhandler errback in getItemById
Goffi <goffi@goffi.org>
parents:
825
diff
changeset
|
412 callback=gotMetadata, |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
413 errback=lambda failure: self.renderError(failure, request, pub_jid), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
414 ) |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
415 |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
416 # get the main item |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
417 self.host.bridge.mbGet( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
418 pub_jid.userhost(), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
419 "", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
420 0, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
421 [item_id], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
422 extra_dict, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
423 C.SERVICE_PROFILE, |
826
70939916dc80
server (blog): added unhandler errback in getItemById
Goffi <goffi@goffi.org>
parents:
825
diff
changeset
|
424 callback=gotItems, |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
425 errback=lambda failure: self.renderError(failure, request, pub_jid), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
426 ) |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
427 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
428 def getItems( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
429 self, pub_jid, max_items, extra_dict, extra_comments_dict, request, profile |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
430 ): |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
431 """ |
746
25984ca4aef2
server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents:
743
diff
changeset
|
432 |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
433 @param pub_jid (jid.JID): publisher JID |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
434 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
435 @param extra_dict (dict): extra configuration for initial items only |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
436 @param extra_comments_dict (dict): extra configuration for comments only |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
437 @param request: HTTP request |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
438 @param profile |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
439 """ |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
440 |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
441 def getResultCb(data, rt_session): |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
442 remaining, results = data |
824
d990ae5612df
server (blog): better handling of mbGetFromManyWithCommentsRTResult in getItems
Goffi <goffi@goffi.org>
parents:
823
diff
changeset
|
443 # we have requested one node only |
d990ae5612df
server (blog): better handling of mbGetFromManyWithCommentsRTResult in getItems
Goffi <goffi@goffi.org>
parents:
823
diff
changeset
|
444 assert remaining == 0 |
d990ae5612df
server (blog): better handling of mbGetFromManyWithCommentsRTResult in getItems
Goffi <goffi@goffi.org>
parents:
823
diff
changeset
|
445 assert len(results) == 1 |
d990ae5612df
server (blog): better handling of mbGetFromManyWithCommentsRTResult in getItems
Goffi <goffi@goffi.org>
parents:
823
diff
changeset
|
446 service, node, failure, items, metadata = results[0] |
d990ae5612df
server (blog): better handling of mbGetFromManyWithCommentsRTResult in getItems
Goffi <goffi@goffi.org>
parents:
823
diff
changeset
|
447 if failure: |
d990ae5612df
server (blog): better handling of mbGetFromManyWithCommentsRTResult in getItems
Goffi <goffi@goffi.org>
parents:
823
diff
changeset
|
448 self.renderError(failure, request, pub_jid) |
d990ae5612df
server (blog): better handling of mbGetFromManyWithCommentsRTResult in getItems
Goffi <goffi@goffi.org>
parents:
823
diff
changeset
|
449 else: |
d990ae5612df
server (blog): better handling of mbGetFromManyWithCommentsRTResult in getItems
Goffi <goffi@goffi.org>
parents:
823
diff
changeset
|
450 self.renderHTML(items, metadata, request, pub_jid, profile) |
746
25984ca4aef2
server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents:
743
diff
changeset
|
451 |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
452 def getResult(rt_session): |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
453 self.host.bridge.mbGetFromManyWithCommentsRTResult( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
454 rt_session, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
455 C.SERVICE_PROFILE, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
456 callback=lambda data: getResultCb(data, rt_session), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
457 errback=lambda failure: self.renderError(failure, request, pub_jid), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
458 ) |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
459 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
460 # max_comments = int(extra_comments_dict['rsm_max']) # FIXME |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
461 max_comments = 0 |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
462 # TODO: use max_comments only when RSM is not available |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
463 self.host.bridge.mbGetFromManyWithComments( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
464 C.JID, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
465 [pub_jid.userhost()], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
466 max_items, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
467 max_comments, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
468 extra_dict, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
469 extra_comments_dict, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
470 C.SERVICE_PROFILE, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
471 callback=getResult, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
472 ) |
746
25984ca4aef2
server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents:
743
diff
changeset
|
473 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
474 def getAtom( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
475 self, pub_jid, max_items, extra_dict, extra_comments_dict, request, profile |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
476 ): |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
477 """ |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
478 |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
479 @param pub_jid (jid.JID): publisher JID |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
480 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
481 @param extra_dict (dict): extra configuration for initial items only |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
482 @param extra_comments_dict (dict): extra configuration for comments only |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
483 @param request: HTTP request |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
484 @param profile |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
485 """ |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
486 |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
487 def gotItems(data): |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
488 # Generate a clean atom feed with uri linking to this blog |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
489 # from microblog data |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
490 items, metadata = data |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
491 feed_elt = domish.Element((NS_ATOM, u"feed")) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
492 title = _(u"{user}'s blog").format(user=profile) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
493 feed_elt.addElement(u"title", content=title) |
884
763da94ba28b
blog (atom): base_url_ext can now only specify scheme, or netloc, or path, it will be used to complete data coming from request's path
Goffi <goffi@goffi.org>
parents:
882
diff
changeset
|
494 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
495 base_blog_url = self.host.getExtBaseURL( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
496 request, u"blog/{user}".format(user=profile) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
497 ) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
498 |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
499 # atom link |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
500 link_feed_elt = feed_elt.addElement("link") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
501 link_feed_elt["href"] = u"{base}/atom.xml".format(base=base_blog_url) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
502 link_feed_elt["type"] = u"application/atom+xml" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
503 link_feed_elt["rel"] = u"self" |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
504 |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
505 # blog link |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
506 link_blog_elt = feed_elt.addElement("link") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
507 link_blog_elt["rel"] = u"alternate" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
508 link_blog_elt["type"] = u"text/html" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
509 link_blog_elt["href"] = base_blog_url |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
510 |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
511 # blog link XMPP uri |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
512 blog_xmpp_uri = metadata["uri"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
513 link_blog_elt = feed_elt.addElement("link") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
514 link_blog_elt["rel"] = u"alternate" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
515 link_blog_elt["type"] = u"application/atom+xml" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
516 link_blog_elt["href"] = blog_xmpp_uri |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
517 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
518 feed_elt.addElement("id", content=_quote(blog_xmpp_uri)) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
519 updated_unix = max([float(item["updated"]) for item in items]) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
520 updated_dt = datetime.fromtimestamp(updated_unix) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
521 feed_elt.addElement( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
522 u"updated", content=u"{}Z".format(updated_dt.isoformat("T")) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
523 ) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
524 |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
525 for item in items: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
526 entry_elt = feed_elt.addElement(u"entry") |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
527 |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
528 # Title |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
529 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
530 title = item["title"] |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
531 except KeyError: |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
532 # for microblog (without title), we use an abstract of content as title |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
533 title = u"{}…".format(u" ".join(item["content"][:70].split())) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
534 entry_elt.addElement(u"title", content=title) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
535 |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
536 # HTTP link |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
537 http_link_elt = entry_elt.addElement(u"link") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
538 http_link_elt["rel"] = u"alternate" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
539 http_link_elt["type"] = u"text/html" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
540 http_link_elt["href"] = u"{base}/{quoted_id}".format( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
541 base=base_blog_url, quoted_id=_quote(item["id"]) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
542 ) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
543 # XMPP link |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
544 xmpp_link_elt = entry_elt.addElement(u"link") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
545 xmpp_link_elt["rel"] = u"alternate" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
546 xmpp_link_elt["type"] = u"application/atom+xml" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
547 xmpp_link_elt["href"] = u"{blog_uri};item={item_id}".format( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
548 blog_uri=blog_xmpp_uri, item_id=item["id"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
549 ) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
550 |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
551 # date metadata |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
552 entry_elt.addElement(u"id", content=item["atom_id"]) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
553 updated = datetime.fromtimestamp(float(item["updated"])) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
554 entry_elt.addElement( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
555 u"updated", content=u"{}Z".format(updated.isoformat("T")) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
556 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
557 published = datetime.fromtimestamp(float(item["published"])) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
558 entry_elt.addElement( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
559 u"published", content=u"{}Z".format(published.isoformat("T")) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
560 ) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
561 |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
562 # author metadata |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
563 author_elt = entry_elt.addElement(u"author") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
564 author_elt.addElement("name", content=item.get("author", profile)) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
565 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
566 author_elt.addElement( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
567 "uri", content=u"xmpp:{}".format(item["author_jid"]) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
568 ) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
569 except KeyError: |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
570 pass |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
571 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
572 author_elt.addElement("email", content=item["author_email"]) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
573 except KeyError: |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
574 pass |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
575 |
899
bc3a3e804a7a
blog(atom): added categories (tags) in Atom feed
Goffi <goffi@goffi.org>
parents:
898
diff
changeset
|
576 # categories |
bc3a3e804a7a
blog(atom): added categories (tags) in Atom feed
Goffi <goffi@goffi.org>
parents:
898
diff
changeset
|
577 for tag in data_format.dict2iter("tag", item): |
bc3a3e804a7a
blog(atom): added categories (tags) in Atom feed
Goffi <goffi@goffi.org>
parents:
898
diff
changeset
|
578 category_elt = entry_elt.addElement(u"category") |
bc3a3e804a7a
blog(atom): added categories (tags) in Atom feed
Goffi <goffi@goffi.org>
parents:
898
diff
changeset
|
579 category_elt["term"] = tag |
bc3a3e804a7a
blog(atom): added categories (tags) in Atom feed
Goffi <goffi@goffi.org>
parents:
898
diff
changeset
|
580 |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
581 # content |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
582 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
583 content_xhtml = item["content_xhtml"] |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
584 except KeyError: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
585 content_elt = entry_elt.addElement("content", content="content") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
586 content_elt["type"] = "text" |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
587 else: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
588 content_elt = entry_elt.addElement("content") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
589 content_elt["type"] = "xhtml" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
590 content_elt.addChild( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
591 xml_tools.ElementParser()(content_xhtml, namespace=C.NS_XHTML) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
592 ) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
593 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
594 atom_feed = u'<?xml version="1.0" encoding="utf-8"?>\n{}'.format( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
595 feed_elt.toXml() |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
596 ) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
597 self.renderAtomFeed(atom_feed, request), |
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
598 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
599 self.host.bridge.mbGet( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
600 pub_jid.userhost(), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
601 "", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
602 max_items, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
603 [], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
604 extra_dict, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
605 C.SERVICE_PROFILE, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
606 callback=gotItems, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
607 ) |
879
2e0e9cf9efb4
blog (atom feed): fixed atom handling:
Goffi <goffi@goffi.org>
parents:
855
diff
changeset
|
608 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
609 ## rendering |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
610 |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
611 def _updateDict(self, value, dict_, key): |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
612 dict_[key] = value |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
613 |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
614 def _getImageParams(self, options, key, default, alt): |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
615 """regexp from http://answers.oreilly.com/topic/280-how-to-validate-urls-with-regular-expressions/""" |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
616 url = options[key] if key in options else "" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
617 regexp = ( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
618 r"^(https?|ftp)://[a-z0-9-]+(\.[a-z0-9-]+)+(/[\w-]+)*/[\w-]+\.(gif|png|jpg)$" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
619 ) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
620 if re.match(regexp, url): |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
621 url = url |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
622 else: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
623 url = default |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
624 return BlogImage(url, alt) |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
625 |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
626 def renderError(self, failure, request, pub_jid): |
891
14e611e38b67
server (blog): set HTTP status code to 500 on renderError
Goffi <goffi@goffi.org>
parents:
890
diff
changeset
|
627 request.setResponseCode(500) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
628 request.write( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
629 self.useTemplate( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
630 request, "static_blog_error", {"message": "Can't access requested data"} |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
631 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
632 ) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
633 request.finish() |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
634 |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
635 def renderHTML(self, items, metadata, request, pub_jid, profile): |
441
63017904c4d4
server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents:
436
diff
changeset
|
636 """Retrieve the user parameters before actually rendering the static blog |
586
3eb3a2c0c011
browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
487
diff
changeset
|
637 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
638 @param items(list[tuple(dict, list)]): same as in self._renderHTML |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
639 @param metadata(dict): original node metadata |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
640 @param request: HTTP request |
727
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
641 @param pub_jid (JID): publisher JID |
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
642 @param profile (unicode): %(doc_profile)s |
389
2d782349b88a
server_side: display blog comments when you click on a main item header or title
souliane <souliane@mailoo.org>
parents:
388
diff
changeset
|
643 """ |
441
63017904c4d4
server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents:
436
diff
changeset
|
644 d_list = [] |
483
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
645 options = {} |
441
63017904c4d4
server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents:
436
diff
changeset
|
646 |
950
67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
647 d = self.getAvatarURL(pub_jid, request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
648 d.addCallback(self._updateDict, options, "avatar") |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
649 d.addErrback(self.renderError, request, pub_jid) |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
650 d_list.append(d) |
441
63017904c4d4
server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents:
436
diff
changeset
|
651 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
652 for param_name in PARAMS_TO_GET: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
653 d = defer.Deferred() |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
654 self.host.bridge.asyncGetParamA( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
655 param_name, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
656 C.STATIC_BLOG_KEY, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
657 "value", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
658 C.SERVER_SECURITY_LIMIT, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
659 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
660 callback=d.callback, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
661 errback=d.errback, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
662 ) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
663 d.addCallback(self._updateDict, options, param_name) |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
664 d.addErrback(self.renderError, request, pub_jid) |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
665 d_list.append(d) |
441
63017904c4d4
server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents:
436
diff
changeset
|
666 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
667 dlist_d = defer.DeferredList(d_list) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
668 dlist_d.addCallback( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
669 lambda dummy: self._renderHTML(items, metadata, options, request, pub_jid) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
670 ) |
388
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
671 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
672 def _renderHTML(self, items, metadata, options, request, pub_jid): |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
673 """Actually render the static blog. |
746
25984ca4aef2
server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents:
743
diff
changeset
|
674 |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
675 If mblog_data is a list of dict, we are missing the comments items so we just |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
676 display the main items. If mblog_data is a list of couple, each couple is |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
677 associating a main item data with the list of its comments, so we render all. |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
678 @param items(list[tuple(dict, list)]): list of 2-tuple with |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
679 - item(dict): item microblog data |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
680 - comments_list(list[tuple]): list of 5-tuple with |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
681 - service (unicode): pubsub service where the comments node is |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
682 - node (unicode): comments node |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
683 - failure (unicode): empty in case of success, else error message |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
684 - comments(list[dict]): list of microblog data |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
685 - comments_metadata(dict): metadata of the comment node |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
686 @param metadata(dict): original node metadata |
483
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
687 @param options: dict defining the blog's parameters |
388
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
688 @param request: the HTTP request |
727
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
689 @param pub_jid (JID): publisher JID |
388
893451e35686
server_side: display blog banner if it is defined
souliane <souliane@mailoo.org>
parents:
375
diff
changeset
|
690 """ |
483
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
691 if not isinstance(options, dict): |
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
692 options = {} |
727
3bd097380da7
server side (blog): fixes displaying the avatar
souliane <souliane@mailoo.org>
parents:
726
diff
changeset
|
693 user = sanitizeHtml(pub_jid.user) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
694 base_url = os.path.join("/blog/", user) |
441
63017904c4d4
server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents:
436
diff
changeset
|
695 |
483
0bbbef1d53a8
server side (blog): use user's avatar a the blog's favicon + small refactorization
souliane <souliane@mailoo.org>
parents:
481
diff
changeset
|
696 def getOption(key): |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
697 return sanitizeHtml(options[key]) if key in options else "" |
441
63017904c4d4
server_side: static blog retrieve page's title, meta description and keywords from the parameters
souliane <souliane@mailoo.org>
parents:
436
diff
changeset
|
698 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
699 avatar = os.path.normpath("/{}".format(getOption("avatar"))) |
702
d94feb0d849e
server_side: give a better look to the static blog
souliane <souliane@mailoo.org>
parents:
694
diff
changeset
|
700 title = getOption(C.STATIC_BLOG_PARAM_TITLE) or user |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
701 query_data = _urlencode(getDefaultQueryData(request)).decode("utf-8") |
880
ccbad50e1426
blog, themes(default): added <link> element referencing xmpp: uri of the item
Goffi <goffi@goffi.org>
parents:
879
diff
changeset
|
702 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
703 xmpp_uri = metadata["uri"] |
880
ccbad50e1426
blog, themes(default): added <link> element referencing xmpp: uri of the item
Goffi <goffi@goffi.org>
parents:
879
diff
changeset
|
704 if len(items) == 1: |
ccbad50e1426
blog, themes(default): added <link> element referencing xmpp: uri of the item
Goffi <goffi@goffi.org>
parents:
879
diff
changeset
|
705 # FIXME: that's really not a good way to get item id |
ccbad50e1426
blog, themes(default): added <link> element referencing xmpp: uri of the item
Goffi <goffi@goffi.org>
parents:
879
diff
changeset
|
706 # this must be changed after static blog refactorisation |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
707 item_id = items[0][0]["id"] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
708 xmpp_uri += u";item={}".format(_quote(item_id)) |
880
ccbad50e1426
blog, themes(default): added <link> element referencing xmpp: uri of the item
Goffi <goffi@goffi.org>
parents:
879
diff
changeset
|
709 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
710 data = { |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
711 "url_base": base_url, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
712 "xmpp_uri": xmpp_uri, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
713 "url_query": u"?{}".format(query_data) if query_data else "", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
714 "keywords": getOption(C.STATIC_BLOG_PARAM_KEYWORDS), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
715 "description": getOption(C.STATIC_BLOG_PARAM_DESCRIPTION), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
716 "title": title, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
717 "favicon": avatar, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
718 "banner_img": self._getImageParams( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
719 options, C.STATIC_BLOG_PARAM_BANNER, avatar, title |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
720 ), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
721 } |
586
3eb3a2c0c011
browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
487
diff
changeset
|
722 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
723 data["navlinks"] = NavigationLinks(request, items, metadata, base_url) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
724 data["messages"] = [] |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
725 for item in items: |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
726 item, comments_list = item |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
727 comments, comments_count = [], 0 |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
728 for node_comments in comments_list: |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
729 comments.extend(node_comments[3]) |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
730 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
731 comments_count += int(node_comments[4]["rsm_count"]) |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
732 except KeyError: |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
733 pass |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
734 data["messages"].append( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
735 BlogMessage(request, base_url, item, comments, comments_count) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
736 ) |
586
3eb3a2c0c011
browser and server side: uses RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents:
487
diff
changeset
|
737 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
738 request.write(self.useTemplate(request, "static_blog", data)) |
10 | 739 request.finish() |
243
63e9b680d3e7
browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
229
diff
changeset
|
740 |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
741 def renderAtomFeed(self, feed, request): |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
742 request.write(feed.encode("utf-8")) |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
743 request.finish() |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
744 |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
745 |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
746 class NavigationLinks(object): |
880
ccbad50e1426
blog, themes(default): added <link> element referencing xmpp: uri of the item
Goffi <goffi@goffi.org>
parents:
879
diff
changeset
|
747 def __init__(self, request, items, metadata, base_url): |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
748 """Build the navigation links. |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
749 |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
750 @param items (list): list of items |
880
ccbad50e1426
blog, themes(default): added <link> element referencing xmpp: uri of the item
Goffi <goffi@goffi.org>
parents:
879
diff
changeset
|
751 @param metadata (dict): rsm data |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
752 @param base_url (unicode): the base URL for this user's blog |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
753 @return: dict |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
754 """ |
880
ccbad50e1426
blog, themes(default): added <link> element referencing xmpp: uri of the item
Goffi <goffi@goffi.org>
parents:
879
diff
changeset
|
755 # FIXME: this code must be refactorized, it is fragile |
ccbad50e1426
blog, themes(default): added <link> element referencing xmpp: uri of the item
Goffi <goffi@goffi.org>
parents:
879
diff
changeset
|
756 # and difficult to maintain |
ccbad50e1426
blog, themes(default): added <link> element referencing xmpp: uri of the item
Goffi <goffi@goffi.org>
parents:
879
diff
changeset
|
757 |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
758 # query data which must be present in all links |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
759 default_query_data = getDefaultQueryData(request) |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
760 |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
761 # which links we need to display |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
762 if request.display_single: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
763 links = ("later_message", "older_message") |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
764 # key must exist when using the template |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
765 self.later_messages = self.older_messages = "" |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
766 else: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
767 links = ("later_messages", "older_messages") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
768 self.later_message = self.older_message = "" |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
769 |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
770 # now we set the links according to RSM |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
771 for key in links: |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
772 query_data = default_query_data.copy() |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
773 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
774 if key.startswith("later_message"): |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
775 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
776 index = int(metadata["rsm_index"]) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
777 except (KeyError, ValueError): |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
778 pass |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
779 else: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
780 if index == 0: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
781 # we don't show this link on first page |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
782 setattr(self, key, "") |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
783 continue |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
784 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
785 query_data["before"] = metadata["rsm_first"].encode("utf-8") |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
786 except KeyError: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
787 pass |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
788 else: |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
789 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
790 index = int(metadata["rsm_index"]) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
791 count = int(metadata.get("rsm_count")) |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
792 except (KeyError, ValueError): |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
793 # XXX: if we don't have index or count, we can't know if we |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
794 # are on the last page or not |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
795 pass |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
796 else: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
797 # if we have index, we don't show the after link |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
798 # on the last page |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
799 if index + len(items) >= count: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
800 setattr(self, key, "") |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
801 continue |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
802 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
803 query_data["after"] = metadata["rsm_last"].encode("utf-8") |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
804 except KeyError: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
805 pass |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
806 |
708
e9a6cbb924e6
server_side: fixes static blog navigation links
souliane <souliane@mailoo.org>
parents:
705
diff
changeset
|
807 if request.display_single: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
808 query_data["max"] = 1 |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
809 |
893
298fbe562060
blog: escape "&" when encoding URL, so they can be used without escaping in the HTML template
Goffi <goffi@goffi.org>
parents:
892
diff
changeset
|
810 link = "{}?{}".format(base_url, _urlencode(query_data)) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
811 setattr(self, key, BlogLink(link, key, key.replace("_", " "))) |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
812 |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
813 |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
814 class BlogImage(object): |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
815 def __init__(self, url_, alt): |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
816 self.url = url_ |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
817 self.alt = alt |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
818 |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
819 |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
820 class BlogLink(object): |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
821 def __init__(self, url_, style, text): |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
822 self.url = url_ |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
823 self.style = style |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
824 self.text = text |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
825 |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
826 |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
827 class BlogMessage(object): |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
828 def __init__(self, request, base_url, entry, comments=None, comments_count=0): |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
829 """ |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
830 |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
831 @param request: HTTP request |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
832 @param base_url (unicode): the base URL |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
833 @param entry(dict): item microblog data |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
834 @param comments(list[dict]): list of microblog data |
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
835 @param comments_count (int): total number of comments |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
836 """ |
854 | 837 if comments is None: |
838 comments = [] | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
839 timestamp = float(entry.get("published", 0)) |
746
25984ca4aef2
server side: special handling of Connection/JabberID and Connection/autoconnect parameter which has needed by QuickApp but restricted by security limit
Goffi <goffi@goffi.org>
parents:
743
diff
changeset
|
840 |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
841 # FIXME: for now we assume that the comments' depth is only 1 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
842 is_comment = not entry.get("comments", False) |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
843 |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
844 self.date = datetime.fromtimestamp(timestamp) |
725
c1abaa91a121
server (blog): update to the new mechanism in XEP-0277 + improvement:
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
845 self.type = "comment" if is_comment else "main_item" |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
846 self.style = "mblog_comment" if is_comment else "" |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
847 self.content = self.getText(entry, "content") |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
848 |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
849 if is_comment: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
850 self.author = _(u"from {}").format(entry["author"]) |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
851 else: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
852 self.author = " " |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
853 self.url = "{}/{}".format(base_url, _quote(entry["id"])) |
828
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
854 query_data = getDefaultQueryData(request) |
0c824ebe9d87
server (blog): implemented tag/category filtering:
Goffi <goffi@goffi.org>
parents:
827
diff
changeset
|
855 if query_data: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
856 self.url += "?{}".format(_urlencode(query_data)) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
857 self.title = self.getText(entry, "title") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
858 self.tags = [sanitizeHtml(tag) for tag in data_format.dict2iter("tag", entry)] |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
859 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
860 count_text = lambda count: D_(u"comments") if count > 1 else D_(u"comment") |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
861 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
862 self.comments_text = u"{} {}".format( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
863 comments_count, count_text(comments_count) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
864 ) |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
865 |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
866 delta = comments_count - len(comments) |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
867 if request.display_single and delta > 0: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
868 prev_url = "{}?{}".format( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
869 self.url, _urlencode({"comments_max": comments_count}) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
870 ) |
854 | 871 prev_text = D_(u"show {count} previous {comments}").format( |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
872 count=delta, comments=count_text(delta) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
873 ) |
712
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
874 self.all_comments_link = BlogLink(prev_url, "comments_link", prev_text) |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
875 |
bf562fb9c273
server_side: use Jinja2 template engine for static blog
souliane <souliane@mailoo.org>
parents:
708
diff
changeset
|
876 if comments: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
877 self.comments = [ |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
878 BlogMessage(request, base_url, comment) for comment in comments |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
879 ] |
704
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
880 |
5319110a862c
server_side: static blog uses the default template
souliane <souliane@mailoo.org>
parents:
702
diff
changeset
|
881 def getText(self, entry, key): |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
882 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
883 xhtml = entry["{}_xhtml".format(key)] |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
884 except KeyError: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
885 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1054
diff
changeset
|
886 processor = addURLToText if key.startswith("content") else sanitizeHtml |
823
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
887 return convertNewLinesToXHTML(processor(entry[key])) |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
888 except KeyError: |
027139763511
server (blog): cleaning & improvments:
Goffi <goffi@goffi.org>
parents:
818
diff
changeset
|
889 return None |
854 | 890 else: |
891 # FIXME: empty <div /> elements provoke rendering issue | |
892 # this regex is a temporary workadound, need more investigation | |
893 xhtml = re_strip_empty_div.sub("", xhtml) | |
894 return fixXHTMLLinks(xhtml) |