2009-06-29 07:06:01 -05:00
|
|
|
'''This file contains basic classes that will be added into any user
|
|
|
|
application for creating the basic structure of the application "Tool" which
|
2011-12-05 08:11:29 -06:00
|
|
|
is the set of web pages used for configuring the application.'''
|
2009-06-29 07:06:01 -05:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2010-11-10 08:15:00 -06:00
|
|
|
import types
|
2011-12-05 08:11:29 -06:00
|
|
|
import appy.gen as gen
|
2009-06-29 07:06:01 -05:00
|
|
|
|
2011-09-06 14:46:57 -05:00
|
|
|
# Prototypical instances of every type -----------------------------------------
|
|
|
|
class Protos:
|
|
|
|
protos = {}
|
|
|
|
# List of attributes that can't be given to a Type constructor
|
|
|
|
notInit = ('id', 'type', 'pythonType', 'slaves', 'isSelect', 'hasLabel',
|
2011-10-01 15:40:13 -05:00
|
|
|
'hasDescr', 'hasHelp', 'required', 'filterable', 'validable',
|
|
|
|
'backd', 'isBack', 'sync', 'pageName', 'shownInfoWidths',
|
|
|
|
'masterName')
|
2011-09-06 14:46:57 -05:00
|
|
|
@classmethod
|
|
|
|
def get(self, appyType):
|
|
|
|
'''Returns a prototype instance for p_appyType.'''
|
|
|
|
className = appyType.__class__.__name__
|
|
|
|
isString = (className == 'String')
|
|
|
|
if isString:
|
|
|
|
# For Strings, we create one prototype per format, because default
|
|
|
|
# values may change according to format.
|
|
|
|
className += str(appyType.format)
|
|
|
|
if className in self.protos: return self.protos[className]
|
|
|
|
# The prototype does not exist yet: create it
|
|
|
|
if isString:
|
|
|
|
proto = appyType.__class__(format=appyType.format)
|
|
|
|
# Now, we fake to be able to detect default values
|
|
|
|
proto.format = 0
|
|
|
|
else:
|
|
|
|
proto = appyType.__class__()
|
|
|
|
self.protos[className] = proto
|
|
|
|
return proto
|
|
|
|
|
2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
class ModelClass:
|
|
|
|
'''This class is the abstract class of all predefined application classes
|
2010-10-14 07:43:56 -05:00
|
|
|
used in the Appy model: Tool, User, etc. All methods and attributes of
|
|
|
|
those classes are part of the Appy machinery and are prefixed with _appy_
|
|
|
|
in order to avoid name conflicts with user-defined parts of the
|
|
|
|
application model.'''
|
2009-06-29 07:06:01 -05:00
|
|
|
_appy_attributes = [] # We need to keep track of attributes order.
|
|
|
|
|
2010-01-06 11:36:16 -06:00
|
|
|
@classmethod
|
2011-09-06 14:46:57 -05:00
|
|
|
def _appy_getTypeBody(klass, appyType, wrapperName):
|
2009-06-29 07:06:01 -05:00
|
|
|
'''This method returns the code declaration for p_appyType.'''
|
|
|
|
typeArgs = ''
|
2011-09-06 14:46:57 -05:00
|
|
|
proto = Protos.get(appyType)
|
|
|
|
for name, value in appyType.__dict__.iteritems():
|
|
|
|
# Some attrs can't be given to the constructor
|
|
|
|
if name in Protos.notInit: continue
|
|
|
|
# If the given value corresponds to the default value, don't give it
|
|
|
|
if value == getattr(proto, name): continue
|
|
|
|
if name == 'layouts':
|
2011-01-14 02:06:25 -06:00
|
|
|
# For Tool attributes we do not copy layout info. Indeed, most
|
|
|
|
# fields added to the Tool are config-related attributes whose
|
|
|
|
# layouts must be standard.
|
2011-09-06 14:46:57 -05:00
|
|
|
if klass.__name__ == 'Tool': continue
|
|
|
|
layouts = appyType.getInputLayouts()
|
|
|
|
# For the Translation class that has potentially thousands of
|
|
|
|
# attributes, the most used layout is cached in a global var in
|
2011-12-05 03:52:18 -06:00
|
|
|
# named "tfw" in wrappers.py.
|
2011-09-06 14:46:57 -05:00
|
|
|
if (klass.__name__ == 'Translation') and \
|
|
|
|
(layouts == '{"edit":"f","cell":"f","view":"f",}'):
|
|
|
|
value = 'tfw'
|
|
|
|
else:
|
|
|
|
value = appyType.getInputLayouts()
|
|
|
|
elif isinstance(value, basestring):
|
|
|
|
value = '"%s"' % value
|
2011-12-05 08:11:29 -06:00
|
|
|
elif isinstance(value, gen.Ref):
|
2011-09-06 14:46:57 -05:00
|
|
|
if not value.isBack: continue
|
|
|
|
value = klass._appy_getTypeBody(value, wrapperName)
|
|
|
|
elif type(value) == type(ModelClass):
|
|
|
|
moduleName = value.__module__
|
2009-06-29 07:06:01 -05:00
|
|
|
if moduleName.startswith('appy.gen'):
|
2011-09-06 14:46:57 -05:00
|
|
|
value = value.__name__
|
2009-06-29 07:06:01 -05:00
|
|
|
else:
|
2011-09-06 14:46:57 -05:00
|
|
|
value = '%s.%s' % (moduleName, value.__name__)
|
2011-12-05 08:11:29 -06:00
|
|
|
elif isinstance(value, gen.Selection):
|
2011-09-06 14:46:57 -05:00
|
|
|
value = 'Selection("%s")' % value.methodName
|
2011-12-05 08:11:29 -06:00
|
|
|
elif isinstance(value, gen.Group):
|
2011-11-28 15:50:01 -06:00
|
|
|
value = 'Grp("%s")' % value.name
|
2011-12-05 08:11:29 -06:00
|
|
|
elif isinstance(value, gen.Page):
|
2011-09-06 14:46:57 -05:00
|
|
|
value = 'pages["%s"]' % value.name
|
|
|
|
elif callable(value):
|
|
|
|
value = '%s.%s' % (wrapperName, value.__name__)
|
|
|
|
typeArgs += '%s=%s,' % (name, value)
|
2009-06-29 07:06:01 -05:00
|
|
|
return '%s(%s)' % (appyType.__class__.__name__, typeArgs)
|
|
|
|
|
2010-01-06 11:36:16 -06:00
|
|
|
@classmethod
|
2009-06-29 07:06:01 -05:00
|
|
|
def _appy_getBody(klass):
|
|
|
|
'''This method returns the code declaration of this class. We will dump
|
2011-12-05 03:52:18 -06:00
|
|
|
this in wrappers.py in the Zope product.'''
|
2011-09-06 14:46:57 -05:00
|
|
|
className = klass.__name__
|
|
|
|
# Determine the name of the class and its wrapper. Because so much
|
|
|
|
# attributes can be generated on a TranslationWrapper, shortcutting it
|
|
|
|
# to 'TW' may reduce the generated file from several kilobytes.
|
|
|
|
if className == 'Translation': wrapperName = 'WT'
|
|
|
|
else: wrapperName = 'W%s' % className
|
|
|
|
res = 'class %s(%s):\n' % (className, wrapperName)
|
|
|
|
# Tool must be folderish
|
|
|
|
if className == 'Tool': res += ' folder=True\n'
|
2011-01-14 02:06:25 -06:00
|
|
|
# First, scan all attributes, determine all used pages and create a
|
|
|
|
# dict with it. It will prevent us from creating a new Page instance
|
|
|
|
# for every field.
|
|
|
|
pages = {}
|
2011-09-06 14:46:57 -05:00
|
|
|
layouts = []
|
|
|
|
for name in klass._appy_attributes:
|
|
|
|
exec 'appyType = klass.%s' % name
|
2011-01-14 02:06:25 -06:00
|
|
|
if appyType.page.name not in pages:
|
|
|
|
pages[appyType.page.name] = appyType.page
|
|
|
|
res += ' pages = {'
|
|
|
|
for page in pages.itervalues():
|
|
|
|
# Determine page show
|
|
|
|
pageShow = page.show
|
|
|
|
if isinstance(pageShow, basestring): pageShow='"%s"' % pageShow
|
|
|
|
res += '"%s":Page("%s", show=%s),'% (page.name, page.name, pageShow)
|
|
|
|
res += '}\n'
|
|
|
|
# Secondly, dump every attribute
|
2011-09-06 14:46:57 -05:00
|
|
|
for name in klass._appy_attributes:
|
|
|
|
exec 'appyType = klass.%s' % name
|
|
|
|
typeBody = klass._appy_getTypeBody(appyType, wrapperName)
|
|
|
|
res += ' %s=%s\n' % (name, typeBody)
|
2009-06-29 07:06:01 -05:00
|
|
|
return res
|
|
|
|
|
2010-10-14 07:43:56 -05:00
|
|
|
# The User class ---------------------------------------------------------------
|
2010-09-02 09:16:08 -05:00
|
|
|
class User(ModelClass):
|
2010-10-14 07:43:56 -05:00
|
|
|
# In a ModelClass we need to declare attributes in the following list.
|
|
|
|
_appy_attributes = ['title', 'name', 'firstName', 'login', 'password1',
|
2012-02-02 10:30:54 -06:00
|
|
|
'password2', 'email', 'roles']
|
2010-09-02 09:16:08 -05:00
|
|
|
# All methods defined below are fake. Real versions are in the wrapper.
|
2011-12-05 08:11:29 -06:00
|
|
|
title = gen.String(show=False, indexed=True)
|
2011-03-24 10:21:57 -05:00
|
|
|
gm = {'group': 'main', 'multiplicity': (1,1), 'width': 25}
|
2011-12-05 08:11:29 -06:00
|
|
|
name = gen.String(**gm)
|
|
|
|
firstName = gen.String(**gm)
|
2010-09-02 09:16:08 -05:00
|
|
|
def showLogin(self): pass
|
|
|
|
def validateLogin(self): pass
|
2011-12-05 08:11:29 -06:00
|
|
|
login = gen.String(show=showLogin, validator=validateLogin,
|
|
|
|
indexed=True, **gm)
|
2010-09-02 09:16:08 -05:00
|
|
|
def showPassword(self): pass
|
|
|
|
def validatePassword(self): pass
|
2011-12-05 08:11:29 -06:00
|
|
|
password1 = gen.String(format=gen.String.PASSWORD, show=showPassword,
|
|
|
|
validator=validatePassword, **gm)
|
|
|
|
password2 = gen.String(format=gen.String.PASSWORD, show=showPassword, **gm)
|
2012-02-02 10:30:54 -06:00
|
|
|
email = gen.String(group='main', width=25)
|
2010-09-02 09:16:08 -05:00
|
|
|
gm['multiplicity'] = (0, None)
|
2011-12-05 08:11:29 -06:00
|
|
|
roles = gen.String(validator=gen.Selection('getGrantableRoles'),
|
|
|
|
indexed=True, **gm)
|
2010-09-02 09:16:08 -05:00
|
|
|
|
2011-11-28 15:50:01 -06:00
|
|
|
# The Group class --------------------------------------------------------------
|
|
|
|
class Group(ModelClass):
|
|
|
|
# In a ModelClass we need to declare attributes in the following list.
|
|
|
|
_appy_attributes = ['title', 'login', 'roles', 'users']
|
|
|
|
# All methods defined below are fake. Real versions are in the wrapper.
|
|
|
|
m = {'group': 'main', 'width': 25, 'indexed': True}
|
2011-12-05 08:11:29 -06:00
|
|
|
title = gen.String(multiplicity=(1,1), **m)
|
2011-11-28 15:50:01 -06:00
|
|
|
def showLogin(self): pass
|
|
|
|
def validateLogin(self): pass
|
2011-12-05 08:11:29 -06:00
|
|
|
login = gen.String(show=showLogin, validator=validateLogin,
|
|
|
|
multiplicity=(1,1), **m)
|
|
|
|
roles = gen.String(validator=gen.Selection('getGrantableRoles'),
|
|
|
|
multiplicity=(0,None), **m)
|
|
|
|
users = gen.Ref(User, multiplicity=(0,None), add=False, link=True,
|
|
|
|
back=gen.Ref(attribute='groups', show=True),
|
|
|
|
showHeaders=True, shownInfo=('title', 'login'))
|
2011-11-28 15:50:01 -06:00
|
|
|
|
2011-01-14 02:06:25 -06:00
|
|
|
# The Translation class --------------------------------------------------------
|
|
|
|
class Translation(ModelClass):
|
|
|
|
_appy_attributes = ['po', 'title']
|
|
|
|
# All methods defined below are fake. Real versions are in the wrapper.
|
|
|
|
def getPoFile(self): pass
|
2011-12-05 08:11:29 -06:00
|
|
|
po = gen.Action(action=getPoFile, page=gen.Page('actions', show='view'),
|
|
|
|
result='filetmp')
|
|
|
|
title = gen.String(show=False, indexed=True)
|
2011-09-06 14:46:57 -05:00
|
|
|
def label(self): pass
|
|
|
|
def show(self, name): pass
|
2009-06-29 07:06:01 -05:00
|
|
|
|
2011-01-14 02:06:25 -06:00
|
|
|
# The Tool class ---------------------------------------------------------------
|
2012-02-02 10:30:54 -06:00
|
|
|
# Prefixes of the fields generated on the Tool.
|
2010-10-14 07:43:56 -05:00
|
|
|
toolFieldPrefixes = ('defaultValue', 'podTemplate', 'formats', 'resultColumns',
|
|
|
|
'enableAdvancedSearch', 'numberOfSearchColumns',
|
|
|
|
'searchFields', 'optionalFields', 'showWorkflow',
|
|
|
|
'showWorkflowCommentField', 'showAllStatesInPhase')
|
2011-11-28 15:50:01 -06:00
|
|
|
defaultToolFields = ('users', 'groups', 'translations', 'enableNotifications',
|
2011-01-14 02:06:25 -06:00
|
|
|
'unoEnabledPython', 'openOfficePort',
|
2011-09-08 09:33:16 -05:00
|
|
|
'numberOfResultsPerPage', 'listBoxesMaximumWidth',
|
2011-09-26 14:19:34 -05:00
|
|
|
'appyVersion', 'refreshSecurity')
|
2009-06-29 07:06:01 -05:00
|
|
|
|
2010-10-14 07:43:56 -05:00
|
|
|
class Tool(ModelClass):
|
|
|
|
# In a ModelClass we need to declare attributes in the following list.
|
|
|
|
_appy_attributes = list(defaultToolFields)
|
|
|
|
|
|
|
|
# Tool attributes
|
2011-01-14 02:06:25 -06:00
|
|
|
def validPythonWithUno(self, value): pass # Real method in the wrapper
|
2011-12-05 08:11:29 -06:00
|
|
|
unoEnabledPython = gen.String(group="connectionToOpenOffice",
|
|
|
|
validator=validPythonWithUno)
|
|
|
|
openOfficePort = gen.Integer(default=2002, group="connectionToOpenOffice")
|
|
|
|
numberOfResultsPerPage = gen.Integer(default=30, show=False)
|
|
|
|
listBoxesMaximumWidth = gen.Integer(default=100, show=False)
|
|
|
|
appyVersion = gen.String(show=False, layouts='f')
|
2011-09-08 09:33:16 -05:00
|
|
|
def refreshSecurity(self): pass # Real method in the wrapper
|
2011-12-05 08:11:29 -06:00
|
|
|
refreshSecurity = gen.Action(action=refreshSecurity, confirm=True)
|
2011-09-14 14:01:58 -05:00
|
|
|
# Ref(User) will maybe be transformed into Ref(CustomUserClass).
|
2011-12-05 08:11:29 -06:00
|
|
|
users = gen.Ref(User, multiplicity=(0,None), add=True, link=False,
|
|
|
|
back=gen.Ref(attribute='toTool', show=False),
|
|
|
|
page=gen.Page('users', show='view'),
|
|
|
|
queryable=True, queryFields=('title', 'login'),
|
|
|
|
showHeaders=True, shownInfo=('title', 'login', 'roles'))
|
|
|
|
groups = gen.Ref(Group, multiplicity=(0,None), add=True, link=False,
|
|
|
|
back=gen.Ref(attribute='toTool2', show=False),
|
|
|
|
page=gen.Page('groups', show='view'),
|
|
|
|
queryable=True, queryFields=('title', 'login'),
|
|
|
|
showHeaders=True, shownInfo=('title', 'login', 'roles'))
|
|
|
|
translations = gen.Ref(Translation, multiplicity=(0,None), add=False,
|
|
|
|
link=False, show='view',
|
|
|
|
back=gen.Ref(attribute='trToTool', show=False),
|
|
|
|
page=gen.Page('translations', show='view'))
|
|
|
|
enableNotifications = gen.Boolean(default=True,
|
|
|
|
page=gen.Page('notifications', show=False))
|
2010-01-06 11:36:16 -06:00
|
|
|
|
|
|
|
@classmethod
|
2009-06-29 07:06:01 -05:00
|
|
|
def _appy_clean(klass):
|
|
|
|
toClean = []
|
|
|
|
for k, v in klass.__dict__.iteritems():
|
|
|
|
if not k.startswith('__') and (not k.startswith('_appy_')):
|
2010-10-14 07:43:56 -05:00
|
|
|
if k not in defaultToolFields:
|
2009-06-29 07:06:01 -05:00
|
|
|
toClean.append(k)
|
|
|
|
for k in toClean:
|
|
|
|
exec 'del klass.%s' % k
|
2010-10-14 07:43:56 -05:00
|
|
|
klass._appy_attributes = list(defaultToolFields)
|
2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|