2011-11-06 16:02:56 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2011-11-11 16:28:07 +01:00
|
|
|
import time
|
|
|
|
|
2011-08-18 13:21:55 +02:00
|
|
|
from zope import component
|
|
|
|
from plone.registry.interfaces import IRegistry
|
|
|
|
from interfaces import ITabellioSettings
|
2011-11-11 16:28:07 +01:00
|
|
|
from plone.memoize import ram
|
2011-08-18 13:21:55 +02:00
|
|
|
|
|
|
|
def get_dossiers_path():
|
|
|
|
return component.getUtility(IRegistry).forInterface(ITabellioSettings, False).dossiersPath
|
|
|
|
|
2011-11-16 19:15:09 +01:00
|
|
|
def get_questions_path():
|
|
|
|
return component.getUtility(IRegistry).forInterface(ITabellioSettings, False).questionsPath
|
|
|
|
|
2011-08-18 13:21:55 +02:00
|
|
|
def get_documents_path():
|
|
|
|
return component.getUtility(IRegistry).forInterface(ITabellioSettings, False).documentsPath
|
|
|
|
|
2012-04-23 10:41:31 +02:00
|
|
|
def get_convocations_path():
|
|
|
|
return component.getUtility(IRegistry).forInterface(ITabellioSettings, False).convocationsPath
|
|
|
|
|
2011-08-29 09:49:01 +02:00
|
|
|
def get_deputies_path():
|
|
|
|
return component.getUtility(IRegistry).forInterface(ITabellioSettings, False).deputiesPath
|
2011-08-18 13:21:55 +02:00
|
|
|
|
2011-11-10 16:26:52 +01:00
|
|
|
def get_polgroups_path():
|
|
|
|
return component.getUtility(IRegistry).forInterface(ITabellioSettings, False).polgroupsPath
|
|
|
|
|
2011-08-18 13:21:55 +02:00
|
|
|
def get_sessions():
|
|
|
|
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
|
|
|
sessions = settings.sessions
|
2011-09-14 10:00:34 +02:00
|
|
|
if not sessions:
|
|
|
|
return []
|
2011-08-18 13:21:55 +02:00
|
|
|
terms = [x.split(':')[1].strip() for x in sessions.splitlines() if x]
|
|
|
|
return terms
|
2011-11-06 16:02:56 +01:00
|
|
|
|
2011-11-11 16:28:07 +01:00
|
|
|
@ram.cache(lambda *args: time.time() // (5 * 60)) # 5 minutes
|
|
|
|
def get_topics_dict():
|
|
|
|
from plone.i18n.normalizer.fr import normalizer
|
|
|
|
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
|
|
|
if not settings.topics:
|
|
|
|
return {}
|
|
|
|
topics = {}
|
|
|
|
for line in settings.topics.splitlines():
|
2011-11-20 20:58:44 +01:00
|
|
|
if line.count('|') == 1:
|
|
|
|
id, term = line.strip().split('|')
|
|
|
|
else:
|
|
|
|
term = line.strip()
|
|
|
|
id = term.encode('ascii', 'replace')
|
2011-11-11 16:28:07 +01:00
|
|
|
topics[id] = (term, normalizer.normalize(term).lower())
|
|
|
|
return topics
|
|
|
|
|
2011-11-06 16:02:56 +01:00
|
|
|
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:]]
|
2011-11-24 15:29:39 +01:00
|
|
|
|
|
|
|
def get_ordered_sessions():
|
|
|
|
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
|
|
|
return list(reversed([x.split(':')[1].strip() for x in settings.sessions.splitlines()]))
|
2011-11-28 14:47:24 +01:00
|
|
|
|
|
|
|
def get_com_audio_code(com_id):
|
|
|
|
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
|
|
|
for line in settings.commission_audio_codes.splitlines():
|
|
|
|
id, audio_code = line.strip().split(':')
|
|
|
|
if id == com_id:
|
|
|
|
return audio_code
|
|
|
|
return None
|