Mercurial > libervia-web
changeset 928:ee243d48100e
pages (common): added common hierarchy for reusable pages (blog is the first)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 16 Apr 2017 18:24:24 +0200 |
parents | bb4dfc2802c0 |
children | 2345577da5ca |
files | src/pages/common/blog/page_meta.py src/pages/common/page_meta.py |
diffstat | 2 files changed, 78 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pages/common/blog/page_meta.py Sun Apr 16 18:24:24 2017 +0200 @@ -0,0 +1,72 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +from libervia.server.constants import Const as C +from twisted.words.protocols.jabber import jid +from twisted.internet import defer +from sat.tools.common import data_objects +from sat.core.i18n import _ +from sat.core.log import getLogger +import urllib +log = getLogger('pages/common/blog') + +"""generic blog (with service/node provided)""" +name = u'blog' +template = u"blog/articles.html" +uri_handlers = {(u'pubsub', u'microblog'): 'microblog_uri'} + + +def microblog_uri(self, uri_data): + service = urllib.quote_plus(uri_data[u'path']) + node = urllib.quote_plus(uri_data[u'node']) + return service + u'/' + node + + +def parse_url(self, request): + """URL is /[service]/[node] + + if [node] is not found, default namespace is used + if both [service] and [node] are not found, default service is used too + """ + data = self.getRData(request) + + try: + service = self.nextPath(request) + except IndexError: + data['service'] = u'' + else: + try: + data[u"service"] = jid.JID(service) + except Exception: + log.warning(_(u"bad service entered: {}").format(service)) + self.pageError(request, C.HTTP_BAD_REQUEST) + + try: + data['node'] = self.nextPath(request) + except IndexError: + data['node'] = u'' + + +@defer.inlineCallbacks +def prepare_render(self, request): + data = self.getRData(request) + service, node = data.get(u'service', u''), data.get(u'node', u'') + profile = self.getProfile(request) + if profile is None: + profile = C.SERVICE_PROFILE + + try: + blog_data = yield self.host.bridge.mbGet( + service.userhost(), + node, + 10, + [], + {}, + profile) + except Exception as e: + # FIXME: need a better way to test errors in bridge errback + if u"forbidden" in unicode(e): + self.pageError(request, 401) + else: + raise e + + request.template_data[u'items'] = data_objects.BlogItems(blog_data)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pages/common/page_meta.py Sun Apr 16 18:24:24 2017 +0200 @@ -0,0 +1,6 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +from libervia.server.constants import Const as C + +access = C.PAGES_ACCESS_NONE +"""pages in this hierarchy are pages used commonly and rendered from other locations"""