Mercurial > libervia-backend
annotate sat/plugins/plugin_misc_static_blog.py @ 2605:87f8cf51fca5
jp (info/session): show short + relative date by default for "started"
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 01 Jun 2018 18:27:49 +0200 |
parents | 26edcf3a30eb |
children | 56f94936df1e |
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 |
2479
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
47 params = u""" |
890
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> |
2479
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
50 <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
|
51 <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
|
52 <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
|
53 <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
|
54 <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
|
55 <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
|
56 </category> |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 </individual> |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 </params> |
2479
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
59 """.format( |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
60 category_name = C.STATIC_BLOG_KEY, |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
61 category_label = D_(C.STATIC_BLOG_KEY), |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
62 title_name = C.STATIC_BLOG_PARAM_TITLE, |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
63 title_label = D_('Page title'), |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
64 banner_name = C.STATIC_BLOG_PARAM_BANNER, |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
65 banner_label = D_('Banner URL'), |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
66 background_name = u"Background", |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
67 background_label = D_(u"Background image URL"), |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
68 keywords_name = C.STATIC_BLOG_PARAM_KEYWORDS, |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
69 keywords_label = D_('Keywords'), |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
70 description_name = C.STATIC_BLOG_PARAM_DESCRIPTION, |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
71 description_label = D_('Description'), |
0d6c53e6c591
plugin blog static: added background parameter, to set an image
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
72 ) |
890
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 |
10bb8574ab11
plugin blog_banner: added temporary plugin with a user parameter to set a blog banner
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 except KeyError: |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
78 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
|
79 host.memory.updateParams(self.params) |
1715
b505b01195f0
plugin static blog: temporarily deactivated public blog menu
Goffi <goffi@goffi.org>
parents:
1468
diff
changeset
|
80 # 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
|
81 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
82 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
|
83 """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
|
84 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
85 @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
|
86 @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
|
87 @return: dict |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
88 """ |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1102
diff
changeset
|
89 # FIXME: "public_blog" key has been removed |
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1102
diff
changeset
|
90 # 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
|
91 try: |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
92 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
|
93 except KeyError: |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
94 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
|
95 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
|
96 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
97 # 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 |
4c48e2549592
plugin misc_static_blog: add a menu for displaying a user static blog
souliane <souliane@mailoo.org>
parents:
1020
diff
changeset
|
103 return {"public_blog": user_jid.userhost()} |