Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_static_blog.py @ 2562:26edcf3a30eb
core, setup: huge cleaning:
- moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention
- move twisted directory to root
- removed all hacks from setup.py, and added missing dependencies, it is now clean
- use https URL for website in setup.py
- removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed
- renamed sat.sh to sat and fixed its installation
- added python_requires to specify Python version needed
- replaced glib2reactor which use deprecated code by gtk3reactor
sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Apr 2018 19:44:50 +0200 |
parents | src/plugins/plugin_misc_static_blog.py@0d6c53e6c591 |
children | 56f94936df1e |
comparison
equal
deleted
inserted
replaced
2561:bd30dc3ffe5a | 2562:26edcf3a30eb |
---|---|
1 #!/usr/bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SAT plugin for static blogs | |
5 # Copyright (C) 2014 Adrien Cossa (souliane@mailoo.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 from sat.core.log import getLogger | |
21 log = getLogger(__name__) | |
22 | |
23 from sat.core.i18n import _, D_ | |
24 from sat.core.constants import Const as C | |
25 from sat.core import exceptions | |
26 from sat.tools import xml_tools | |
27 | |
28 from twisted.internet import defer | |
29 from twisted.words.protocols.jabber import jid | |
30 | |
31 | |
32 PLUGIN_INFO = { | |
33 C.PI_NAME: "Static Blog Plugin", | |
34 C.PI_IMPORT_NAME: "STATIC-BLOG", | |
35 C.PI_TYPE: "MISC", | |
36 C.PI_PROTOCOLS: [], | |
37 C.PI_DEPENDENCIES: [], | |
38 C.PI_RECOMMENDATIONS: ['MISC-ACCOUNT'], # TODO: remove when all blogs can be retrieved | |
39 C.PI_MAIN: "StaticBlog", | |
40 C.PI_HANDLER: "no", | |
41 C.PI_DESCRIPTION: _("""Plugin for static blogs""") | |
42 } | |
43 | |
44 | |
45 class StaticBlog(object): | |
46 | |
47 params = u""" | |
48 <params> | |
49 <individual> | |
50 <category name="{category_name}" label="{category_label}"> | |
51 <param name="{title_name}" label="{title_label}" value="" type="string" security="0"/> | |
52 <param name="{banner_name}" label="{banner_label}" value="" type="string" security="0"/> | |
53 <param name="{background_name}" label="{background_label}" value ="" type="string" security="0"/> | |
54 <param name="{keywords_name}" label="{keywords_label}" value="" type="string" security="0"/> | |
55 <param name="{description_name}" label="{description_label}" value="" type="string" security="0"/> | |
56 </category> | |
57 </individual> | |
58 </params> | |
59 """.format( | |
60 category_name = C.STATIC_BLOG_KEY, | |
61 category_label = D_(C.STATIC_BLOG_KEY), | |
62 title_name = C.STATIC_BLOG_PARAM_TITLE, | |
63 title_label = D_('Page title'), | |
64 banner_name = C.STATIC_BLOG_PARAM_BANNER, | |
65 banner_label = D_('Banner URL'), | |
66 background_name = u"Background", | |
67 background_label = D_(u"Background image URL"), | |
68 keywords_name = C.STATIC_BLOG_PARAM_KEYWORDS, | |
69 keywords_label = D_('Keywords'), | |
70 description_name = C.STATIC_BLOG_PARAM_DESCRIPTION, | |
71 description_label = D_('Description'), | |
72 ) | |
73 | |
74 def __init__(self, host): | |
75 try: # TODO: remove this attribute when all blogs can be retrieved | |
76 self.domain = host.plugins['MISC-ACCOUNT'].getNewAccountDomain() | |
77 except KeyError: | |
78 self.domain = None | |
79 host.memory.updateParams(self.params) | |
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) | |
81 | |
82 def _displayPublicBlog(self, menu_data, profile): | |
83 """Check if the blog can be displayed and answer the frontend. | |
84 | |
85 @param menu_data: %(menu_data)s | |
86 @param profile: %(doc_profile)s | |
87 @return: dict | |
88 """ | |
89 # FIXME: "public_blog" key has been removed | |
90 # TODO: replace this with a more generic widget call with URIs | |
91 try: | |
92 user_jid = jid.JID(menu_data['jid']) | |
93 except KeyError: | |
94 log.error(_("jid key is not present !")) | |
95 return defer.fail(exceptions.DataError) | |
96 | |
97 # TODO: remove this check when all blogs can be retrieved | |
98 if self.domain and user_jid.host != self.domain: | |
99 info_ui = xml_tools.XMLUI("popup", title=D_("Not available")) | |
100 info_ui.addText(D_("Retrieving a blog from an external domain is not implemented yet.")) | |
101 return {'xmlui': info_ui.toXml()} | |
102 | |
103 return {"public_blog": user_jid.userhost()} |