Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_misc_static_blog.py @ 4226:3f7ca590a5da
cli (pubsub): use `PEP` when service is not specified in error message.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 05 Mar 2024 17:31:56 +0100 |
parents | 4b842c1fb686 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 |
1020
adbde4a3a52f
plugin misc_static_blog: renamed from tmp_blog_banner, now also with page's title, meta keywords and description
souliane <souliane@mailoo.org>
parents:
890
diff
changeset
|
4 # SAT plugin for static blogs |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
5 # Copyright (C) 2014 Adrien Cossa (souliane@mailoo.org) |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
20 from libervia.backend.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
21 |
1102
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
22 log = getLogger(__name__) |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
24 from libervia.backend.core.i18n import _, D_ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
25 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
26 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
27 from libervia.backend.tools import xml_tools |
1102
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
28 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
29 from twisted.internet import defer |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
30 from twisted.words.protocols.jabber import jid |
1020
adbde4a3a52f
plugin misc_static_blog: renamed from tmp_blog_banner, now also with page's title, meta keywords and description
souliane <souliane@mailoo.org>
parents:
890
diff
changeset
|
31 |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
34 C.PI_NAME: "Static Blog Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
35 C.PI_IMPORT_NAME: "STATIC-BLOG", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
36 C.PI_TYPE: "MISC", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
37 C.PI_PROTOCOLS: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
38 C.PI_DEPENDENCIES: [], |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 C.PI_RECOMMENDATIONS: [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
40 "MISC-ACCOUNT" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
41 ], # TODO: remove when all blogs can be retrieved |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
42 C.PI_MAIN: "StaticBlog", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
43 C.PI_HANDLER: "no", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
44 C.PI_DESCRIPTION: _("""Plugin for static blogs"""), |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
45 } |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 |
1020
adbde4a3a52f
plugin misc_static_blog: renamed from tmp_blog_banner, now also with page's title, meta keywords and description
souliane <souliane@mailoo.org>
parents:
890
diff
changeset
|
48 class StaticBlog(object): |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 |
3028 | 50 params = """ |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
51 <params> |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 <individual> |
2479
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
53 <category name="{category_name}" label="{category_label}"> |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
54 <param name="{title_name}" label="{title_label}" value="" type="string" security="0"/> |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
55 <param name="{banner_name}" label="{banner_label}" value="" type="string" security="0"/> |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
56 <param name="{background_name}" label="{background_label}" value ="" type="string" security="0"/> |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
57 <param name="{keywords_name}" label="{keywords_label}" value="" type="string" security="0"/> |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
58 <param name="{description_name}" label="{description_label}" value="" type="string" security="0"/> |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 </category> |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 </individual> |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
61 </params> |
2479
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
62 """.format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 category_name=C.STATIC_BLOG_KEY, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 category_label=D_(C.STATIC_BLOG_KEY), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 title_name=C.STATIC_BLOG_PARAM_TITLE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 title_label=D_("Page title"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 banner_name=C.STATIC_BLOG_PARAM_BANNER, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 banner_label=D_("Banner URL"), |
3028 | 69 background_name="Background", |
70 background_label=D_("Background image URL"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 keywords_name=C.STATIC_BLOG_PARAM_KEYWORDS, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 keywords_label=D_("Keywords"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 description_name=C.STATIC_BLOG_PARAM_DESCRIPTION, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 description_label=D_("Description"), |
2479
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
75 ) |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
76 |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 def __init__(self, host): |
1102
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
78 try: # TODO: remove this attribute when all blogs can be retrieved |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
79 self.domain = host.plugins["MISC-ACCOUNT"].account_domain_new_get() |
1102
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
80 except KeyError: |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
81 self.domain = None |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
82 host.memory.update_params(self.params) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
83 # host.import_menu((D_("User"), D_("Public blog")), self._display_public_blog, security_limit=1, help_string=D_("Display public blog page"), type_=C.MENU_JID_CONTEXT) |
1102
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
84 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
85 def _display_public_blog(self, menu_data, profile): |
1102
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
86 """Check if the blog can be displayed and answer the frontend. |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
87 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
88 @param menu_data: %(menu_data)s |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
89 @param profile: %(doc_profile)s |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
90 @return: dict |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
91 """ |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1102
diff
changeset
|
92 # FIXME: "public_blog" key has been removed |
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1102
diff
changeset
|
93 # TODO: replace this with a more generic widget call with URIs |
1102
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
94 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 user_jid = jid.JID(menu_data["jid"]) |
1102
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
96 except KeyError: |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
97 log.error(_("jid key is not present !")) |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
98 return defer.fail(exceptions.DataError) |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
99 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
100 # TODO: remove this check when all blogs can be retrieved |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
101 if self.domain and user_jid.host != self.domain: |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
102 info_ui = xml_tools.XMLUI("popup", title=D_("Not available")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 info_ui.addText( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 D_("Retrieving a blog from an external domain is not implemented yet.") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 return {"xmlui": info_ui.toXml()} |
1102
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
107 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
108 return {"public_blog": user_jid.userhost()} |