annotate libervia/pages/blog/view/atom.xml/page_meta.py @ 1406:cffa3ae4d0aa

pages (blog/view): move URL friendly code to backend tools: - the code to render an URL friendly is now in `sat.tools.common.regex` - user friendly extra text is now only displayed when no `-` is found in ID. This is a temporary transition behaviour because new blog items IDs are now user friendly by default, and thus extra text is not wanted anymore. For older IDs it is still needed though, and the presence of `-` is used to guess when an ID is user friendly or not.
author Goffi <goffi@goffi.org>
date Fri, 16 Apr 2021 18:44:49 +0200
parents 089742e065e3
children 106bae41f5c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
1 #!/usr/bin/env python3
1239
f511f8fbbf8a fixed shebangs
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
2
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from libervia.server.constants import Const as C
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from sat.tools.common import uri
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 import time
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
7 name = "blog_feed_atom"
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 access = C.PAGES_ACCESS_PUBLIC
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
9 template = "blog/atom.xml"
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
1323
a20fe9eb307b pages (blog/view/atom.xml): fixed items management after blog_view changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
12 async def prepare_render(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
13 request.setHeader("Content-Type", "application/atom+xml; charset=utf-8")
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 data = self.getRData(request)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
15 service, node = data["service"], data.get("node")
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
16 self.checkCache(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
17 request, C.CACHE_PUBSUB, service=service, node=node, short="microblog"
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
18 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
19 data["show_comments"] = False
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 template_data = request.template_data
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
21 blog_page = self.getPageByName("blog_view")
1323
a20fe9eb307b pages (blog/view/atom.xml): fixed items management after blog_view changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
22 await blog_page.prepare_render(self, request)
a20fe9eb307b pages (blog/view/atom.xml): fixed items management after blog_view changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
23 items = data["blog_items"]['items']
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
24
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
25 template_data["request_uri"] = self.host.getExtBaseURL(
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
26 request, request.path.decode("utf-8")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
27 )
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
28 template_data["xmpp_uri"] = uri.buildXMPPUri(
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
29 "pubsub", subtype="microblog", path=service.full(), node=node
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
30 )
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
31 blog_view = self.getPageByName("blog_view")
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
32 template_data["http_uri"] = self.host.getExtBaseURL(
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
33 request, blog_view.getURL(service.full(), node)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
34 )
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 if items:
1323
a20fe9eb307b pages (blog/view/atom.xml): fixed items management after blog_view changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
36 template_data["updated"] = items[0]['updated']
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 else:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
38 template_data["updated"] = time.time()