Mercurial > libervia-backend
annotate src/plugins/plugin_misc_static_blog.py @ 2354:5129a0506739
jp (shell): fixed use of profile + added EOF handling:
- main profile (i.e. the one specified on command line when invocating "jp shell") was not used. It is now added to arguments if the value is not overriden on command line or in use
- EOF (i.e. when user press C-d) is now understood as "quit" command
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 08 Sep 2017 07:58:10 +0200 |
parents | 33c8c4973743 |
children | 0d6c53e6c591 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1715
diff
changeset
|
1 #!/usr/bin/env python2 |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
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 |
1102
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
20 from sat.core.log import getLogger |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
21 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
|
22 |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 from sat.core.i18n import _, D_ |
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
|
24 from sat.core.constants import Const as C |
1102
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
25 from sat.core import exceptions |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
26 from sat.tools import xml_tools |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
27 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
28 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
|
29 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
|
30 |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
33 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
|
34 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
|
35 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
|
36 C.PI_PROTOCOLS: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
37 C.PI_DEPENDENCIES: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
38 C.PI_RECOMMENDATIONS: ['MISC-ACCOUNT'], # TODO: remove when all blogs can be retrieved |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
39 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
|
40 C.PI_HANDLER: "no", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
41 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
|
42 } |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 |
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
|
45 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
|
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 params = """ |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 <params> |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 <individual> |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
50 <category name="%(category_name)s" label="%(category_label)s"> |
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
|
51 <param name="%(title_name)s" label="%(title_label)s" value="" type="string" security="0"/> |
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
|
52 <param name="%(banner_name)s" label="%(banner_label)s" value="" type="string" security="0"/> |
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
|
53 <param name="%(keywords_name)s" label="%(keywords_label)s" value="" type="string" security="0"/> |
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
|
54 <param name="%(description_name)s" label="%(description_label)s" 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
|
55 </category> |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 </individual> |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 </params> |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 """ % { |
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
|
59 'category_name': C.STATIC_BLOG_KEY, |
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
|
60 'category_label': D_(C.STATIC_BLOG_KEY), |
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
|
61 'title_name': C.STATIC_BLOG_PARAM_TITLE, |
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
|
62 'title_label': D_('Page title'), |
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
|
63 'banner_name': C.STATIC_BLOG_PARAM_BANNER, |
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
|
64 'banner_label': D_('Banner URL'), |
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
|
65 'keywords_name': C.STATIC_BLOG_PARAM_KEYWORDS, |
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
|
66 'keywords_label': D_('Keywords'), |
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
|
67 'description_name': C.STATIC_BLOG_PARAM_DESCRIPTION, |
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
|
68 'description_label': D_('Description'), |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 } |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
70 |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 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
|
72 try: # TODO: remove this attribute 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
|
73 self.domain = host.plugins['MISC-ACCOUNT'].getNewAccountDomain() |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
74 except KeyError: |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
75 self.domain = None |
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 host.memory.updateParams(self.params) |
1715
b505b01195f0
plugin static blog: temporarily deactivated public blog menu
Goffi <goffi@goffi.org>
parents:
1468
diff
changeset
|
77 # host.importMenu((D_("User"), D_("Public blog")), self._displayPublicBlog, 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
|
78 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
79 def _displayPublicBlog(self, menu_data, profile): |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
80 """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
|
81 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
82 @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
|
83 @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
|
84 @return: dict |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
85 """ |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1102
diff
changeset
|
86 # FIXME: "public_blog" key has been removed |
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1102
diff
changeset
|
87 # 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
|
88 try: |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
89 user_jid = jid.JID(menu_data['jid']) |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
90 except KeyError: |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
91 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
|
92 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
|
93 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
94 # 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
|
95 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
|
96 info_ui = xml_tools.XMLUI("popup", title=D_("Not available")) |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
97 info_ui.addText(D_("Retrieving a blog from an external domain is not implemented yet.")) |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
98 return {'xmlui': info_ui.toXml()} |
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 return {"public_blog": user_jid.userhost()} |