| 1 | ################################################################################
|
|---|
| 2 | # _filtermanager.py
|
|---|
| 3 | #
|
|---|
| 4 | # This program is free software; you can redistribute it and/or
|
|---|
| 5 | # modify it under the terms of the GNU General Public License
|
|---|
| 6 | # as published by the Free Software Foundation; either version 2
|
|---|
| 7 | # of the License, or (at your option) any later version.
|
|---|
| 8 | #
|
|---|
| 9 | # This program is distributed in the hope that it will be useful,
|
|---|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | # GNU General Public License for more details.
|
|---|
| 13 | #
|
|---|
| 14 | # You should have received a copy of the GNU General Public License
|
|---|
| 15 | # along with this program; if not, write to the Free Software
|
|---|
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 17 | ################################################################################
|
|---|
| 18 |
|
|---|
| 19 | # Imports.
|
|---|
| 20 | from App.Common import package_home
|
|---|
| 21 | from App.special_dtml import HTMLFile
|
|---|
| 22 | from Products.ExternalMethod import ExternalMethod
|
|---|
| 23 | from Products.PageTemplates import ZopePageTemplate
|
|---|
| 24 | from Products.PythonScripts import PythonScript
|
|---|
| 25 | import ZPublisher.HTTPRequest
|
|---|
| 26 | import copy
|
|---|
| 27 | import os
|
|---|
| 28 | import tempfile
|
|---|
| 29 | import time
|
|---|
| 30 | import urllib
|
|---|
| 31 | import zExceptions
|
|---|
| 32 | # Product Imports.
|
|---|
| 33 | import _blobfields
|
|---|
| 34 | import _fileutil
|
|---|
| 35 | import _globals
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | ################################################################################
|
|---|
| 39 | #
|
|---|
| 40 | # XML IM/EXPORT
|
|---|
| 41 | #
|
|---|
| 42 | ################################################################################
|
|---|
| 43 |
|
|---|
| 44 | # ------------------------------------------------------------------------------
|
|---|
| 45 | # importXml
|
|---|
| 46 | # ------------------------------------------------------------------------------
|
|---|
| 47 |
|
|---|
| 48 | def _importXml(self, item, zms_system=0, createIfNotExists=1):
|
|---|
| 49 | itemType = item.get('type')
|
|---|
| 50 | itemOb = item.get('value')
|
|---|
| 51 | if itemType == 'filter':
|
|---|
| 52 | newId = itemOb.get('id')
|
|---|
| 53 | newAcquired = 0
|
|---|
| 54 | newName = itemOb.get('name')
|
|---|
| 55 | newFormat = itemOb.get('format')
|
|---|
| 56 | newContentType = itemOb.get('content_type')
|
|---|
| 57 | newDescription = itemOb.get('description','')
|
|---|
| 58 | newRoles = itemOb.get('roles',[])
|
|---|
| 59 | newMetaTypes = itemOb.get('meta_types',[])
|
|---|
| 60 | filters = getRawFilters(self)
|
|---|
| 61 | ids = filters.keys()
|
|---|
| 62 | ids = filter( lambda x: filters[x].get('zms_system',0)==1, ids)
|
|---|
| 63 | if createIfNotExists == 1 or newId in ids:
|
|---|
| 64 | delFilter(self, newId)
|
|---|
| 65 | setFilter(self, newId, newAcquired, newName, newFormat, newContentType, newDescription, newRoles, newMetaTypes, zms_system)
|
|---|
| 66 | for process in itemOb.get('processes',[]):
|
|---|
| 67 | newProcessId = process.get('id')
|
|---|
| 68 | newProcessFile = process.get('file')
|
|---|
| 69 | setFilterProcess(self, newId, newProcessId, newProcessFile)
|
|---|
| 70 | elif itemType == 'process':
|
|---|
| 71 | newId = itemOb.get('id')
|
|---|
| 72 | newAcquired = 0
|
|---|
| 73 | newName = itemOb.get('name')
|
|---|
| 74 | newType = itemOb.get('type','process')
|
|---|
| 75 | newCommand = itemOb.get('command')
|
|---|
| 76 | processes = getRawProcesses(self)
|
|---|
| 77 | ids = processes.keys()
|
|---|
| 78 | ids = filter( lambda x: processes[x].get('zms_system',0)==1, ids)
|
|---|
| 79 | if createIfNotExists == 1 or newId in ids:
|
|---|
| 80 | delProcess(self, newId)
|
|---|
| 81 | setProcess(self, newId, newAcquired, newName, newType, newCommand, zms_system)
|
|---|
| 82 | else:
|
|---|
| 83 | _globals.writeError(self,"[_importXml]: Unknown type >%s<"%itemType)
|
|---|
| 84 |
|
|---|
| 85 | def importXml(self, xml, REQUEST=None, zms_system=0, createIfNotExists=1):
|
|---|
| 86 | v = self.parseXmlString(xml)
|
|---|
| 87 | if type(v) is list:
|
|---|
| 88 | for item in v:
|
|---|
| 89 | id = _importXml(self,item,zms_system,createIfNotExists)
|
|---|
| 90 | else:
|
|---|
| 91 | id = _importXml(self,v,zms_system,createIfNotExists)
|
|---|
| 92 |
|
|---|
| 93 | # ------------------------------------------------------------------------------
|
|---|
| 94 | # exportXml
|
|---|
| 95 | # ------------------------------------------------------------------------------
|
|---|
| 96 | def exportXml(self, REQUEST, RESPONSE):
|
|---|
| 97 | value = []
|
|---|
| 98 | ids = REQUEST.get('ids',[])
|
|---|
| 99 | for id in self.getFilterIds():
|
|---|
| 100 | if id in ids or len(ids) == 0:
|
|---|
| 101 | ob = self.getFilter(id).copy()
|
|---|
| 102 | if ob.has_key('zms_system'):
|
|---|
| 103 | del ob['zms_system']
|
|---|
| 104 | value.append({'type':'filter','value':ob})
|
|---|
| 105 | for id in self.getProcessIds():
|
|---|
| 106 | if id in ids or len(ids) == 0:
|
|---|
| 107 | ob = self.getProcess(id).copy()
|
|---|
| 108 | if ob.has_key('zms_system'):
|
|---|
| 109 | del ob['zms_system']
|
|---|
| 110 | value.append({'type':'process','value':ob})
|
|---|
| 111 | # XML.
|
|---|
| 112 | if len(value)==1:
|
|---|
| 113 | value = value[0]
|
|---|
| 114 | content_type = 'text/xml; charset=utf-8'
|
|---|
| 115 | filename = 'export.filter.xml'
|
|---|
| 116 | export = self.getXmlHeader() + self.toXmlString(value,1)
|
|---|
| 117 | RESPONSE.setHeader('Content-Type',content_type)
|
|---|
| 118 | RESPONSE.setHeader('Content-Disposition','inline;filename="%s"'%filename)
|
|---|
| 119 | return export
|
|---|
| 120 |
|
|---|
| 121 | """
|
|---|
| 122 | ################################################################################
|
|---|
| 123 | #
|
|---|
| 124 | # P R O C E S S E S
|
|---|
| 125 | #
|
|---|
| 126 | ################################################################################
|
|---|
| 127 | """
|
|---|
| 128 |
|
|---|
| 129 | # ------------------------------------------------------------------------------
|
|---|
| 130 | # _filtermanager.getRawProcesses:
|
|---|
| 131 | #
|
|---|
| 132 | # Returns raw dictionary of processes.
|
|---|
| 133 | # ------------------------------------------------------------------------------
|
|---|
| 134 | def getRawProcesses(self):
|
|---|
| 135 | # Return attribute.
|
|---|
| 136 | return self.getConfProperty('ZMS.filter.processes',{})
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 | # ------------------------------------------------------------------------------
|
|---|
| 140 | # _filtermanager.setProcess:
|
|---|
| 141 | #
|
|---|
| 142 | # Set/add process specified by given Id.
|
|---|
| 143 | # ------------------------------------------------------------------------------
|
|---|
| 144 | def setProcess(self, newId, newAcquired=0, newName='', newType='process', newCommand=None, zms_system=0):
|
|---|
| 145 | if newCommand is None:
|
|---|
| 146 | newCommand = ''
|
|---|
| 147 | if newType in [ 'DTML Method']:
|
|---|
| 148 | newCommand += '<dtml-comment>--// BO '+ newId + ' //--</dtml-comment>\n'
|
|---|
| 149 | newCommand += '\n'
|
|---|
| 150 | newCommand += '<dtml-comment>--// EO '+ newId + ' //--</dtml-comment>\n'
|
|---|
| 151 | elif newType in [ 'Script (Python)']:
|
|---|
| 152 | newCommand += '# --// BO '+ newId + ' //--\n'
|
|---|
| 153 | newCommand += '# Example code:\n'
|
|---|
| 154 | newCommand += '\n'
|
|---|
| 155 | newCommand += '# Import a standard function, and get the HTML request and response objects.\n'
|
|---|
| 156 | newCommand += 'from Products.PythonScripts.standard import html_quote\n'
|
|---|
| 157 | newCommand += 'request = container.REQUEST\n'
|
|---|
| 158 | newCommand += 'RESPONSE = request.RESPONSE\n'
|
|---|
| 159 | newCommand += '\n'
|
|---|
| 160 | newCommand += '# Return a string identifying this script.\n'
|
|---|
| 161 | newCommand += 'print "This is the", script.meta_type, \'"%s"\' % script.getId(),\n'
|
|---|
| 162 | newCommand += 'if script.title:\n'
|
|---|
| 163 | newCommand += ' print "(%s)" % html_quote(script.title),\n'
|
|---|
| 164 | newCommand += 'print "in", container.absolute_url()\n'
|
|---|
| 165 | newCommand += 'return printed\n'
|
|---|
| 166 | newCommand += '\n'
|
|---|
| 167 | newCommand += '# --// EO '+ newId + ' //--\n'
|
|---|
| 168 | # Set method.
|
|---|
| 169 | container = self.getHome()
|
|---|
| 170 | if newType in [ 'DTML Method']:
|
|---|
| 171 | if newId not in container.objectIds([newType]):
|
|---|
| 172 | container.manage_addDTMLMethod( newId, newName, newCommand)
|
|---|
| 173 | newOb = getattr( container, newId)
|
|---|
| 174 | newOb.manage_edit( title=newName, data=newCommand)
|
|---|
| 175 | roles=[ 'Manager']
|
|---|
| 176 | newOb._proxy_roles=tuple(roles)
|
|---|
| 177 | elif newType in [ 'Script (Python)']:
|
|---|
| 178 | if newId not in container.objectIds([newType]):
|
|---|
| 179 | PythonScript.manage_addPythonScript( container, newId)
|
|---|
| 180 | newOb = getattr( container, newId)
|
|---|
| 181 | newOb.ZPythonScript_setTitle( newName)
|
|---|
| 182 | newOb.write(newCommand)
|
|---|
| 183 | roles=[ 'Manager']
|
|---|
| 184 | newOb._proxy_roles=tuple(roles)
|
|---|
| 185 | # Set.
|
|---|
| 186 | obs = getRawProcesses(self)
|
|---|
| 187 | ob = {}
|
|---|
| 188 | ob['acquired'] = newAcquired
|
|---|
| 189 | ob['name'] = newName
|
|---|
| 190 | ob['type'] = newType
|
|---|
| 191 | ob['command'] = newCommand
|
|---|
| 192 | ob['zms_system'] = zms_system
|
|---|
| 193 | obs[newId] = ob
|
|---|
| 194 | # Set attribute.
|
|---|
| 195 | self.setConfProperty('ZMS.filter.processes',obs.copy())
|
|---|
| 196 | # Return with new id.
|
|---|
| 197 | return newId
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 | # ------------------------------------------------------------------------------
|
|---|
| 201 | # _filtermanager.delProcess:
|
|---|
| 202 | #
|
|---|
| 203 | # Delete process specified by given Id.
|
|---|
| 204 | # ------------------------------------------------------------------------------
|
|---|
| 205 | def delProcess(self, id):
|
|---|
| 206 | # Delete.
|
|---|
| 207 | cp = getRawProcesses(self)
|
|---|
| 208 | obs = {}
|
|---|
| 209 | for key in cp.keys():
|
|---|
| 210 | if key == id:
|
|---|
| 211 | # Delete method.
|
|---|
| 212 | if cp[key].get('type','') in [ 'DTML Method', 'External Method', 'Script (Python)']:
|
|---|
| 213 | container = self.getHome()
|
|---|
| 214 | dtml_method = getattr( container, id, None)
|
|---|
| 215 | if dtml_method is not None:
|
|---|
| 216 | container.manage_delObjects( ids=[id])
|
|---|
| 217 | else:
|
|---|
| 218 | obs[key] = cp[key]
|
|---|
| 219 | # Set attribute.
|
|---|
| 220 | self.setConfProperty('ZMS.filter.processes',obs.copy())
|
|---|
| 221 | # Return with empty id.
|
|---|
| 222 | return ''
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 | """
|
|---|
| 226 | ################################################################################
|
|---|
| 227 | #
|
|---|
| 228 | # F I L T E R S
|
|---|
| 229 | #
|
|---|
| 230 | ################################################################################
|
|---|
| 231 | """
|
|---|
| 232 |
|
|---|
| 233 | # ------------------------------------------------------------------------------
|
|---|
| 234 | # _filtermanager.getRawFilters:
|
|---|
| 235 | #
|
|---|
| 236 | # Returns raw dictionary of filters.
|
|---|
| 237 | # ------------------------------------------------------------------------------
|
|---|
| 238 | def getRawFilters(self):
|
|---|
| 239 | # Return attribute.
|
|---|
| 240 | raw = self.getConfProperty('ZMS.filter.filters',{})
|
|---|
| 241 | for key in raw.keys():
|
|---|
| 242 | f = raw[ key]
|
|---|
| 243 | processes = f.get( 'processes', [])
|
|---|
| 244 | processes = filter( lambda x: x['id'] is not None, processes)
|
|---|
| 245 | f[ 'processes'] = processes
|
|---|
| 246 | return raw
|
|---|
| 247 |
|
|---|
| 248 | # ------------------------------------------------------------------------------
|
|---|
| 249 | # _filtermanager.setFilter:
|
|---|
| 250 | #
|
|---|
| 251 | # Set/add filter specified by given Id.
|
|---|
| 252 | # ------------------------------------------------------------------------------
|
|---|
| 253 | def setFilter(self, newId, newAcquired=0, newName='', newFormat='', newContentType='', newDescription='', newRoles=[], newMetaTypes=[], zms_system=0):
|
|---|
| 254 | # Set.
|
|---|
| 255 | obs = getRawFilters(self)
|
|---|
| 256 | ob = {}
|
|---|
| 257 | ob['acquired'] = newAcquired
|
|---|
| 258 | ob['name'] = newName
|
|---|
| 259 | ob['format'] = newFormat
|
|---|
| 260 | ob['content_type'] = newContentType
|
|---|
| 261 | ob['description'] = newDescription
|
|---|
| 262 | ob['roles'] = newRoles
|
|---|
| 263 | ob['meta_types'] = newMetaTypes
|
|---|
| 264 | ob['zms_system'] = zms_system
|
|---|
| 265 | obs[newId] = ob
|
|---|
| 266 | # Set attribute.
|
|---|
| 267 | self.setConfProperty('ZMS.filter.filters',obs.copy())
|
|---|
| 268 | # Return with new id.
|
|---|
| 269 | return newId
|
|---|
| 270 |
|
|---|
| 271 | # ------------------------------------------------------------------------------
|
|---|
| 272 | # _filtermanager.delFilter:
|
|---|
| 273 | #
|
|---|
| 274 | # Delete filter specified by given Id.
|
|---|
| 275 | # ------------------------------------------------------------------------------
|
|---|
| 276 | def delFilter(self, id):
|
|---|
| 277 | # Delete.
|
|---|
| 278 | cp = getRawFilters(self)
|
|---|
| 279 | obs = {}
|
|---|
| 280 | for key in cp.keys():
|
|---|
| 281 | if key != id:
|
|---|
| 282 | obs[key] = cp[key]
|
|---|
| 283 | # Set attribute.
|
|---|
| 284 | self.setConfProperty('ZMS.filter.filters',obs.copy())
|
|---|
| 285 | # Return with empty id.
|
|---|
| 286 | return ''
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 | """
|
|---|
| 290 | ################################################################################
|
|---|
| 291 | #
|
|---|
| 292 | # F I L T E R - P R O C E S S E S
|
|---|
| 293 | #
|
|---|
| 294 | ################################################################################
|
|---|
| 295 | """
|
|---|
| 296 |
|
|---|
| 297 | # ------------------------------------------------------------------------------
|
|---|
| 298 | # _filtermanager.setFilterProcess:
|
|---|
| 299 | #
|
|---|
| 300 | # Set/add filter-process specified by given id.
|
|---|
| 301 | # ------------------------------------------------------------------------------
|
|---|
| 302 | def setFilterProcess(self, id, newProcessId, newProcessFile=None):
|
|---|
| 303 | # Set.
|
|---|
| 304 | obs = getRawFilters(self)
|
|---|
| 305 | ob = {}
|
|---|
| 306 | ob['id'] = newProcessId
|
|---|
| 307 | ob['file'] = newProcessFile
|
|---|
| 308 | pobs = obs[id].get('processes',[])
|
|---|
| 309 | pobs.append(ob)
|
|---|
| 310 | obs[id]['processes'] = pobs
|
|---|
| 311 | # Set attribute.
|
|---|
| 312 | self.setConfProperty('ZMS.filter.filters',obs.copy())
|
|---|
| 313 | # Return with new id.
|
|---|
| 314 | return len(pobs)-1
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 | # ------------------------------------------------------------------------------
|
|---|
| 318 | # _filtermanager.delFilterProcess:
|
|---|
| 319 | #
|
|---|
| 320 | # Delete filter-process specified by given Ids.
|
|---|
| 321 | # ------------------------------------------------------------------------------
|
|---|
| 322 | def delFilterProcess(self, id, pid):
|
|---|
| 323 | # Delete.
|
|---|
| 324 | obs = getRawFilters(self)
|
|---|
| 325 | pobs = obs[ id].get('processes',[])
|
|---|
| 326 | ob = pobs[ pid]
|
|---|
| 327 | pobs.remove( pobs[pid])
|
|---|
| 328 | obs[id]['processes'] = pobs
|
|---|
| 329 | # Set attribute.
|
|---|
| 330 | self.setConfProperty('ZMS.filter.filters',obs.copy())
|
|---|
| 331 | # Return with empty id.
|
|---|
| 332 | return -1
|
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 | # ------------------------------------------------------------------------------
|
|---|
| 336 | # _filtermanager.moveFilterProcess:
|
|---|
| 337 | #
|
|---|
| 338 | # Move filter-process specified by given Ids to specified position.
|
|---|
| 339 | # ------------------------------------------------------------------------------
|
|---|
| 340 | def moveFilterProcess(self, id, pid, pos):
|
|---|
| 341 | _globals.writeLog( self, '[moveFilterProcess]:id=%s; pid=%s; dir=%s'%(id,str(pid),str(dir)))
|
|---|
| 342 | # Set.
|
|---|
| 343 | obs = getRawFilters(self)
|
|---|
| 344 | pobs = obs[id].get('processes',[])
|
|---|
| 345 | ob = pobs[pid]
|
|---|
| 346 | pobs.remove(ob)
|
|---|
| 347 | pobs.insert(pos,ob)
|
|---|
| 348 | obs[id]['processes'] = pobs
|
|---|
| 349 | # Set attribute.
|
|---|
| 350 | self.setConfProperty('ZMS.filter.filters',obs.copy())
|
|---|
| 351 | # Return with new id.
|
|---|
| 352 | return pos
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 | """
|
|---|
| 356 | ################################################################################
|
|---|
| 357 | #
|
|---|
| 358 | # I M / E X P O R T
|
|---|
| 359 | #
|
|---|
| 360 | ################################################################################
|
|---|
| 361 | """
|
|---|
| 362 |
|
|---|
| 363 | # ------------------------------------------------------------------------------
|
|---|
| 364 | # _filtermanager.processData:
|
|---|
| 365 | #
|
|---|
| 366 | # Process data with custom transformation.
|
|---|
| 367 | # ------------------------------------------------------------------------------
|
|---|
| 368 | def processData(self, processId, data, trans=None):
|
|---|
| 369 | # Create temporary folder.
|
|---|
| 370 | folder = tempfile.mktemp()
|
|---|
| 371 | # Save data to file.
|
|---|
| 372 | filename = _fileutil.getOSPath('%s/in.dat'%folder)
|
|---|
| 373 | _fileutil.exportObj(data, filename)
|
|---|
| 374 | # Save transformation to file.
|
|---|
| 375 | if trans is not None and trans != '':
|
|---|
| 376 | transfilename = _fileutil.getOSPath('%s/%s'%(folder,trans.getFilename()))
|
|---|
| 377 | _fileutil.exportObj(trans, transfilename)
|
|---|
| 378 | # Process file.
|
|---|
| 379 | filename = processFile(self, processId, filename, trans)
|
|---|
| 380 | # Read data from file.
|
|---|
| 381 | f = open(filename, 'rb')
|
|---|
| 382 | data = f.read()
|
|---|
| 383 | f.close()
|
|---|
| 384 | # Remove temporary folder.
|
|---|
| 385 | if not _globals.debug( self):
|
|---|
| 386 | _fileutil.remove(folder, deep=1)
|
|---|
| 387 | # Return data.
|
|---|
| 388 | return data
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 | # ------------------------------------------------------------------------------
|
|---|
| 392 | # _filtermanager.processMethod:
|
|---|
| 393 | #
|
|---|
| 394 | # Process DTML method.
|
|---|
| 395 | # ------------------------------------------------------------------------------
|
|---|
| 396 | def processMethod(self, processId, filename, trans, REQUEST):
|
|---|
| 397 | _globals.writeLog( self, '[processMethod]: processId=%s'%processId)
|
|---|
| 398 | infilename = filename
|
|---|
| 399 | outfilename = filename
|
|---|
| 400 | REQUEST.set( 'ZMS_FILTER_IN', infilename)
|
|---|
| 401 | REQUEST.set( 'ZMS_FILTER_OUT', outfilename)
|
|---|
| 402 | REQUEST.set( 'ZMS_FILTER_TRANS', trans)
|
|---|
| 403 | REQUEST.set( 'ZMS_FILTER_CUR_DIR', _fileutil.getFilePath(infilename))
|
|---|
| 404 | try:
|
|---|
| 405 | value = getattr( self, processId)( self, REQUEST)
|
|---|
| 406 | except:
|
|---|
| 407 | value = _globals.writeError( self, '[processMethod]: processId=%s'%processId)
|
|---|
| 408 | outfilename = REQUEST.get( 'ZMS_FILTER_OUT')
|
|---|
| 409 | # Return filename.
|
|---|
| 410 | return outfilename
|
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 | # ------------------------------------------------------------------------------
|
|---|
| 414 | # _filtermanager.processCommand:
|
|---|
| 415 | #
|
|---|
| 416 | # Process file with command.
|
|---|
| 417 | # ------------------------------------------------------------------------------
|
|---|
| 418 | def processCommand(self, filename, command):
|
|---|
| 419 | _globals.writeLog( self, '[processCommand]: infilename=%s'%filename)
|
|---|
| 420 | infilename = _fileutil.getOSPath( filename)
|
|---|
| 421 | outfilename = _fileutil.getOSPath( filename)
|
|---|
| 422 | mZmsHome = '{zms_home}'
|
|---|
| 423 | mCurDir = '{cur_dir}'
|
|---|
| 424 | mIn = '{in}'
|
|---|
| 425 | mOut = '{out}'
|
|---|
| 426 | i = command.find(mOut[:-1])
|
|---|
| 427 | if i >= 0:
|
|---|
| 428 | j = command.find('}',i)
|
|---|
| 429 | mExt = command[i+len(mOut[:-1]):j]
|
|---|
| 430 | mOut = command[i:j+1]
|
|---|
| 431 | if len(mExt) > 0:
|
|---|
| 432 | outfilename = outfilename[:outfilename.rfind('.')] + mExt
|
|---|
| 433 | else:
|
|---|
| 434 | outfilename += '.tmp'
|
|---|
| 435 | tmpoutfilename = outfilename + '~'
|
|---|
| 436 | instance_home = INSTANCE_HOME
|
|---|
| 437 | software_home = os.path.join(SOFTWARE_HOME, '..%s..' % os.sep)
|
|---|
| 438 | software_home = os.path.normpath(software_home)
|
|---|
| 439 | command = command.replace( '{software_home}', software_home)
|
|---|
| 440 | command = command.replace( '{instance_home}', instance_home)
|
|---|
| 441 | command = command.replace( mZmsHome,_fileutil.getOSPath(package_home(globals())))
|
|---|
| 442 | command = command.replace( mCurDir,_fileutil.getFilePath(infilename))
|
|---|
| 443 | command = command.replace( mIn,infilename)
|
|---|
| 444 | command = command.replace( mOut,tmpoutfilename)
|
|---|
| 445 | _globals.writeLog( self, '[processCommand]: command=%s'%command)
|
|---|
| 446 | os.system(command)
|
|---|
| 447 | # Check if output file exists.
|
|---|
| 448 | try:
|
|---|
| 449 | os.stat( _fileutil.getOSPath( tmpoutfilename))
|
|---|
| 450 | _globals.writeLog( self, '[processCommand]: rename %s to %s'%( tmpoutfilename, outfilename))
|
|---|
| 451 | try:
|
|---|
| 452 | os.remove( outfilename)
|
|---|
| 453 | except OSError:
|
|---|
| 454 | pass
|
|---|
| 455 | os.rename( tmpoutfilename, outfilename)
|
|---|
| 456 | except OSError:
|
|---|
| 457 | outfilename = infilename
|
|---|
| 458 | # Remove input file if it is the result of a transformation of output file.
|
|---|
| 459 | if outfilename != infilename:
|
|---|
| 460 | os.remove( infilename)
|
|---|
| 461 | # Return filename.
|
|---|
| 462 | _globals.writeLog( self, '[processCommand]: outfilename=%s'%( outfilename))
|
|---|
| 463 | return outfilename
|
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 | # ------------------------------------------------------------------------------
|
|---|
| 467 | # _filtermanager.processFile:
|
|---|
| 468 | #
|
|---|
| 469 | # Process file with custom transformation.
|
|---|
| 470 | # ------------------------------------------------------------------------------
|
|---|
| 471 | def processFile(self, processId, filename, trans=None):
|
|---|
| 472 | _globals.writeLog( self, '[processFile]: processId=%s'%processId)
|
|---|
| 473 | folder = _fileutil.getFilePath(filename)
|
|---|
| 474 | processOb = self.getProcess(processId)
|
|---|
| 475 | command = processOb.get('command')
|
|---|
| 476 | # Save transformation to file.
|
|---|
| 477 | if trans is not None and trans != '':
|
|---|
| 478 | transfilename = '%s/%s'%( folder, trans.getFilename())
|
|---|
| 479 | command = command.replace( '{trans}', transfilename)
|
|---|
| 480 | # Execute command.
|
|---|
| 481 | filename = processCommand(self, filename, command)
|
|---|
| 482 | # Return filename.
|
|---|
| 483 | return filename
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 | # ------------------------------------------------------------------------------
|
|---|
| 487 | # _filtermanager.processFilter:
|
|---|
| 488 | #
|
|---|
| 489 | # Process filter.
|
|---|
| 490 | # ------------------------------------------------------------------------------
|
|---|
| 491 | def processFilter(self, ob_filter, folder, filename, REQUEST):
|
|---|
| 492 | for ob_process in ob_filter.get('processes',[]):
|
|---|
| 493 | filename = self.execProcessFilter( ob_process, folder, filename, REQUEST)
|
|---|
| 494 | # Return filename.
|
|---|
| 495 | return filename
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 | # ------------------------------------------------------------------------------
|
|---|
| 499 | # _filtermanager.importFilter:
|
|---|
| 500 | # ------------------------------------------------------------------------------
|
|---|
| 501 | def importFilter(self, filename, id, REQUEST):
|
|---|
| 502 | ob_filter = self.getFilter(id)
|
|---|
| 503 | folder = _fileutil.getFilePath(filename)
|
|---|
| 504 | # Process filter.
|
|---|
| 505 | filename = processFilter(self, ob_filter, folder, filename, REQUEST)
|
|---|
| 506 | # Return filename.
|
|---|
| 507 | return filename
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 | # ------------------------------------------------------------------------------
|
|---|
| 511 | # _filtermanager.exportFilter:
|
|---|
| 512 | # ------------------------------------------------------------------------------
|
|---|
| 513 | def exportFilter(self, id, REQUEST):
|
|---|
| 514 | # Set local variables.
|
|---|
| 515 | ob_filter = self.getFilter(id)
|
|---|
| 516 | tempfolder, outfilename = self.initExportFilter( id, REQUEST)
|
|---|
| 517 | # Process filter.
|
|---|
| 518 | outfilename = processFilter(self, ob_filter, tempfolder, outfilename, REQUEST)
|
|---|
| 519 | # Return values.
|
|---|
| 520 | content_type = ob_filter.get('content_type','content/unknown')
|
|---|
| 521 | filename = 'exportFilter.%s'%content_type[content_type.find('/')+1:]
|
|---|
| 522 | # Zip File.
|
|---|
| 523 | if content_type == 'application/zip':
|
|---|
| 524 | data = _fileutil.buildZipArchive( outfilename, get_data=True)
|
|---|
| 525 | # Read File.
|
|---|
| 526 | else:
|
|---|
| 527 | _globals.writeLog( self, '[exportFilter]: Read %s'%outfilename)
|
|---|
| 528 | f = open(outfilename, 'rb')
|
|---|
| 529 | data = f.read()
|
|---|
| 530 | f.close()
|
|---|
| 531 | # Remove temporary folder.
|
|---|
| 532 | if not _globals.debug( self):
|
|---|
| 533 | _fileutil.remove( tempfolder, deep=1)
|
|---|
| 534 | # Return.
|
|---|
| 535 | return filename, data, content_type
|
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 | ################################################################################
|
|---|
| 539 | ################################################################################
|
|---|
| 540 | ###
|
|---|
| 541 | ### class FilterItem
|
|---|
| 542 | ###
|
|---|
| 543 | ################################################################################
|
|---|
| 544 | ################################################################################
|
|---|
| 545 | class FilterItem:
|
|---|
| 546 |
|
|---|
| 547 | # --------------------------------------------------------------------------
|
|---|
| 548 | # FilterManager.initExportFilter:
|
|---|
| 549 | # --------------------------------------------------------------------------
|
|---|
| 550 | def initExportFilter(self, id, REQUEST):
|
|---|
| 551 | # Set environment variables.
|
|---|
| 552 | instance_home = INSTANCE_HOME
|
|---|
| 553 | software_home = os.path.join(SOFTWARE_HOME, '..%s..' % os.sep)
|
|---|
| 554 | software_home = os.path.normpath(software_home)
|
|---|
| 555 | REQUEST.set( 'ZMS_FILTER', True)
|
|---|
| 556 | REQUEST.set( 'ZMS_FILTER_SOFTWARE_HOME', software_home)
|
|---|
| 557 | REQUEST.set( 'ZMS_FILTER_INSTANCE_HOME', instance_home)
|
|---|
| 558 | REQUEST.set( 'ZMS_FILTER_PACKAGE_HOME', _fileutil.getOSPath(package_home(globals())))
|
|---|
| 559 | # Set local variables.
|
|---|
| 560 | ob_filter = self.getFilter(id)
|
|---|
| 561 | ob_filter_format = ob_filter.get('format','')
|
|---|
| 562 | incl_embedded = ob_filter_format == 'XML_incl_embedded'
|
|---|
| 563 | # Create temporary folder.
|
|---|
| 564 | tempfolder = tempfile.mktemp()
|
|---|
| 565 | ressources = self.exportRessources( tempfolder, REQUEST, from_zms=ob_filter_format=='XHTML', from_home=ob_filter_format=='XHTML', incl_embedded=incl_embedded)
|
|---|
| 566 | # Export data to file.
|
|---|
| 567 | if ob_filter_format == 'export':
|
|---|
| 568 | outfilename = _fileutil.getOSPath('%s/INDEX0'%tempfolder)
|
|---|
| 569 | elif ob_filter_format in ['XML','XML_incl_embedded']:
|
|---|
| 570 | # Set XML.
|
|---|
| 571 | data = self.toXml( REQUEST, incl_embedded)
|
|---|
| 572 | outfilename = _fileutil.getOSPath('%s/export.xml'%tempfolder)
|
|---|
| 573 | _fileutil.exportObj( data, outfilename)
|
|---|
| 574 | elif ob_filter_format == 'XHTML':
|
|---|
| 575 | # Set XHTML.
|
|---|
| 576 | data = self.toXhtml( REQUEST)
|
|---|
| 577 | outfilename = _fileutil.getOSPath('%s/export.html'%tempfolder)
|
|---|
| 578 | _fileutil.exportObj( data, outfilename)
|
|---|
| 579 | elif ob_filter_format == 'myXML':
|
|---|
| 580 | # Set myXML.
|
|---|
| 581 | data = self.getXmlHeader() + getattr( self, 'getObjToXml_DocElmnt')(context=self)
|
|---|
| 582 | outfilename = _fileutil.getOSPath('%s/export.xml'%tempfolder)
|
|---|
| 583 | _fileutil.exportObj( data, outfilename)
|
|---|
| 584 | else:
|
|---|
| 585 | raise zExceptions.InternalError("Unknown format '%s'"%ob_filter.get('format',''))
|
|---|
| 586 | return tempfolder, outfilename
|
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 | # --------------------------------------------------------------------------
|
|---|
| 590 | # _filtermanager.execProcessFilter:
|
|---|
| 591 | # --------------------------------------------------------------------------
|
|---|
| 592 | def execProcessFilter(self, ob_process, folder, filename, REQUEST):
|
|---|
| 593 | processId = ob_process.get( 'id')
|
|---|
| 594 | processOb = self.getProcess( processId)
|
|---|
| 595 | if processOb is not None:
|
|---|
| 596 | processType = processOb.get( 'type', 'process')
|
|---|
| 597 | trans = ob_process.get( 'file', None)
|
|---|
| 598 | # Save transformation to file.
|
|---|
| 599 | if trans is not None and trans != '':
|
|---|
| 600 | transfilename = '%s/%s'%( folder, trans.getFilename())
|
|---|
| 601 | _fileutil.exportObj( trans.getData(), transfilename)
|
|---|
| 602 | if processType in [ 'DTML Method', 'External Method', 'Script (Python)']:
|
|---|
| 603 | filename = processMethod(self, processId, filename, trans, REQUEST)
|
|---|
| 604 | else:
|
|---|
| 605 | filename = processFile(self, processId, filename, trans)
|
|---|
| 606 | # Return filename.
|
|---|
| 607 | return filename
|
|---|
| 608 |
|
|---|
| 609 |
|
|---|
| 610 | ################################################################################
|
|---|
| 611 | ################################################################################
|
|---|
| 612 | ###
|
|---|
| 613 | ### class FilterManager
|
|---|
| 614 | ###
|
|---|
| 615 | ################################################################################
|
|---|
| 616 | ################################################################################
|
|---|
| 617 | class FilterManager:
|
|---|
| 618 |
|
|---|
| 619 | # Management Interface.
|
|---|
| 620 | # ---------------------
|
|---|
| 621 | manage_customizeFilterForm = HTMLFile('dtml/ZMS/manage_customizefilterform', globals())
|
|---|
| 622 | manage_importexportDebugFilter = HTMLFile('dtml/ZMSContainerObject/manage_importexportdebugfilter', globals())
|
|---|
| 623 |
|
|---|
| 624 |
|
|---|
| 625 | # --------------------------------------------------------------------------
|
|---|
| 626 | # FilterManager.getProcessIds:
|
|---|
| 627 | #
|
|---|
| 628 | # Returns list of process-Ids.
|
|---|
| 629 | # --------------------------------------------------------------------------
|
|---|
| 630 | def getProcessIds(self, sort=1):
|
|---|
| 631 | obs = getRawProcesses(self)
|
|---|
| 632 | ids = obs.keys()
|
|---|
| 633 | portalMaster = self.getPortalMaster()
|
|---|
| 634 | if portalMaster is not None:
|
|---|
| 635 | ids.extend( filter( lambda x: x not in ids, portalMaster.getProcessIds()))
|
|---|
| 636 | if sort:
|
|---|
| 637 | mapping = map(lambda x: (self.getProcess(x)['name'],x),ids)
|
|---|
| 638 | mapping.sort()
|
|---|
| 639 | ids = map(lambda x: x[1],mapping)
|
|---|
| 640 | return ids
|
|---|
| 641 |
|
|---|
| 642 | # --------------------------------------------------------------------------
|
|---|
| 643 | # FilterManager.getProcess:
|
|---|
| 644 | #
|
|---|
| 645 | # Returns process specified by Id.
|
|---|
| 646 | # --------------------------------------------------------------------------
|
|---|
| 647 | def getProcess(self, id):
|
|---|
| 648 | processes = getRawProcesses(self)
|
|---|
| 649 | process = {}
|
|---|
| 650 | if processes.has_key( id):
|
|---|
| 651 | process = processes.get( id).copy()
|
|---|
| 652 | else:
|
|---|
| 653 | # Acquire from parent.
|
|---|
| 654 | portalMaster = self.getPortalMaster()
|
|---|
| 655 | if portalMaster is not None:
|
|---|
| 656 | if id in portalMaster.getProcessIds():
|
|---|
| 657 | process = portalMaster.getProcess(id)
|
|---|
| 658 | process['acquired'] = 1
|
|---|
| 659 | process['id'] = id
|
|---|
| 660 | # Synchronize type.
|
|---|
| 661 | try:
|
|---|
| 662 | container = self.getHome()
|
|---|
| 663 | if process.get('type') in [ 'DTML Method']:
|
|---|
| 664 | ob = getattr( container, process['id'])
|
|---|
| 665 | process['command'] = ob.raw
|
|---|
| 666 | elif process.get('type') in [ 'Script (Python)']:
|
|---|
| 667 | ob = getattr( container, process['id'])
|
|---|
| 668 | process['command'] = ob.read()
|
|---|
| 669 | except:
|
|---|
| 670 | pass
|
|---|
| 671 | return process
|
|---|
| 672 |
|
|---|
| 673 |
|
|---|
| 674 | # --------------------------------------------------------------------------
|
|---|
| 675 | # FilterManager.getFilterIds:
|
|---|
| 676 | #
|
|---|
| 677 | # Returns list of filter-Ids.
|
|---|
| 678 | # --------------------------------------------------------------------------
|
|---|
| 679 | def getFilterIds(self, sort=1):
|
|---|
| 680 | obs = getRawFilters(self)
|
|---|
| 681 | ids = obs.keys()
|
|---|
| 682 | if sort:
|
|---|
| 683 | mapping = map(lambda x: (self.getFilter(x)['name'],x),ids)
|
|---|
| 684 | mapping.sort()
|
|---|
| 685 | ids = map(lambda x: x[1],mapping)
|
|---|
| 686 | return ids
|
|---|
| 687 |
|
|---|
| 688 |
|
|---|
| 689 | # --------------------------------------------------------------------------
|
|---|
| 690 | # FilterManager.getFilter:
|
|---|
| 691 | #
|
|---|
| 692 | # Returns filter specified by Id.
|
|---|
| 693 | # --------------------------------------------------------------------------
|
|---|
| 694 | def getFilter(self, id):
|
|---|
| 695 | obs = getRawFilters(self)
|
|---|
| 696 | ob = {}
|
|---|
| 697 | if obs.has_key( id):
|
|---|
| 698 | ob = obs.get( id).copy()
|
|---|
| 699 | # Acquire from parent.
|
|---|
| 700 | if ob.get('acquired',0) == 1:
|
|---|
| 701 | portalMaster = self.getPortalMaster()
|
|---|
| 702 | if portalMaster is not None:
|
|---|
| 703 | ob = portalMaster.getFilter(id)
|
|---|
| 704 | ob['acquired'] = 1
|
|---|
| 705 | ob['id'] = id
|
|---|
| 706 | return ob
|
|---|
| 707 |
|
|---|
| 708 |
|
|---|
| 709 | # --------------------------------------------------------------------------
|
|---|
| 710 | # FilterManager.getFilterProcesses:
|
|---|
| 711 | #
|
|---|
| 712 | # Returns list of processes for filter specified by Id.
|
|---|
| 713 | # --------------------------------------------------------------------------
|
|---|
| 714 | def getFilterProcesses(self, id):
|
|---|
| 715 | obs = []
|
|---|
| 716 | for process in self.getFilter( id).get( 'processes', []):
|
|---|
| 717 | ob = process.copy()
|
|---|
| 718 | ob[ 'type'] = ob.get( 'type', 'process')
|
|---|
| 719 | process = self.getProcess( ob[ 'id'])
|
|---|
| 720 | if process is not None:
|
|---|
| 721 | obs.append( ob)
|
|---|
| 722 | return obs
|
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 | ############################################################################
|
|---|
| 726 | # FilterManager.manage_changeFilter:
|
|---|
| 727 | #
|
|---|
| 728 | # Customize filter.
|
|---|
| 729 | ############################################################################
|
|---|
| 730 | def manage_changeFilter(self, lang, btn='', key='', REQUEST=None, RESPONSE=None):
|
|---|
| 731 | """ FilterManager.manage_changeFilter """
|
|---|
| 732 | message = ''
|
|---|
| 733 | id = REQUEST.get('id','')
|
|---|
| 734 | pid = REQUEST.get('pid',-1)
|
|---|
| 735 |
|
|---|
| 736 | # Acquire.
|
|---|
| 737 | # --------
|
|---|
| 738 | if btn == self.getZMILangStr('BTN_ACQUIRE'):
|
|---|
| 739 | newId = REQUEST.get('aq_id')
|
|---|
| 740 | newAcquired = 1
|
|---|
| 741 | id = setFilter(self, newId, newAcquired)
|
|---|
| 742 | message = self.getZMILangStr('MSG_INSERTED')%id
|
|---|
| 743 |
|
|---|
| 744 | # Change.
|
|---|
| 745 | # -------
|
|---|
| 746 | elif btn == self.getZMILangStr('BTN_SAVE'):
|
|---|
| 747 | cp = self.getFilter(id)
|
|---|
| 748 | # Filter.
|
|---|
| 749 | newId = REQUEST.get('inpId').strip()
|
|---|
| 750 | newAcquired = 0
|
|---|
| 751 | newName = REQUEST.get('inpName').strip()
|
|---|
| 752 | newFormat = REQUEST.get('inpFormat').strip()
|
|---|
| 753 | newContentType = REQUEST.get('inpContentType').strip()
|
|---|
| 754 | newDescription = REQUEST.get('inpDescription').strip()
|
|---|
| 755 | newRoles = REQUEST.get('inpRoles',[])
|
|---|
| 756 | newMetaTypes = REQUEST.get('inpMetaTypes',[])
|
|---|
| 757 | id = delFilter(self, id)
|
|---|
| 758 | id = setFilter(self, newId, newAcquired, newName, newFormat, newContentType, newDescription, newRoles, newMetaTypes)
|
|---|
| 759 | # Filter Processes.
|
|---|
| 760 | c = 0
|
|---|
| 761 | for filterProcess in cp.get('processes',[]):
|
|---|
| 762 | newProcessId = REQUEST.get('newFilterProcessId_%i'%c)
|
|---|
| 763 | newProcessFile = REQUEST.get('newFilterProcessFile_%i'%c)
|
|---|
| 764 | if isinstance(newProcessFile,ZPublisher.HTTPRequest.FileUpload):
|
|---|
| 765 | if len(getattr(newProcessFile, 'filename',''))==0:
|
|---|
| 766 | newProcessFile = filterProcess.get('file', None)
|
|---|
| 767 | else:
|
|---|
| 768 | newProcessFile = _blobfields.createBlobField(self, _globals.DT_FILE, newProcessFile)
|
|---|
| 769 | setFilterProcess(self, id, newProcessId, newProcessFile)
|
|---|
| 770 | c += 1
|
|---|
| 771 | message = self.getZMILangStr('MSG_CHANGED')
|
|---|
| 772 |
|
|---|
| 773 | # Delete.
|
|---|
| 774 | # -------
|
|---|
| 775 | elif btn == self.getZMILangStr('BTN_DELETE') and key == 'obj':
|
|---|
| 776 | id = delFilter(self, id)
|
|---|
| 777 | message = self.getZMILangStr('MSG_DELETED')%int(1)
|
|---|
| 778 | elif btn == 'delete' and key == 'attr':
|
|---|
| 779 | pid = delFilterProcess(self, id, pid)
|
|---|
| 780 | message = self.getZMILangStr('MSG_DELETED')%int(1)
|
|---|
| 781 |
|
|---|
| 782 | # Export.
|
|---|
| 783 | # -------
|
|---|
| 784 | elif btn == self.getZMILangStr('BTN_EXPORT'):
|
|---|
| 785 | return exportXml(self, REQUEST, RESPONSE)
|
|---|
| 786 |
|
|---|
| 787 | # Import.
|
|---|
| 788 | # -------
|
|---|
| 789 | elif btn == self.getZMILangStr('BTN_IMPORT'):
|
|---|
| 790 | f = REQUEST['file']
|
|---|
| 791 | if f:
|
|---|
| 792 | filename = f.filename
|
|---|
| 793 | importXml(self, xml=f)
|
|---|
| 794 | else:
|
|---|
| 795 | filename = REQUEST['init']
|
|---|
| 796 | createIfNotExists = 1
|
|---|
| 797 | self.importConf(filename, REQUEST, createIfNotExists)
|
|---|
| 798 | message = self.getZMILangStr('MSG_IMPORTED')%('<i>%s</i>'%filename)
|
|---|
| 799 |
|
|---|
| 800 | # Insert.
|
|---|
| 801 | # -------
|
|---|
| 802 | elif btn == self.getZMILangStr('BTN_INSERT'):
|
|---|
| 803 | if key == 'obj':
|
|---|
| 804 | newId = REQUEST.get('newId').strip()
|
|---|
| 805 | newAcquired = 0
|
|---|
| 806 | newName = REQUEST.get('newName').strip()
|
|---|
| 807 | newFormat = REQUEST.get('newFormat').strip()
|
|---|
| 808 | newContentType = REQUEST.get('newContentType').strip()
|
|---|
| 809 | id = setFilter(self, newId, newAcquired, newName, newFormat, newContentType)
|
|---|
| 810 | message = self.getZMILangStr('MSG_INSERTED')%id
|
|---|
| 811 | elif key == 'attr':
|
|---|
| 812 | newProcessId = REQUEST.get('newFilterProcessId')
|
|---|
| 813 | newProcessFile = REQUEST.get('newFilterProcessFile')
|
|---|
| 814 | if isinstance(newProcessFile,ZPublisher.HTTPRequest.FileUpload):
|
|---|
| 815 | if len(getattr(newProcessFile, 'filename',''))==0:
|
|---|
| 816 | newProcessFile = None
|
|---|
| 817 | else:
|
|---|
| 818 | newProcessFile = _blobfields.createBlobField(self, _globals.DT_FILE, newProcessFile)
|
|---|
| 819 | pid = setFilterProcess(self, id, newProcessId, newProcessFile)
|
|---|
| 820 | message = self.getZMILangStr('MSG_INSERTED')%newProcessId
|
|---|
| 821 |
|
|---|
| 822 | # Move to.
|
|---|
| 823 | # --------
|
|---|
| 824 | elif btn == 'move_to':
|
|---|
| 825 | pos = REQUEST['pos']
|
|---|
| 826 | pid = moveFilterProcess(self, id, pid, pos)
|
|---|
| 827 | message = self.getZMILangStr('MSG_MOVEDOBJTOPOS')%(("<i>%s</i>"%pid),(pos+1))
|
|---|
| 828 |
|
|---|
| 829 | # Return with message.
|
|---|
| 830 | message = urllib.quote(message)
|
|---|
| 831 | return RESPONSE.redirect('manage_customizeFilterForm?id=%s&pid:int=%i&lang=%s&manage_tabs_message=%s'%(id,pid,lang,message))
|
|---|
| 832 |
|
|---|
| 833 |
|
|---|
| 834 | ############################################################################
|
|---|
| 835 | # FilterManager.manage_changeProcess:
|
|---|
| 836 | #
|
|---|
| 837 | # Customize process.
|
|---|
| 838 | ############################################################################
|
|---|
| 839 | def manage_changeProcess(self, lang, btn='', key='', REQUEST=None, RESPONSE=None):
|
|---|
| 840 | """ FilterManager.manage_changeProcess """
|
|---|
| 841 | message = ''
|
|---|
| 842 | id = REQUEST.get('id','')
|
|---|
| 843 |
|
|---|
| 844 | # Change.
|
|---|
| 845 | # -------
|
|---|
| 846 | if btn == self.getZMILangStr('BTN_SAVE'):
|
|---|
| 847 | newId = REQUEST.get('inpId').strip()
|
|---|
| 848 | newAcquired = 0
|
|---|
| 849 | newName = REQUEST.get('inpName').strip()
|
|---|
| 850 | newType = REQUEST.get('inpType').strip()
|
|---|
| 851 | newCommand = REQUEST.get('inpCommand').strip()
|
|---|
| 852 | id = delProcess(self, id)
|
|---|
| 853 | id = setProcess(self, newId, newAcquired, newName, newType, newCommand)
|
|---|
| 854 | message = self.getZMILangStr('MSG_CHANGED')
|
|---|
| 855 |
|
|---|
| 856 | # Delete.
|
|---|
| 857 | # -------
|
|---|
| 858 | elif btn == self.getZMILangStr('BTN_DELETE'):
|
|---|
| 859 | id = delProcess(self, id)
|
|---|
| 860 | message = self.getZMILangStr('MSG_DELETED')%int(1)
|
|---|
| 861 |
|
|---|
| 862 | # Export.
|
|---|
| 863 | # -------
|
|---|
| 864 | elif btn == self.getZMILangStr('BTN_EXPORT'):
|
|---|
| 865 | return exportXml(self, REQUEST, RESPONSE)
|
|---|
| 866 |
|
|---|
| 867 | # Import.
|
|---|
| 868 | # -------
|
|---|
| 869 | elif btn == self.getZMILangStr('BTN_IMPORT'):
|
|---|
| 870 | f = REQUEST['file']
|
|---|
| 871 | if f:
|
|---|
| 872 | filename = f.filename
|
|---|
| 873 | importXml(self, xml=f)
|
|---|
| 874 | else:
|
|---|
| 875 | filename = REQUEST['init']
|
|---|
| 876 | createIfNotExists = 1
|
|---|
| 877 | self.importConf(filename, REQUEST, createIfNotExists)
|
|---|
| 878 | message = self.getZMILangStr('MSG_IMPORTED')%('<i>%s</i>'%filename)
|
|---|
| 879 |
|
|---|
| 880 | # Insert.
|
|---|
| 881 | # -------
|
|---|
| 882 | elif btn == self.getZMILangStr('BTN_INSERT'):
|
|---|
| 883 | newId = REQUEST.get('newId').strip()
|
|---|
| 884 | newAcquired = 0
|
|---|
| 885 | newName = REQUEST.get('newName').strip()
|
|---|
| 886 | newType = REQUEST.get('newType').strip()
|
|---|
| 887 | id = setProcess(self, newId, newAcquired, newName, newType)
|
|---|
| 888 | message = self.getZMILangStr('MSG_INSERTED')%id
|
|---|
| 889 |
|
|---|
| 890 | # Return with message.
|
|---|
| 891 | message = urllib.quote(message)
|
|---|
| 892 | return RESPONSE.redirect('manage_customizeFilterForm?id=%s&lang=%s&manage_tabs_message=%s'%(id,lang,message))
|
|---|
| 893 |
|
|---|
| 894 | ################################################################################
|
|---|