allow specification of message factory for states definition in order to provide package-specific translation domains

This commit is contained in:
Helmut Merz 2013-03-24 17:13:13 +01:00
parent f898a2b49e
commit e2a19d5ffc
2 changed files with 6 additions and 3 deletions

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2009 Helmut Merz helmutm@cy55.de # Copyright (c) 2013 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -18,8 +18,6 @@
""" """
Basic implementations for stateful objects and adapters. Basic implementations for stateful objects and adapters.
$Id$
""" """
from persistent.interfaces import IPersistent from persistent.interfaces import IPersistent
@ -99,6 +97,7 @@ class StatefulAdapter(Stateful):
def __init__(self, context): def __init__(self, context):
self.context = context self.context = context
self.msgFactory = self.getStatesDefinition().msgFactory
def getState(self): def getState(self):
statesAttr = getattr(self.context, self.statesAttributeName, {}) statesAttr = getattr(self.context, self.statesAttributeName, {})

View file

@ -76,11 +76,13 @@ class StatesDefinition(object):
implements(IStatesDefinition) implements(IStatesDefinition)
initialState = 'started' initialState = 'started'
msgFactory = None
def __init__(self, name, *details, **kw): def __init__(self, name, *details, **kw):
self.name = self.__name__ = name self.name = self.__name__ = name
self.states = Jeep() self.states = Jeep()
self.transitions = Jeep() self.transitions = Jeep()
msgFactory = kw.get('msgFactory')
for d in details: for d in details:
if ITransition.providedBy(d): if ITransition.providedBy(d):
self.transitions.append(d) self.transitions.append(d)
@ -89,6 +91,8 @@ class StatesDefinition(object):
else: else:
raise TypeError('Only states or transitions are allowed here, ' raise TypeError('Only states or transitions are allowed here, '
'got %s instead.' % repr(d)) 'got %s instead.' % repr(d))
if msgFactory:
d.title = msgFactory(d.title)
for k, v in kw.items(): for k, v in kw.items():
setattr(self, k, v) setattr(self, k, v)