# HG changeset patch # User Goffi # Date 1488755131 -3600 # Node ID 96a56856d357f6ee02b7c7493314f50b926760eb # Parent 86563d6c83b0791ab6280925f941dfbeccc25518 pages (blog_new/articles): first concert Libervia page, blog articles: This page is for now called blog_new to avoid conflict with former blog static page, but it will replace the older one when ready. The page get target profile from URL, the request 10 last blog from it, and display it using blog/articles template. Errors are not correctly handled for now (specially blog retrieval errors). diff -r 86563d6c83b0 -r 96a56856d357 src/pages/blog_new/page_meta.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pages/blog_new/page_meta.py Mon Mar 06 00:05:31 2017 +0100 @@ -0,0 +1,38 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- + +from libervia.server.constants import Const as C +from twisted.internet import defer +from twisted.words.protocols.jabber import jid +from sat.tools.common import data_objects + +access = C.PAGES_ACCESS_PUBLIC # can be a callable +template = u"blog/articles.html" + +@defer.inlineCallbacks +def parse_url(self, request): + try: + prof_requested = self.nextPath(request) + except IndexError: + self.pageError(request) + + template_data = request.template_data + + target_profile = yield self.host.bridge.profileNameGet(prof_requested) + template_data[u'target_profile'] = target_profile + target_jid = yield self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', profile_key=target_profile) + target_jid = jid.JID(target_jid).userhost() + template_data[u'target_jid'] = target_jid + + +@defer.inlineCallbacks +def prepare_render(self, request): + target_jid = request.template_data[u'target_jid'] + blog_data = yield self.host.bridge.mbGet( + target_jid, + "", + 10, + [], + {}, + C.SERVICE_PROFILE) + request.template_data[u'items'] = data_objects.BlogItems(blog_data)