source: products/qPloneSkinDump/trunk/skins/qploneskindump/validate_qploneskindump_form.vpy @ 2111

Last change on this file since 2111 was 74, checked in by chervol, 18 years ago

initial plone2.0.5 branch import

File size: 1.9 KB
Line 
1## Controller Python Script "validate_qploneskindump_form.vpy"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind state=state
7##bind subpath=traverse_subpath
8##parameters=
9##title=Validates qPloneSkinDump form
10##
11
12from Products.CMFCore.utils import getToolByName
13from Products.qPloneSkinDump.qPloneSkinDump import isValidProductName
14from Products.qPloneSkinDump.qPloneSkinDump import isValidDirName
15from Products.qPloneSkinDump.qPloneSkinDump import isValidDestinationDir
16errors = state.getErrors()
17
18def update_errors(existent_errors, new_errors):
19    for e_name, e_value in new_errors.items():
20        if e_name in existent_errors.keys():
21            existent_errors[e_name] = existent_errors[e_name] + e_value
22        else:
23            existent_errors[e_name] = e_value
24
25# Check REQUIRED fields
26REQUIRED_FIELDS = ['ZMISkinName', 'ZMIBaseSkinName', 'FSProductName', 'FSSkinDirectory', 'FSDestinationDirectory']
27theform = {}
28for f in REQUIRED_FIELDS:
29    fdata = context.REQUEST.get(f, None)
30    if not fdata:
31        update_errors(errors, {f:u'Field is required.'})
32    theform[f]=fdata
33
34if not( theform["FSDestinationDirectory"] and isValidDestinationDir(theform["FSDestinationDirectory"]) ):
35    update_errors(errors, {"FSDestinationDirectory": u"Not valid Destination directory"})
36
37if not( theform['FSProductName'] and theform["FSDestinationDirectory"] \
38        and isValidProductName(theform['FSProductName'], theform["FSDestinationDirectory"]) ):
39    update_errors(errors, {'FSProductName': u"Not valid Product name or problem with destination directory - read help attentively."})
40
41if not( theform['FSSkinDirectory'] and isValidDirName(theform['FSSkinDirectory']) ):
42    update_errors(errors, {'FSSkinDirectory': u"Not valid Skin name - read help attentively."})
43
44if errors:
45    return state.set(status='failure', errors=errors, portal_status_message='Please correct the indicated errors.')
46
47return state
Note: See TracBrowser for help on using the repository browser.