comparison src/plugins/plugin_misc_static_blog.py @ 1102:4c48e2549592

plugin misc_static_blog: add a menu for displaying a user static blog
author souliane <souliane@mailoo.org>
date Tue, 15 Jul 2014 18:28:40 +0200
parents adbde4a3a52f
children 731fbed0b9cf
comparison
equal deleted inserted replaced
1101:ad4ec8d9235e 1102:4c48e2549592
15 # GNU Affero General Public License for more details. 15 # GNU Affero General Public License for more details.
16 16
17 # You should have received a copy of the GNU Affero General Public License 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/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.log import getLogger
21 log = getLogger(__name__)
20 22
21 from sat.core.i18n import _, D_ 23 from sat.core.i18n import _, D_
22 from sat.core.constants import Const as C 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
23 30
24 31
25 PLUGIN_INFO = { 32 PLUGIN_INFO = {
26 "name": "Static Blog Plugin", 33 "name": "Static Blog Plugin",
27 "import_name": "STATIC-BLOG", 34 "import_name": "STATIC-BLOG",
28 "type": "MISC", 35 "type": "MISC",
29 "protocols": [], 36 "protocols": [],
30 "dependencies": [], 37 "dependencies": [],
38 "recommendations": ['MISC-ACCOUNT'], # TODO: remove when all blogs can be retrieved
31 "main": "StaticBlog", 39 "main": "StaticBlog",
32 "handler": "no", 40 "handler": "no",
33 "description": _("""Plugin for static blogs""") 41 "description": _("""Plugin for static blogs""")
34 } 42 }
35 43
59 'description_name': C.STATIC_BLOG_PARAM_DESCRIPTION, 67 'description_name': C.STATIC_BLOG_PARAM_DESCRIPTION,
60 'description_label': D_('Description'), 68 'description_label': D_('Description'),
61 } 69 }
62 70
63 def __init__(self, host): 71 def __init__(self, host):
72 try: # TODO: remove this attribute when all blogs can be retrieved
73 self.domain = host.plugins['MISC-ACCOUNT'].getNewAccountDomain()
74 except KeyError:
75 self.domain = None
64 host.memory.updateParams(self.params) 76 host.memory.updateParams(self.params)
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)
78
79 def _displayPublicBlog(self, menu_data, profile):
80 """Check if the blog can be displayed and answer the frontend.
81
82 @param menu_data: %(menu_data)s
83 @param profile: %(doc_profile)s
84 @return: dict
85 """
86 try:
87 user_jid = jid.JID(menu_data['jid'])
88 except KeyError:
89 log.error(_("jid key is not present !"))
90 return defer.fail(exceptions.DataError)
91
92 # TODO: remove this check when all blogs can be retrieved
93 if self.domain and user_jid.host != self.domain:
94 info_ui = xml_tools.XMLUI("popup", title=D_("Not available"))
95 info_ui.addText(D_("Retrieving a blog from an external domain is not implemented yet."))
96 return {'xmlui': info_ui.toXml()}
97
98 return {"public_blog": user_jid.userhost()}