From 46534fc487fc4ae24cdf9a37ca959b236996477d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 6 Nov 2011 16:02:56 +0100 Subject: [PATCH] add utility functions to manage list of legislatures/sessions --- tabellio/config/utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tabellio/config/utils.py b/tabellio/config/utils.py index d3c15fe..9d370ae 100644 --- a/tabellio/config/utils.py +++ b/tabellio/config/utils.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from zope import component from plone.registry.interfaces import IRegistry from interfaces import ITabellioSettings @@ -19,3 +21,25 @@ def get_sessions(): return [] terms = [x.split(':')[1].strip() for x in sessions.splitlines() if x] return terms + +def get_legisl_and_sessions(): + settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False) + sessions = settings.sessions + if not sessions: + return [] + terms = [] + current_legisl = None + for term in sessions.splitlines(): + legisl, session = term.strip().split(':') + if legisl != current_legisl: + terms.append(legisl) + current_legisl = legisl + terms.append('-- %s' % session) + return terms + +def get_list_of_sessions(legisl_or_session): + settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False) + if not legisl_or_session.startswith('--'): + return [x.split(':')[1].strip() for x in settings.sessions.splitlines() if x.split(':')[0] == legisl_or_session] + else: + return [legisl_or_session[3:]]