#!/usr/bin/env python
##################################################
## DEPENDENCIES
import sys
import os
import os.path
from os.path import getmtime,exists
import time
import types
import __builtin__
from Cheetah.Version import MinCompatibleVersion
from Cheetah.Version import MinCompatibleVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import DummyTransaction
from Cheetah.NameMapper import NotFound,valueForName,valueFromSearchList,valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers
import time
from Modeling import utils
##################################################
## MODULE CONSTANTS
try:
True, False
except NameError:
True, False = (1==1), (1==0)
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '2.0rc6'
__CHEETAH_versionTuple__ = (2, 0, 0, 'candidate', 6)
__CHEETAH_genTime__ = 1140978986.270437
__CHEETAH_genTimestamp__ = 'Sun Feb 26 19:36:26 2006'
__CHEETAH_src__ = 'Modeling/ModelMasons/Python_bricks/module_compact.tmpl'
__CHEETAH_srcLastModified__ = 'Sun Feb 26 19:08:10 2006'
__CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine'
if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
raise AssertionError(
'This template was compiled with Cheetah version'
' %s. Templates compiled before version %s must be recompiled.'%(
__CHEETAH_version__, RequiredCheetahVersion))
##################################################
## CLASSES
class module_compact(Template):
##################################################
## CHEETAH GENERATED METHODS
def __init__(self, *args, **KWs):
Template.__init__(self, *args, **KWs)
if not self._CHEETAH__instanceInitialized:
cheetahKWArgs = {}
allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
for k,v in KWs.items():
if k in allowedKWs: cheetahKWArgs[k] = v
self._initCheetahInstance(**cheetahKWArgs)
def respond(self, trans=None):
## CHEETAH: main method generated for this template
if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
trans = self.transaction # is None unless self.awake() was called
if not trans:
trans = DummyTransaction()
_dummyTrans = True
else: _dummyTrans = False
write = trans.response().write
SL = self._CHEETAH__searchList
_filter = self._CHEETAH__currentFilter
########################################
## START - generated method body
# This template will build the module
write('# Generated by mdl_generate_python_code.py / ')
_v = VFN(VFFSL(SL,"time",True),"strftime",False)("%Y/%m/%d %H:%M") # '$(time.strftime("%Y/%m/%d %H:%M"))' on line 3, col 46
if _v is not None: write(_filter(_v, rawExpr='$(time.strftime("%Y/%m/%d %H:%M"))')) # from line 3, col 46.
write('\n')
custom = 1
for entity in VFFSL(SL,"entities",True): # generated from line 5, col 1
if VFN(VFFSL(SL,"entity",True),"parentEntity",False)() and VFN(VFFSL(SL,"entity",True),"parentEntity",False)() not in VFFSL(SL,"entities",True): # generated from line 6, col 1
write('from ')
_v = VFN(VFN(VFFSL(SL,"entity",True),"parentEntity",False)(),"moduleName",False)() # '$entity.parentEntity().moduleName()' on line 7, col 6
if _v is not None: write(_filter(_v, rawExpr='$entity.parentEntity().moduleName()')) # from line 7, col 6.
write(' import ')
_v = VFN(VFN(VFFSL(SL,"entity",True),"parentEntity",False)(),"className",False)() # '$entity.parentEntity().className()' on line 7, col 49
if _v is not None: write(_filter(_v, rawExpr='$entity.parentEntity().className()')) # from line 7, col 49.
write('\n')
elif VFFSL(SL,"custom",True): # generated from line 8, col 1
write('from Modeling.CustomObject import CustomObject\n')
custom = 0
write('''from Modeling.Validation import ValidationException
from mx.DateTime import DateTimeFrom
''')
for entity in VFFSL(SL,"entities",True): # generated from line 17, col 1
class_name = str(VFFSL(SL,"entity.className",True))
l_class_name = utils.lower(VFFSL(SL,"entity.className",True))
type_name = VFFSL(SL,"entity.typeName",True)
type_name_id = utils.stringToPythonIdentifier(str(VFFSL(SL,"entity.typeName",True)))
entity_props = list(VFN(VFFSL(SL,"entity",True),"newOrOverriddenPythonProperties",False)())
_v = VFN(VFFSL(SL,"entity_props",True),"sort",False)(lambda x,y: cmp(x.name(), y.name())) # '$entity_props.sort(lambda x,y: cmp(x.name(), y.name()))' on line 23, col 1
if _v is not None: write(_filter(_v, rawExpr='$entity_props.sort(lambda x,y: cmp(x.name(), y.name()))')) # from line 23, col 1.
write('\n')
if VFN(VFFSL(SL,"entity",True),"parentEntity",False)(): # generated from line 24, col 1
write('class ')
_v = VFFSL(SL,"class_name",True) # '$(class_name)' on line 25, col 7
if _v is not None: write(_filter(_v, rawExpr='$(class_name)')) # from line 25, col 7.
write('(')
_v = VFN(VFN(VFFSL(SL,"entity",True),"parentEntity",False)(),"className",False)() # '$(entity.parentEntity().className())' on line 25, col 21
if _v is not None: write(_filter(_v, rawExpr='$(entity.parentEntity().className())')) # from line 25, col 21.
write('):\n')
else: # generated from line 26, col 1
write('class ')
_v = VFFSL(SL,"class_name",True) # '$(class_name)' on line 27, col 7
if _v is not None: write(_filter(_v, rawExpr='$(class_name)')) # from line 27, col 7.
write('(CustomObject):\n')
write(' """\n ')
_v = VFFSL(SL,"class_name",True) # '$(class_name)' on line 30, col 3
if _v is not None: write(_filter(_v, rawExpr='$(class_name)')) # from line 30, col 3.
write('''s are objects ...
"""
''')
if not (VFN(VFFSL(SL,"entity",True),"parentEntity",False)()):
write(' __implements__ = CustomObject.__implements__\n')
write('''
def __init__(self, **kw):
"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 VFFSL(SL,"entity.parentEntity",True): # generated from line 42, col 5
write(' ')
_v = VFN(VFN(VFFSL(SL,"entity",True),"parentEntity",False)(),"name",False)() # '$(entity.parentEntity().name())' on line 43, col 5
if _v is not None: write(_filter(_v, rawExpr='$(entity.parentEntity().name())')) # from line 43, col 5.
write('.__init__(self)\n')
for attr in VFFSL(SL,"entity_props",True): # generated from line 45, col 5
if hasattr(VFFSL(SL,"attr",True), 'defaultValueAsPythonStatement'): # generated from line 46, col 5
if not VFFSL(SL,"attr",True) in VFN(VFFSL(SL,"entity",True),"primaryKeyAttributes",False)(): # generated from line 47, col 1
write(' self._')
_v = VFFSL(SL,"attr.name",True) # '$attr.name' on line 48, col 11
if _v is not None: write(_filter(_v, rawExpr='$attr.name')) # from line 48, col 11.
write(' = ')
_v = VFFSL(SL,"attr.defaultValueAsPythonStatement",True) # '$attr.defaultValueAsPythonStatement' on line 48, col 24
if _v is not None: write(_filter(_v, rawExpr='$attr.defaultValueAsPythonStatement')) # from line 48, col 24.
write('\n')
else: # generated from line 49, col 1
write(' self._')
_v = VFFSL(SL,"attr.name",True) # '$attr.name' on line 50, col 11
if _v is not None: write(_filter(_v, rawExpr='$attr.name')) # from line 50, col 11.
write(' = ')
_v = VFFSL(SL,"attr.defaultValueAsPythonStatement",True) # '$attr.defaultValueAsPythonStatement' on line 50, col 24
if _v is not None: write(_filter(_v, rawExpr='$attr.defaultValueAsPythonStatement')) # from line 50, col 24.
write(' # Primary Key: read-only!\n')
for rel in VFFSL(SL,"entity_props",True): # generated from line 54, col 5
if not hasattr(VFFSL(SL,"rel",True), 'defaultValueAsPythonStatement'): # generated from line 55, col 7
if VFN(VFFSL(SL,"rel",True),"isToMany",False)(): # generated from line 56, col 9
write(' self._')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 57, col 11
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 57, col 11.
write('=[]\n')
else: # generated from line 58, col 9
write(' self._')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 59, col 11
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 59, col 11.
write('=None\n')
write(''' for k,v in kw.items():
self.takeValueForKey(v, k)
def entityName(self):
"Used by the framework to link this object to its entity"
return "''')
_v = VFFSL(SL,"entity.name",True) # '$(entity.name)' on line 68, col 15
if _v is not None: write(_filter(_v, rawExpr='$(entity.name)')) # from line 68, col 15.
write('" # do not change\n\n')
for attr in VFFSL(SL,"entity_props",True): # generated from line 70, col 3
if hasattr(VFFSL(SL,"attr",True), 'defaultValueAsPythonStatement'): # generated from line 71, col 3
write('\n # Attribute: ')
_v = VFFSL(SL,"attr.name",True) # '$attr.name' on line 73, col 16
if _v is not None: write(_filter(_v, rawExpr='$attr.name')) # from line 73, col 16.
write('\n')
if VFFSL(SL,"attr",True) in VFN(VFFSL(SL,"entity",True),"primaryKeyAttributes",False)(): # generated from line 74, col 1
write(' # This attribute is a primary key: it is a READ-ONLY attribute that should\n # not be changed\n')
write(' def get')
_v = VFN(VFFSL(SL,"utils",True),"capitalizeFirstLetter",False)(attr.name()) # '$utils.capitalizeFirstLetter(attr.name())' on line 78, col 10
if _v is not None: write(_filter(_v, rawExpr='$utils.capitalizeFirstLetter(attr.name())')) # from line 78, col 10.
write('(self):\n "Return the ')
_v = VFFSL(SL,"class_name",True) # '$class_name' on line 79, col 17
if _v is not None: write(_filter(_v, rawExpr='$class_name')) # from line 79, col 17.
write(' / ')
_v = VFFSL(SL,"attr.name",True) # '$attr.name' on line 79, col 31
if _v is not None: write(_filter(_v, rawExpr='$attr.name')) # from line 79, col 31.
write(' attribute value"\n self.willRead()\n return self._')
_v = VFFSL(SL,"attr.name",True) # '$attr.name' on line 81, col 18
if _v is not None: write(_filter(_v, rawExpr='$attr.name')) # from line 81, col 18.
write('\n \n')
if not VFFSL(SL,"attr",True) in VFN(VFFSL(SL,"entity",True),"primaryKeyAttributes",False)(): # generated from line 83, col 1
write(' def set')
_v = VFN(VFFSL(SL,"utils",True),"capitalizeFirstLetter",False)(attr.name()) # '$utils.capitalizeFirstLetter(attr.name())' on line 84, col 10
if _v is not None: write(_filter(_v, rawExpr='$utils.capitalizeFirstLetter(attr.name())')) # from line 84, col 10.
write('(self, ')
_v = VFFSL(SL,"attr.name",True) # '$attr.name' on line 84, col 58
if _v is not None: write(_filter(_v, rawExpr='$attr.name')) # from line 84, col 58.
write('):\n "Change the ')
_v = VFFSL(SL,"class_name",True) # '$class_name' on line 85, col 17
if _v is not None: write(_filter(_v, rawExpr='$class_name')) # from line 85, col 17.
write(' / ')
_v = VFFSL(SL,"attr.name",True) # '$attr.name' on line 85, col 31
if _v is not None: write(_filter(_v, rawExpr='$attr.name')) # from line 85, col 31.
write(' attribute value"\n self.willChange()\n self._')
_v = VFFSL(SL,"attr.name",True) # '$attr.name' on line 87, col 11
if _v is not None: write(_filter(_v, rawExpr='$attr.name')) # from line 87, col 11.
write(' = ')
_v = VFFSL(SL,"attr.name",True) # '$attr.name' on line 87, col 25
if _v is not None: write(_filter(_v, rawExpr='$attr.name')) # from line 87, col 25.
write('\n')
write(' def validate')
_v = VFN(VFFSL(SL,"utils",True),"capitalizeFirstLetter",False)(attr.name()) # '$utils.capitalizeFirstLetter(attr.name())' on line 89, col 15
if _v is not None: write(_filter(_v, rawExpr='$utils.capitalizeFirstLetter(attr.name())')) # from line 89, col 15.
write('''(self, value):
"Edit this to enforce custom business logic"
if 0: # your custom bizlogic
raise ValidationException
return
''')
# isClassProperty
write(' ')
# Attributes
write(' ')
write(' \n')
for rel in VFFSL(SL,"entity_props",True): # generated from line 97, col 3
if not hasattr(VFFSL(SL,"rel",True), 'defaultValueAsPythonStatement'): # generated from line 98, col 3
write(' # Relationship: ')
_v = VFFSL(SL,"rel.name",True) # '$rel.name' on line 99, col 19
if _v is not None: write(_filter(_v, rawExpr='$rel.name')) # from line 99, col 19.
write('\n\n')
if VFN(VFFSL(SL,"rel",True),"isToMany",False)(): # generated from line 101, col 3
write(' def get')
_v = VFN(VFFSL(SL,"utils",True),"capitalizeFirstLetter",False)(VFN(VFFSL(SL,"rel",True),"name",False)()) # '$(utils.capitalizeFirstLetter($rel.name()))' on line 102, col 10
if _v is not None: write(_filter(_v, rawExpr='$(utils.capitalizeFirstLetter($rel.name()))')) # from line 102, col 10.
write('(self):\n "Returns the ')
_v = VFFSL(SL,"rel.name",True) # '$(rel.name)' on line 103, col 18
if _v is not None: write(_filter(_v, rawExpr='$(rel.name)')) # from line 103, col 18.
write(' relationship (toMany)"\n self.willRead()\n return self._')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 105, col 18
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 105, col 18.
write('\n \n def addTo')
_v = VFN(VFFSL(SL,"utils",True),"capitalizeFirstLetter",False)(VFN(VFFSL(SL,"rel",True),"name",False)()) # '$(utils.capitalizeFirstLetter($rel.name()))' on line 107, col 12
if _v is not None: write(_filter(_v, rawExpr='$(utils.capitalizeFirstLetter($rel.name()))')) # from line 107, col 12.
write('(self, object):\n "Add the ')
_v = VFFSL(SL,"rel.name",True) # '$rel.name' on line 108, col 14
if _v is not None: write(_filter(_v, rawExpr='$rel.name')) # from line 108, col 14.
write(' relationship (toMany)"\n if object not in self._')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 109, col 28
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 109, col 28.
write(':\n self.willChange()\n _')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 111, col 8
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 111, col 8.
write('=list(self._')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 111, col 31
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 111, col 31.
write(')\n _')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$(rel.name())' on line 112, col 8
if _v is not None: write(_filter(_v, rawExpr='$(rel.name())')) # from line 112, col 8.
write('.append(object)\n self._')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 113, col 13
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 113, col 13.
write('=tuple(_')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 113, col 32
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 113, col 32.
write(')\n \n def removeFrom')
_v = VFN(VFFSL(SL,"utils",True),"capitalizeFirstLetter",False)(VFN(VFFSL(SL,"rel",True),"name",False)()) # '$(utils.capitalizeFirstLetter($rel.name()))' on line 115, col 17
if _v is not None: write(_filter(_v, rawExpr='$(utils.capitalizeFirstLetter($rel.name()))')) # from line 115, col 17.
write('(self, object):\n "Remove the ')
_v = VFFSL(SL,"rel.name",True) # '$rel.name' on line 116, col 17
if _v is not None: write(_filter(_v, rawExpr='$rel.name')) # from line 116, col 17.
write(' relationship (toMany)"\n self.willChange()\n _')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 118, col 6
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 118, col 6.
write('=list(self._')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 118, col 29
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 118, col 29.
write(')\n _')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$(rel.name())' on line 119, col 6
if _v is not None: write(_filter(_v, rawExpr='$(rel.name())')) # from line 119, col 6.
write('.remove(object)\n self._')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 120, col 11
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 120, col 11.
write('=tuple(_')
_v = VFN(VFFSL(SL,"rel",True),"name",False)() # '$rel.name()' on line 120, col 30
if _v is not None: write(_filter(_v, rawExpr='$rel.name()')) # from line 120, col 30.
write(')\n \n')
else: # generated from line 122, col 3
write(' def get')
_v = VFN(VFFSL(SL,"utils",True),"capitalizeFirstLetter",False)(VFN(VFFSL(SL,"rel",True),"name",False)()) # '$(utils.capitalizeFirstLetter($rel.name()))' on line 123, col 10
if _v is not None: write(_filter(_v, rawExpr='$(utils.capitalizeFirstLetter($rel.name()))')) # from line 123, col 10.
write('(self):\n "Return the ')
_v = VFFSL(SL,"rel.name",True) # '$rel.name' on line 124, col 17
if _v is not None: write(_filter(_v, rawExpr='$rel.name')) # from line 124, col 17.
write(' relationship (toOne)"\n self.willRead()\n return self._')
_v = VFFSL(SL,"rel.name",True) # '$rel.name' on line 126, col 18
if _v is not None: write(_filter(_v, rawExpr='$rel.name')) # from line 126, col 18.
write('\n \n def set')
_v = VFN(VFFSL(SL,"utils",True),"capitalizeFirstLetter",False)(VFN(VFFSL(SL,"rel",True),"name",False)()) # '$(utils.capitalizeFirstLetter($rel.name()))' on line 128, col 10
if _v is not None: write(_filter(_v, rawExpr='$(utils.capitalizeFirstLetter($rel.name()))')) # from line 128, col 10.
write('(self, object):\n "Set the ')
_v = VFFSL(SL,"rel.name",True) # '$rel.name' on line 129, col 14
if _v is not None: write(_filter(_v, rawExpr='$rel.name')) # from line 129, col 14.
write(' relationship (toOne)"\n self.willChange()\n self._')
_v = VFFSL(SL,"rel.name",True) # '$rel.name' on line 131, col 11
if _v is not None: write(_filter(_v, rawExpr='$rel.name')) # from line 131, col 11.
write('=object\n ')
# isToMany
write('\n ')
# isClassProperty
write('\n')
########################################
## END - generated method body
return _dummyTrans and trans.response().getvalue() or ""
##################################################
## CHEETAH GENERATED ATTRIBUTES
_CHEETAH__instanceInitialized = False
_CHEETAH_version = __CHEETAH_version__
_CHEETAH_versionTuple = __CHEETAH_versionTuple__
_CHEETAH_genTime = __CHEETAH_genTime__
_CHEETAH_genTimestamp = __CHEETAH_genTimestamp__
_CHEETAH_src = __CHEETAH_src__
_CHEETAH_srcLastModified = __CHEETAH_srcLastModified__
_mainCheetahMethod_for_module_compact= 'respond'
## END CLASS DEFINITION
if not hasattr(module_compact, '_initCheetahAttributes'):
templateAPIClass = getattr(module_compact, '_CHEETAH_templateClass', Template)
templateAPIClass._addCheetahPlumbingCodeToClass(module_compact)
# CHEETAH was developed by Tavis Rudd and Mike Orr
# with code, advice and input from many other volunteers.
# For more information visit http://www.CheetahTemplate.org/
##################################################
## if run from command line:
if __name__ == '__main__':
from Cheetah.TemplateCmdLineIface import CmdLineIface
CmdLineIface(templateObj=module_compact()).run()
|