[Modeling-cvs] ProjectModeling/Modeling/ModelMasons/Python_bricks module_base.tmpl,NONE,1.1 module_c
Status: Abandoned
Brought to you by:
sbigaret
|
From: <sbi...@us...> - 2003-04-20 16:10:44
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/ModelMasons/Python_bricks
In directory sc8-pr-cvs1:/tmp/cvs-serv30397/ModelMasons/Python_bricks
Added Files:
module_base.tmpl module_compact.tmpl base_module.tmpl
Removed Files:
module.tmpl
Log Message:
ModelMasons: added a new generation scheme. The existing one is named
'compact', the new one, 'base'. The latter generates two different modules
for a given entity, in modules <className> (which is not overwritten when
re-generating) and <className>Base (which IS overwritten upon
regeneration)
Updated scripts/mdl_generate_python_code.py
--- NEW FILE: module_base.tmpl ---
## This template will build the module
#for entity in $entities:
from $(entity.className())Base import $(entity.className())Base
#end for
from Modeling.Validation import ValidationException
from mx.DateTime import DateTimeFrom
#from Modeling import utils
#for entity in $entities:
#set $class_name = str($entity.className)
#if $entity.parentEntity():
class $(class_name)($(class_name)Base): #derive from $(entity.parentEntity().className())
#else
class $(class_name)($(class_name)Base):
#end if
"""
$(class_name)s are objects ...
"""
def __init__(self):
"Initializer"
# Note: if you modify this method, it is a strong requirement that
# every parameter gets a default value, since the framework needs to be
# able to instanciate an object with no parameter at all.
$(class_name)Base.__init__(self)
#end for
--- NEW FILE: module_compact.tmpl ---
## This template will build the module
# Modeling
#set $custom = 1
#for entity in $entities:
#if $entity.parentEntity() and $entity.parentEntity() not in $entities:
from $entity.parentEntity().moduleName() import $entity.parentEntity().className()
#elif $custom:
from Modeling.CustomObject import CustomObject
#set $custom=0
#end if
#end for
from Modeling.Validation import ValidationException
from mx.DateTime import DateTimeFrom
#from Modeling import utils
#for entity in $entities:
#set $class_name = str($entity.className)
#set $l_class_name = utils.lower($entity.className)
#set $type_name = $entity.typeName
#set $type_name_id = utils.stringToPythonIdentifier(str($entity.typeName))
#set $entity_props=list($entity.newOrOverriddenPythonProperties())
$entity_props.sort(lambda x,y: cmp(x.name(), y.name()))
#if $entity.parentEntity():
class $(class_name)($(entity.parentEntity().className())):
#else
class $(class_name)(CustomObject):
#end if
"""
$(class_name)s are objects ...
"""
#unless $entity.parentEntity()
__implements__ = CustomObject.__implements__
#end unless
def __init__(self):
"Initializer"
# Note: if you modify this method, it is a strong requirement that
# every parameter gets a default value, since the framework needs to be
# able to instanciate an object with no parameter at all.
#if $entity.parentEntity:
$(entity.parentEntity().name()).__init__(self)
#end if
#for attr in $entity_props:
#if hasattr($attr, 'defaultValueAsPythonStatement'):
#if not $attr in $entity.primaryKeyAttributes():
self._$attr.name = $attr.defaultValueAsPythonStatement
#else
self._$attr.name = $attr.defaultValueAsPythonStatement # Primary Key: read-only!
#end if
#end if
#end for
#for rel in $entity_props:
#if not hasattr($rel, 'defaultValueAsPythonStatement'):
#if $rel.isToMany():
self._$rel.name()=[]
#else
self._$rel.name()=None
#end if
#end if
#end for
def entityName(self):
"Used by the framework to link this object to its entity"
return "$(entity.name)" # do not change
#for attr in $entity_props:
#if hasattr($attr, 'defaultValueAsPythonStatement'):
# Attribute: $attr.name
#if $attr in $entity.primaryKeyAttributes():
# This attribute is a primary key: it is a READ-ONLY attribute that should
# not be changed
#end if
def get$utils.capitalizeFirstLetter(attr.name())(self):
"Return the $class_name / $attr.name attribute value"
self.willRead()
return self._$attr.name
#if not $attr in $entity.primaryKeyAttributes():
def set$utils.capitalizeFirstLetter(attr.name())(self, $attr.name):
"Change the $class_name / $attr.name attribute value"
self.willChange()
self._$attr.name = $attr.name
#end if
def validate$utils.capitalizeFirstLetter(attr.name())(self, value):
"Edit this to enforce custom business logic"
if 0: # your custom bizlogic
raise ValidationException
return
#end if ##* isClassProperty *# #slurp
#end for ##* Attributes *# #slurp
#for rel in $entity_props:
#if not hasattr($rel, 'defaultValueAsPythonStatement'):
# Relationship: $rel.name
#if $rel.isToMany():
def get$(utils.capitalizeFirstLetter($rel.name()))(self):
"Returns the $(rel.name) relationship (toMany)"
self.willRead()
return self._$rel.name()
def addTo$(utils.capitalizeFirstLetter($rel.name()))(self, object):
"Add the $rel.name relationship (toMany)"
if object not in self._$rel.name():
self.willChange()
_$rel.name()=list(self._$rel.name())
_$(rel.name()).append(object)
self._$rel.name()=tuple(_$rel.name())
def removeFrom$(utils.capitalizeFirstLetter($rel.name()))(self, object):
"Remove the $rel.name relationship (toMany)"
self.willChange()
_$rel.name()=list(self._$rel.name())
_$(rel.name()).remove(object)
self._$rel.name()=tuple(_$rel.name())
#else
def get$(utils.capitalizeFirstLetter($rel.name()))(self):
"Return the $rel.name relationship (toOne)"
self.willRead()
return self._$rel.name
def set$(utils.capitalizeFirstLetter($rel.name()))(self, object):
"Set the $rel.name relationship (toOne)"
self.willChange()
self._$rel.name=object
#end if ##* isToMany *#
#end if ##* isClassProperty *#
#end for
#end for
--- NEW FILE: base_module.tmpl ---
## This template will build the <module>Base.py module
# Modeling
#set $custom = 1
#for entity in $entities:
#if $entity.parentEntity() and $entity.parentEntity() not in $entities:
from $entity.parentEntity().moduleName() import $entity.parentEntity().className()
#elif $custom:
from Modeling.CustomObject import CustomObject
#set $custom=0
#end if
#end for
from Modeling.Validation import ValidationException
from mx.DateTime import DateTimeFrom
#from Modeling import utils
#for entity in $entities:
#set $class_name = str($entity.className)
#set $l_class_name = utils.lower($entity.className)
#set $type_name = $entity.typeName
#set $type_name_id = utils.stringToPythonIdentifier(str($entity.typeName))
#set $entity_props=list($entity.newOrOverriddenPythonProperties())
$entity_props.sort(lambda x,y: cmp(x.name(), y.name()))
#if $entity.parentEntity():
class $(class_name)Base($(entity.parentEntity().className())):
#else
class $(class_name)Base(CustomObject):
#end if
"""
Base module for $(class_name)s
"""
#unless $entity.parentEntity()
__implements__ = CustomObject.__implements__
#end unless
def __init__(self):
"Initializer"
# Note: if you modify this method, it is a strong requirement that
# every parameter gets a default value, since the framework needs to be
# able to instanciate an object with no parameter at all.
#if $entity.parentEntity:
$(entity.parentEntity().name()).__init__(self)
#end if
#for attr in $entity_props:
#if hasattr($attr, 'defaultValueAsPythonStatement'):
#if not $attr in $entity.primaryKeyAttributes():
self._$attr.name = $attr.defaultValueAsPythonStatement
#else
self._$attr.name = $attr.defaultValueAsPythonStatement # Primary Key: read-only!
#end if
#end if
#end for
#for rel in $entity_props:
#if not hasattr($rel, 'defaultValueAsPythonStatement'):
#if $rel.isToMany():
self._$rel.name()=[]
#else
self._$rel.name()=None
#end if
#end if
#end for
def entityName(self):
"Used by the framework to link this object to its entity"
return "$(entity.name)" # do not change
#for attr in $entity_props:
#if hasattr($attr, 'defaultValueAsPythonStatement'):
# Attribute: $attr.name
#if $attr in $entity.primaryKeyAttributes():
# This attribute is a primary key: it is a READ-ONLY attribute that should
# not be changed
#end if
def get$utils.capitalizeFirstLetter(attr.name())(self):
"Return the $class_name / $attr.name attribute value"
self.willRead()
return self._$attr.name
#if not $attr in $entity.primaryKeyAttributes():
def set$utils.capitalizeFirstLetter(attr.name())(self, $attr.name):
"Change the $class_name / $attr.name attribute value"
self.willChange()
self._$attr.name = $attr.name
#end if
def validate$utils.capitalizeFirstLetter(attr.name())(self, value):
"Edit this to enforce custom business logic"
if 0: # your custom bizlogic
raise ValidationException
return
#end if ##* isClassProperty *# #slurp
#end for ##* Attributes *# #slurp
#for rel in $entity_props:
#if not hasattr($rel, 'defaultValueAsPythonStatement'):
# Relationship: $rel.name
#if $rel.isToMany():
def get$(utils.capitalizeFirstLetter($rel.name()))(self):
"Returns the $(rel.name) relationship (toMany)"
self.willRead()
return self._$rel.name()
def addTo$(utils.capitalizeFirstLetter($rel.name()))(self, object):
"Add the $rel.name relationship (toMany)"
if object not in self._$rel.name():
self.willChange()
_$rel.name()=list(self._$rel.name())
_$(rel.name()).append(object)
self._$rel.name()=tuple(_$rel.name())
def removeFrom$(utils.capitalizeFirstLetter($rel.name()))(self, object):
"Remove the $rel.name relationship (toMany)"
self.willChange()
_$rel.name()=list(self._$rel.name())
_$(rel.name()).remove(object)
self._$rel.name()=tuple(_$rel.name())
#else
def get$(utils.capitalizeFirstLetter($rel.name()))(self):
"Return the $rel.name relationship (toOne)"
self.willRead()
return self._$rel.name
def set$(utils.capitalizeFirstLetter($rel.name()))(self, object):
"Set the $rel.name relationship (toOne)"
self.willChange()
self._$rel.name=object
#end if ##* isToMany *#
#end if ##* isClassProperty *#
#end for
#end for
--- module.tmpl DELETED ---
|