[Zapp-cvs-commit] ZApp/skins/zapp_generic clearStack.py,NONE,1.1 getApplication.py,NONE,1.1 getCurre
Brought to you by:
sspickle
Update of /cvsroot/zapp/ZApp/skins/zapp_generic
In directory sc8-pr-cvs1:/tmp/cvs-serv14999/skins/zapp_generic
Added Files:
clearStack.py getApplication.py getCurrentStack.py
getSessionValue.py getTopNamespace.py guess_type.py
manage_edit_stack_levels.py manage_session_stack.pt
popStateInfo.py pushStateInfo.py setCurrentStack.py
setSessionValues.py setupRequest.py zapp_cmf_object_edit.py
zapp_cmf_object_edit_form.pt zapp_cmf_object_get_info.py
zapp_cmf_object_type_edit.py zapp_cmf_object_type_edit_form.pt
zapp_cmf_object_view.pt zapp_file_edit.py
zapp_file_edit_form.pt zapp_file_view.pt zapp_get_fileObj.py
zapp_image_edit.py zapp_image_edit_form.pt zapp_image_view.pt
Log Message:
added some skins to ZApp CMF core..
--- NEW FILE: clearStack.py ---
## Script (Python) "clearStack"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
context.setCurrentStack([{}])
return 'OK!'
--- NEW FILE: getApplication.py ---
## Script (Python) "getApplication"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
return getattr(context, getattr(context, 'hec_app_id', 'HTheatre'))
--- NEW FILE: getCurrentStack.py ---
## Script (Python) "getCurrentStack"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=Get the Current Stack
##
sessionID = context.browser_id_manager.getBrowserId(create=1)
system_app = context.getApplication()
SESSION = context.REQUEST.SESSION
currStack = SESSION.get('HEC_STACK',[{}])
if not len(currStack) :
currStack = [{}]
return currStack
--- NEW FILE: getSessionValue.py ---
## Script (Python) "getSessionValue"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=key, defaultVal=''
##title=
##
result = defaultVal
ns = context.getTopNamespace()
if ns:
result = ns.get(key,result)
return result
--- NEW FILE: getTopNamespace.py ---
## Script (Python) "getTopNamespace"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=Return the Top Stack Dict
##
result = {}
currStack = context.getCurrentStack()
if currStack:
result = currStack[-1]
result.update({'hec_v_stackSize':len(currStack)})
return result
--- NEW FILE: guess_type.py ---
## Script (Python) "guess_type"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=value
##title=Get the Current Stack
##
if same_type(value,''):
return 'string'
elif same_type(value,0):
return 'int'
elif same_type(value,0.0):
return 'float'
elif same_type(value,[]):
return 'list'
elif same_type(value,{}):
return 'structure'
else:
return 'unknown'
--- NEW FILE: manage_edit_stack_levels.py ---
## Script (Python) "getCurrentStack"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=sessionLevels=None, submit=None, indexes=None
##title=Get the Current Stack
##
if submit == 'EDIT':
indexes = []
if submit in ['EDIT','DELETE']:
newStack = []
for i in range(len(sessionLevels)):
level = sessionLevels[i]
if level.index not in indexes:
newLevel = {}
newStack.append(newLevel)
for k in level.keys():
newLevel[k] = level[k]
context.setCurrentStack(newStack)
else:
raise RuntimeError, "I don't know that one!: " + `submit` + ":" + `indexes`
context.REQUEST.RESPONSE.redirect( context.REQUEST.URL1 + '/manage_session_stack')
--- NEW FILE: manage_session_stack.pt ---
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="here/main_template/macros/master">
<metal:block fill-slot="base">
<base href=""
tal:attributes="href python: here.absolute_url() + '/'">
</metal:block>
<body>
<div metal:fill-slot="header">
<h1 id="DesktopTitle"
tal:content="here/Title">Document Title</h1>
<div id="DesktopDescription">
This is a screen for managing your current system stack.
</div>
</div>
<div metal:fill-slot="main">
<div tal:define="theStack here/getCurrentStack">
<br><br>
<form action="manage_edit_stack_levels" method="post">
<table>
<tr tal:repeat="stackLevel theStack">
<td><h3><input type="checkbox" name="indexes:int:list" tal:attributes="value repeat/stackLevel/index"><span tal:content="string:Level ${repeat/stackLevel/index}" /></h3>
<input type="hidden" name="sessionLevels.index:int:records" tal:attributes="value repeat/stackLevel/index"/></td>
<td><table tal:define="itemKeys stackLevel/keys" border="1"><tr><td>
<table>
<tr tal:repeat="itemKey itemKeys">
<tal:block tal:omit-tag="" tal:define="itemValue python:stackLevel[itemKey];
itemType python:here.guess_type(itemValue)">
<td tal:content="string:${itemKey} (${itemType})"/><td><input size="20" tal:attributes="name string:sessionLevels.${itemKey}:${itemType}:records;
value itemValue"></td>
</tal:block>
</tr>
</table>
</td></tr></table>
</td>
</tr>
</table>
<input type="submit" value="EDIT" name="submit">
<input type="submit" value="DELETE" name="submit">
</form>
</div>
</div>
</body>
</html>
--- NEW FILE: popStateInfo.py ---
## Script (Python) "popStateInfo""
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=stateDict=None
##title=
##
currStack = context.getCurrentStack()
try:
topInfo = currStack.pop()
except:
currStack = context.getCurrentStack()
context.setCurrentStack( currStack )
return currStack
--- NEW FILE: pushStateInfo.py ---
## Script (Python) "pushStateInfo"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=stateDict=None
##title=
##
if stateDict is None:
stateDict = context.REQUEST.form
currStack = context.getCurrentStack()
currStack.append(stateDict)
context.setCurrentStack( currStack )
return "OK"
--- NEW FILE: setCurrentStack.py ---
## Script (Python) "setCurrentStack"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=currStack
##title=
##
SESSION = context.REQUEST.SESSION
SESSION['BSM_STACK'] = currStack
return "OK!"
--- NEW FILE: setSessionValues.py ---
## Script (Python) "setSessionValues"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=key=None, value=None, kwDict=None, **kw
##title=
##
currStack = context.getCurrentStack()
dataDict = kw
if key is not None:
dataDict[key] = value
if kwDict is not None:
dataDict.update(kwDict)
topDict = currStack[-1]
for key, val in dataDict.items():
topDict[key] = val
context.setCurrentStack(currStack)
return topDict
--- NEW FILE: setupRequest.py ---
## Script (Python) "setupRequest"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
import string
REQUEST=context.REQUEST
if not REQUEST.get('HEC_Setup',None):
rawInput = context.mmu_getRawInput(REQUEST)
xmlDict = {}
if len(rawInput):
try:
xmlDict = context.mmu_handleXML(rawInput)
dataDict = xmlDict['RequestData']['Variables']
except:
dataDict = REQUEST.form
else:
dataDict = REQUEST.form
#
# translation
#
REQUEST.set('dataDict', dataDict)
REQUEST.set('xmlDict', xmlDict)
REQUEST.set('listsUpdated',dataDict.get('listsUpdated','2000/1/1'))
try:
size = string.atoi(dataDict.get('size','20'))
except:
size = 20
REQUEST.set('size',size)
dataDict['size'] = size
try:
start = string.atoi(dataDict.get('start','1'))
except:
start = 1
REQUEST.set('start',start)
dataDict['start'] = start
REQUEST.set('HEC_Setup',1)
--- NEW FILE: zapp_cmf_object_edit.py ---
## Script (Python) "question_edit"
dict = {}
dict.update(context.REQUEST.form)
submitValue = context.REQUEST.get('submit','')
if submitValue == 'add row':
propName = context.REQUEST.get('propToChange','')
if propName:
currVal = context.REQUEST.get(propName, [])
currVal += [{}]
elif submitValue == 'delete row':
propName = context.REQUEST.get('propToChange','')
if propName:
currVal = context.REQUEST.get(propName, [])
if currVal:
currVal = currVal[:-1]
context.safeMiscData.setXMLAttrs(dict = dict)
context.REQUEST.RESPONSE.redirect('zapp_cmf_object_edit_form')
--- NEW FILE: zapp_cmf_object_edit_form.pt ---
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="here/main_template/macros/master">
<metal:block fill-slot="base">
<base href=""
tal:attributes="href python: here.absolute_url() + '/'">
</metal:block>
<body>
<div metal:fill-slot="main">
ZApp CMF Thingy..
<!-- A ZApp CMF property set is a list of objects/dictionaries (stored as 'zapp_properties') in the TypeProperty
each object has several required attributes:
'name': is the name of the property
'type': is it's type simple types like: 'float','int','long','string','date','boolean',
complex types like: 'int:list', (a list of values, the type specified before the ':' is the type of each value),
'record' (a structure or dictionary),
'records' (a list of structures of dictionaries),)
if record or 'records' is used... there is also:
'subObject': which is another propertySet for that record type.
-->
<div tal:define="myApp python:here.findApplication();
myType here/portal_type;
miscDataSpecialist myApp/MiscData;
typePropertiesObjects python:miscDataSpecialist.ZApp_getItems(Manager='CMFThings', objectID='metaObject', dataType='ZCMFPropsFor' + myType);
myTPropsMiscData python:typePropertiesObjects and typePropertiesObjects[0].getXMLDict();
myPropSet myTPropsMiscData/zapp_properties | nothing;
myProperties python:here.safeMiscData.getXMLDict()">
<table tal:condition="myPropSet">
<form action="zapp_cmf_object_edit" method="post">
<tr tal:repeat="propDef myPropSet">
<td tal:define="propName propDef/name;
propType propDef/type;
subObject propDef/subObject | python:[];
subDefs subObject/zapp_properties | python:[];
propValue python:myProperties.get(propName,'')">
<table tal:condition="python:propType in ['float','int','long','string','date']">
<tr><td tal:content="string:${propName}(${propType})"/><td><input tal:attributes="name string:${propName}:${propType}; value propValue"></td></tr>
</table>
<table tal:condition="python:propType in ['text']">
<tr><td tal:content="string:${propName}(${propType})"/><td><textarea tal:content="propValue" tal:attributes="name string:${propName}" rows="5" cols="40"/></td></tr>
</table>
<table tal:condition="python:propType in ['boolean']">
<tr><td tal:content="string:${propName}(${propType})"/><td><input type="checkbox" value="1" tal:attributes="name string:${propName}:int; checked propValue"></td></tr>
</table>
<table tal:condition="python:('list' in propType.split(':')) and propValue">
<tr tal:repeat="item propValue" tal:define="propType python:propType.split(':')[0]">
<td tal:content="python:'Item ' + path('item/repeat/index') + 1" />
<td><input tal:attributes="name string:${propName}:${propType}:list; value item"/></td>
</tr>
</table>
<table border="1" tal:condition="python:subObject and (propType=='record')">
<tr><td colspan="2" tal:content="string:${propName} --- structure/object"/></tr>
<tr tal:repeat="propDef subDefs">
<tal:block tal:omit-tag=""
tal:define="subPropName propDef/name;
propType propDef/type;
propValue python:propValue and propValue.get(subPropName,'')">
<td tal:content="string:${subPropName}(${propType})"/>
<td><input tal:condition="python:propType not in ['boolean','text']" tal:attributes="name string:${propName}.${subPropName}:${propType}:record; value propValue">
<textarea tal:condition="python:propType in ['text']" tal:content="propValue" tal:attributes="name string:${propName}.${subPropName}:record;" rows="5" cols="40"/>
<input tal:condition="python:propType in ['boolean']" type="checkbox" value="1" tal:attributes="name string:${propName}.${subPropName}:int:record; checked propValue">
</td>
</tal:block>
</tr>
</table>
<table tal:condition="python:subObject and (propType=='records')">
<tr>
<td><input type="radio" name="propToChange" tal:attributes="value string:${propName}"></td>
<td tal:repeat="subDef subDefs"><span tal:content="string:${subDef/name}(${subDef/type})"/></td>
</tr>
<tr tal:repeat="currItem python:propValue or [{}]"><td> </td>
<td tal:repeat="propDef subDefs"><span tal:omit-tag="" tal:define="subPropName propDef/name;
subpropType propDef/type;
currVal python:currItem.get(subPropName,'')">
<input tal:condition="python:subpropType in ['float','int','long','string','date']" tal:attributes="name string:${propName}.${subPropName}:records; value currVal">
<input tal:condition="python:subpropType in ['boolean']" type="checkbox" value="1" tal:attributes="name string:${propName}.${subPropName}:int:records; checked currVal">
<textarea tal:condition="python:subpropType in ['text']" tal:content="currVal" tal:attributes="name string:${propName}.${subPropName}:records;" rows="5" cols="40"/>
</span>
</td>
</tr>
</table>
</td></tr>
<tr><td><input name="submit" type="submit" value="edit" ><input name="submit" type="submit" value="add row" ><input name="submit" type="submit" value="delete row" ></td></tr>
</form>
</table>
<div tal:condition="not:myPropSet"> Sorry.. there is no propSet for this type! </div>
</div>
</div>
</body>
</html>
--- NEW FILE: zapp_cmf_object_get_info.py ---
# Example code:
return context.safeMiscData.getXMLAttr('questionInfo')
--- NEW FILE: zapp_cmf_object_type_edit.py ---
## Script (Python) "question_edit"
myApp = context.findApplication()
myType = context.portal_type
miscData = myApp.MiscData
tpropObjects = miscData.ZApp_getItems(Manager='CMFThings', objectID='metaObject', dataType='ZCMFPropsFor' + myType)
myTPropsObj = tpropObjects and tpropObjects[0]
myTPropDict = (myTPropsObj and myTPropsObj.getXMLDict()) or {}
myTPropDefs = myTPropDict.get('zapp_properties',[])
inputDict = {}
inputDict.update(context.REQUEST.form) # get a 'real' dictionary object..
result = "original dict = '%s'" % `myTPropDefs`
if inputDict.has_key('submit'):
submitValue = inputDict.get('submit','')
selectedNames = inputDict.get('names',[])
selectedSubNames = inputDict.get('subnames',[])
if (len(selectedNames) and len(selectedSubNames)):
raise RuntimeError, "pick root level items, or subobject items, but not both!"
if submitValue == 'delete property':
if len(selectedNames):
newTPropDefs = []
for item in myTPropDefs:
if item.get('name','') not in selectedNames:
newTPropDefs.append( item )
myTPropDefs = newTPropDefs
elif len(selectedSubNames):
for subName in selectedSubNames:
objName, subName = subName.split(':',1)
for item in myTPropDefs:
if item.get('name','') == objName:
subObject = item.get('subObject',{})
subTPropDefs = subObject.get('zapp_properties',[])
newSubTPropDefs = []
for subitem in subTPropDefs:
if subitem.get('name','') != subName:
newSubTPropDefs.append( subitem )
subObject['zapp_properties'] = newSubTPropDefs
elif submitValue == 'top':
if len(selectedNames):
topList = []
bottomList = []
for item in myTPropDefs:
if item.get('name','') in selectedNames:
topList.append( item )
else:
bottomList.append( item )
myTPropDefs = topList + bottomList
elif len(selectedSubNames):
for subName in selectedSubNames:
objName, subName = subName.split(':',1)
for item in myTPropDefs:
if item.get('name','') == objName:
subObject = item.get('subObject',{})
subTPropDefs = subObject.get('zapp_properties',[])
topList = []
bottomList = []
for subitem in subTPropDefs:
if subitem.get('name','') == subName:
topList.append( subitem )
else:
bottomList.append(subitem)
subObject['zapp_properties'] = topList + bottomList
elif submitValue == 'bottom':
if len(selectedNames):
topList = []
bottomList = []
for item in myTPropDefs:
if item.get('name','') in selectedNames:
bottomList.append( item )
else:
topList.append( item )
myTPropDefs = topList + bottomList
elif len(selectedSubNames):
for subName in selectedSubNames:
objName, subName = subName.split(':',1)
for item in myTPropDefs:
if item.get('name','') == objName:
subObject = item.get('subObject',{})
subTPropDefs = subObject.get('zapp_properties',[])
topList = []
bottomList = []
for subitem in subTPropDefs:
if subitem.get('name','') == subName:
bottomList.append( subitem )
else:
topList.append(subitem)
subObject['zapp_properties'] = topList + bottomList
elif submitValue == 'add new item':
newItem = inputDict.get('newItem')
if newItem.name:
newProp = {'name':newItem.name, 'type':newItem.propType}
if len(selectedNames) == 0:
if newItem.propType in ['record','records']:
newProp[ 'subObject' ] = {}
myTPropDefs.append( newProp )
elif len(selectedNames) == 1:
if newItem.propType in ['record','records']:
raise RuntimeError,"Only simple types allowed in records!"
for item in myTPropDefs:
if item.get('name','') in selectedNames:
subObject = item.get('subObject',{})
subTPropDefs = subObject.get('zapp_properties',[])
subTPropDefs.append( newProp )
subObject['zapp_properties'] = subTPropDefs
break
else:
raise RuntimeError, "You can only add to one record type at a time!"
if not myTPropsObj:
tpropObjects = miscData.ZApp_getItems(Manager='CMFThings', objectID='metaObject', dataType='ZCMFPropsFor' + myType, createIfNone=1)
myTPropsObj = tpropObjects and tpropObjects[0]
if not myTPropsObj:
raise RuntimeError, "Can't create new misc data object!"
myTPropsObj.setXMLAttrs({'zapp_properties': myTPropDefs})
context.REQUEST.RESPONSE.redirect('zapp_cmf_object_type_edit_form')
--- NEW FILE: zapp_cmf_object_type_edit_form.pt ---
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="here/main_template/macros/master">
<metal:block fill-slot="base">
<base href=""
tal:attributes="href python: here.absolute_url() + '/'">
</metal:block>
<body>
<div metal:fill-slot="main">
<script type="text/javascript">
<!--
isSelected = false;
function toggleSelect() {
if (isSelected == false) {
for (i = 0; i < document.objectItems.length; i++)
document.objectItems.elements[i].checked = true ;
isSelected = true;
document.objectItems.selectButton.value = "Deselect All";
return isSelected;
}
else {
for (i = 0; i < document.objectItems.length; i++)
document.objectItems.elements[i].checked = false ;
isSelected = false;
document.objectItems.selectButton.value = "Select All";
return isSelected;
}
}
//-->
</script>
Type for ZApp CMF Thingy..
<!-- A ZApp CMF property set is a list of objects/dictionaries (stored as 'zapp_properties') in the TypeProperty
each object has several required attributes:
'name': is the name of the property
'type': is it's type simple types like: 'float','int','long','string','date','boolean',
complex types like: 'int:list', (a list of values, the type specified before the ':' is the type of each value),
'record' (a structure or dictionary),
'records' (a list of structures of dictionaries),)
if record or 'records' is used... there is also:
'subObject': which is another propertySet for that record type.
-->
<div tal:define="myApp python:here.findApplication();
myType here/portal_type;
miscDataSpecialist myApp/MiscData;
typePropertiesObjects python:miscDataSpecialist.ZApp_getItems(Manager='CMFThings', objectID='metaObject', dataType='ZCMFPropsFor' + myType);
myTPropsMiscData python:typePropertiesObjects and typePropertiesObjects[0].getXMLDict();
myPropSet myTPropsMiscData/zapp_properties | nothing">
<form action="zapp_cmf_object_type_edit" method="post">
<table tal:condition="myPropSet">
<tr tal:repeat="propDef myPropSet">
<td tal:define="propName propDef/name;
propType propDef/type;
subObject propDef/subObject | python:[];
subDefs subObject/zapp_properties | python:[]">
<table tal:condition="python:propType in ['float','int','long','string','date']">
<tr><td><input type="checkbox" name="names:list" tal:attributes="value propName"/></td> <td tal:content="string:${propName}(${propType})"/></tr>
</table>
<table tal:condition="python:('list' in propType.split(':')) and propValue">
<tr><td><input type="checkbox" name="names:list" tal:attributes="value propName"/></td> <td tal:content="string:${propName}(${propType})"/></tr>
</table>
<table tal:condition="python:propType in ['record','records']">
<tr><td><input type="checkbox" name="names:list" tal:attributes="value propName"/></td> <td tal:content="string:${propName}(${propType})"/></tr>
<tr tal:repeat="subDef subDefs"><tal:block tal:omit-tag="" tal:define="subName subDef/name; subType subDef/type">
<td> </td>
<td> <input type="checkbox" name="subnames:list" tal:attributes="value string:${propName}:${subName}"><span tal:content="string:${subName}(${subType})"/></td></tal:block>
</tr>
</table>
</td></tr>
</table>
<hr>
<div>
<table>
<tr>
<td>Name:</td>
<td><input name="newItem.name:record"></td>
<td>
<select name="newItem.propType:record">
<span tal:repeat="item python:['string','text','float','int','long','date','boolean','array','record','records']">
<option tal:attributes="value item" tal:content="item"/>
</span></select> </td>
</tr>
</table>
</div>
<input type="submit" name="submit" value="delete property">
<input type="submit" name="submit" value="top">
<input type="submit" name="submit" value="bottom">
<input type="submit" name="submit" value="add new item">
</form>
</div>
</div>
</body>
</html>
--- NEW FILE: zapp_cmf_object_view.pt ---
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="here/main_template/macros/master">
<metal:block fill-slot="base">
<base href=""
tal:attributes="href python: here.absolute_url() + '/'">
</metal:block>
<body>
<div metal:fill-slot="main">
<div tal:define="myApp python:here.findApplication();
myType here/portal_type;
miscDataSpecialist myApp/MiscData;
typePropertiesObjects python:miscDataSpecialist.ZApp_getItems(Manager='CMFThings', objectID='metaObject', dataType='CMFPropertiesFor' + myType);
myTypePropertiesMiscData python:typePropertiesObjects and typePropertiesObjects[0].getXMLDict();
myProperties python:here.safeMiscData.getXMLDict()">
ZApp CMF Thing.
<div tal:content="myTypePropertiesMiscData"> </div>
<div tal:content="myProperties"> </div>
</div>
</div>
</body>
</html>
--- NEW FILE: zapp_file_edit.py ---
## Script (Python) "hec_image_edit"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# Example code:
file = context.REQUEST.form.get('file','')
portal = context.portal_url.getPortalObject()
if not file:
return "I need a file!"
path = context.getPhysicalPath()
print "I got a ", `file`
fileID = path[-1]
currFolder = portal.fSystem
for folder in path[1:-1]:
if folder in currFolder.objectIds('Folder'):
fsFolder = getattr(currFolder, folder, None)
else:
currFolder.manage_addFolder(folder)
fsFolder = getattr( currFolder, folder, None)
if not fsFolder:
raise RuntimeError, "Can't create folder!"
currFolder = fsFolder
fileObj = getattr(currFolder, fileID, None)
#print "adding ", `fileObj`," with id ", fileObj.id, " image to ", `currFolder`, currFolder.id
if fileObj is None:
currFolder.manage_addFile(id=fileID, file=file)
fileObj = getattr(currFolder, fileID, None)
print "I'm creating a file object.. "
try:
print "I'm trying to upload a file"
fileObj.manage_upload(file)
except:
print "I failed.. by getting a ", `fileObj`
return printed
context.REQUEST.RESPONSE.redirect('view')
--- NEW FILE: zapp_file_edit_form.pt ---
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="here/main_template/macros/master">
<body>
<div metal:fill-slot="main" i18n:domain="cmf_default">
<div class="Desktop">
<span tal:replace="request/message"
tal:condition="request/message|nothing"><hr /></span>
<h2 i18n:translate="">Edit <span
tal:replace="here/getId" i18n:name="objectid">My ID</span></h2>
<form action="hec_file_edit" method="post" enctype="multipart/form-data"
tal:attributes="action string:${here/absolute_url}/hec_file_edit"
>
<table class="FormLayout">
<tr>
<th i18n:translate="">Title</th>
<td> <span tal:replace="here/Title">My Title</span></td>
</tr>
<tr>
<th i18n:translate="">Description</th>
<td> <span tal:replace="here/Description">My Description</span></td>
</tr>
<tr>
<th i18n:translate="">Content type</th>
<td> <span tal:replace="here/Format">html/text</span></td>
</tr>
<tr>
<th i18n:translate="">Upload file</th>
<td> <input type="file" name="file" size="35" /> </td>
</tr>
<tr>
<td> <br /> </td>
<td>
<input type="submit" name="change" value=" Change "
i18n:attributes="value" />
<input type="submit" name="change_and_view" value=" Change and View "
i18n:attributes="value" />
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
--- NEW FILE: zapp_file_view.pt ---
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="here/main_template/macros/master">
<metal:block fill-slot="base">
<base href=""
tal:attributes="href python: here.absolute_url() + '/'">
</metal:block>
<body>
<div metal:fill-slot="header">
<h1 id="DesktopTitle"
tal:content="here/Title">Document Title</h1>
<div id="DesktopDescription" tal:content="here/Description">
Document Description goes here.
</div>
<div metal:use-macro="here/content_byline/macros/byline">By Me</div>
</div>
<div metal:fill-slot="main" i18n:domain="cmf_default">
<h2 i18n:translate=""> File Properties </h2>
<table tal:define="theFile here/hec_image_get_fileObj">
<tr>
<th align="right" i18n:translate="">Filename</th>
<td tal:content="theFile/getId">My ID</td>
</tr>
<tr>
<th align="right" i18n:translate="">Size</th>
<td tal:content="theFile/size">1024K</td>
</tr>
<tr>
<th align="right" i18n:translate="">Content-type</th>
<td tal:content="theFile/content_type">application/gzip</td>
<tr>
<tr>
<td> <br /> </td>
<td>
</td>
</tr>
</table>
<h2 i18n:translate="">Download File</h2>
<p> <a href="." title="Download File"
tal:define="file here/absolute_url"
tal:attributes="href file; title here/Title"
tal:content="string:Download ${here/Title}">Download File</a>
</p>
<div class="Discussion">
<span tal:replace="structure here/viewThreadsAtBottom"
tal:condition="here/viewThreadsAtBottom|nothing"></span>
</div>
</div>
</body>
</html>
--- NEW FILE: zapp_get_fileObj.py ---
portal = context.portal_url.getPortalObject()
path = context.getPhysicalPath()
fileID = path[-1]
currFolder = portal.fSystem
for folder in path[1:-1]:
if folder in currFolder.objectIds('Folder'):
fsFolder = getattr(currFolder, folder, None)
if not fsFolder:
raise RuntimeError, "Can't find folder!" + folder
currFolder = fsFolder
return getattr(currFolder, fileID, None)
--- NEW FILE: zapp_image_edit.py ---
## Script (Python) "hec_image_edit"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# Example code:
file = context.REQUEST.form.get('file','')
portal = context.portal_url.getPortalObject()
if not file:
return "I need a file!"
path = context.getPhysicalPath()
print "I got a ", `file`
fileID = path[-1]
currFolder = portal.fSystem
for folder in path[1:-1]:
if folder in currFolder.objectIds('Folder'):
fsFolder = getattr(currFolder, folder, None)
else:
currFolder.manage_addFolder(folder)
fsFolder = getattr( currFolder, folder, None)
if not fsFolder:
raise RuntimeError, "Can't create folder!"
currFolder = fsFolder
fileObj = getattr(currFolder, fileID, None)
#print "adding ", `fileObj`," with id ", fileObj.id, " image to ", `currFolder`, currFolder.id
if fileObj is None:
currFolder.manage_addImage(id=fileID, file=file)
fileObj = getattr(currFolder, fileID, None)
print "I'm creating a file object.. "
try:
print "I'm trying to upload a file"
fileObj.manage_upload(file)
except:
print "I failed.. by getting a ", `fileObj`
return printed
context.REQUEST.RESPONSE.redirect('view')
--- NEW FILE: zapp_image_edit_form.pt ---
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="here/main_template/macros/master">
<body>
<div metal:fill-slot="main" i18n:domain="cmf_default">
<div class="Desktop">
<span tal:replace="request/message"
tal:condition="request/message|nothing"><hr /></span>
<div class="Image">
<h2 i18n:translate="">Edit <span
tal:replace="here/getId" i18n:name="objectid">My ID</span></h2>
<form action="hec_image_edit" method="post" enctype="multipart/form-data"
tal:attributes="action string:${here/absolute_url}/hec_image_edit"
>
<table class="FormLayout">
<tr>
<th i18n:translate="">Title</th>
<td> <span tal:replace="here/Title">My Title</span> </td>
</tr>
<tr>
<th i18n:translate="">Description</th>
<td> <span tal:replace="here/Description">My Description</span> </td>
</tr>
<tr>
<th i18n:translate="">Content type</th>
<td> <span tal:replace="here/Format">text/html</span> </td>
</tr>
<tr>
<th i18n:translate="">Upload image</th>
<td> <input type="file" name="file" size="25" /> </td>
</tr>
<tr>
<td> <br /> </td>
<td>
<input type="submit" name="change" value=" Change "
i18n:attributes="value" />
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
</body>
</html>
--- NEW FILE: zapp_image_view.pt ---
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="here/main_template/macros/master">
<metal:block fill-slot="base">
<base href=""
tal:attributes="href python: here.absolute_url() + '/'">
</metal:block>
<body>
<div metal:fill-slot="header">
<h1 id="DesktopTitle"
tal:content="here/Title">Document Title</h1>
<div id="DesktopDescription" tal:content="here/Description">
Document Description goes here.
</div>
<div metal:use-macro="here/content_byline/macros/byline">By Me</div>
</div>
<div metal:fill-slot="main">
<img tal:attributes="src python:here.hec_image_get_fileObj().absolute_url()"/>
<div class="Discussion">
<span tal:replace="structure here/viewThreadsAtBottom"
tal:condition="here/viewThreadsAtBottom|nothing"></span>
</div>
</div>
</body>
</html>
|