This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
tabellio.agenda/tabellio/agenda/parlevent.py

74 lines
2.4 KiB
Python

import os
from five import grok
from zope import schema, component
from zope.interface import implements
from z3c.relationfield.schema import RelationChoice
from Products.CMFCore.utils import getToolByName
import datetime
from plone.formwidget.contenttree import ObjPathSourceBinder
from themis.fields import LegisSession
from plone.app.textfield import RichText
from themis.datatypes.commission import ICommission
from plone.registry.interfaces import IRegistry
from tabellio.config.interfaces import ITabellioSettings
from tabellio.agenda.interfaces import MessageFactory as _
from event import IBaseEvent, BaseEvent, EventBaseView
class IParlEvent(IBaseEvent):
session = LegisSession(title=_(u'Session'))
order_of_the_day = RichText(title=_(u'Order of the day'), required=False)
cri = RelationChoice(title=_(u'Minutes'), required=False,
source=ObjPathSourceBinder())
class ParlEvent(BaseEvent):
implements(IParlEvent)
def klass(self):
return 'parlementary-event'
class ParlEventBaseView(EventBaseView):
def next_event_url(self):
return EventBaseView.next_event_url(self,
portal_type=('tabellio.agenda.parlevent',
'tabellio.agenda.comevent'))
def previous_event_url(self):
return EventBaseView.previous_event_url(self,
portal_type=('tabellio.agenda.parlevent',
'tabellio.agenda.comevent'))
def get_stream_name(self):
filename = '%04d%02d%02d%02d-SEAN.mp3' % (
self.context.start.year, self.context.start.month,
self.context.start.day, self.context.start.hour)
return filename
def has_stream(self):
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
if not settings.audiofiles_path:
return False
return os.path.exists(os.path.join(settings.audiofiles_path, self.get_stream_name()))
class View(grok.View, ParlEventBaseView):
grok.context(IParlEvent)
grok.require('zope2.View')
class M3U(grok.View, ParlEventBaseView):
grok.context(IParlEvent)
grok.require('zope2.View')
grok.name('m3u')
def render(self):
portal_url = getToolByName(self.context, 'portal_url').getPortalObject().absolute_url()
self.request.response.setHeader('Content-type', 'audio/x-mpegurl')
return portal_url + '/mp3/' + self.get_stream_name()