view src/pages/g/e/page_meta.py @ 940:e30a4b7eff09

page (g/e): events invitations first draft
author Goffi <goffi@goffi.org>
date Thu, 27 Apr 2017 01:17:46 +0200
parents
children 6b55d038b121
line wrap: on
line source

#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

from libervia.server.constants import Const as C
from sat.core.i18n import _
from twisted.internet import defer
from twisted.words.protocols.jabber import jid
from libervia.server import session_iface
from sat.tools.common import uri
from sat.core.log import getLogger
log = getLogger('pages/g/e')

access = C.PAGES_ACCESS_PROFILE
template = u"event/invitation.html"


@defer.inlineCallbacks
def prepare_render(self, request):
    template_data = request.template_data
    guest_session = self.host.getSessionData(request, session_iface.ISATGuestSession)
    try:
        main_uri = guest_session.data['main_uri']
        event_uri = guest_session.data['event_uri']
    except KeyError:
        log.warning(_(u"main or event URI not found, can't render event page"))
        self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)

    data = self.getRData(request)

    ## Event ##

    event_uri_data = uri.parseXMPPUri(event_uri)
    if event_uri_data[u'type'] != u'pubsub':
        self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)

    event_service = template_data[u'event_service'] = jid.JID(event_uri_data[u'path'])
    event_node = template_data[u'event_node'] = event_uri_data[u'node']
    profile = self.getProfile(request)
    event_data = yield self.host.bridgeCall(u"eventGet", event_service.userhost(), event_node, profile)
    template_data['event'] = event_data

    ## Blog ##

    main_uri_data = uri.parseXMPPUri(main_uri)
    if main_uri_data[u'type'] != u'pubsub' or main_uri_data.get('sub_type') != 'microblog':
        self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)

    data[u'service'] = jid.JID(main_uri_data[u'path'])
    data[u'node'] = main_uri_data[u'node']

    # we now need blog items, using blog common page
    # this will fill the "items" template data
    blog_page = self.getPageByName(u'blog')
    yield blog_page.prepare_render(self, request)

@defer.inlineCallbacks
def on_data_post(self, request):
    type_ = self.getPostedData(request, u'type')
    if type_ == u'comment':
        blog_page = self.getPageByName(u'blog')
        yield blog_page.on_data_post(self, request)
    elif type_ == u'attendance':
        profile = self.getProfile(request)
        service, node, attend, guests = self.getPostedData(request, (u'service', u'node', u'attend', u'guests'))
        data = {u'attend': attend,
                u'guests': guests}
        yield self.host.bridgeCall(u"eventSet", service, node, data, profile)
    else:
        log.warning(_(u"Unhandled data type: {}").format(type_))