| 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 | |
|---|
| 12 | from Products.CMFCore.utils import getToolByName |
|---|
| 13 | from Products.qPloneSkinDump.qPloneSkinDump import isValidProductName |
|---|
| 14 | from Products.qPloneSkinDump.qPloneSkinDump import isValidDirName |
|---|
| 15 | from Products.qPloneSkinDump.qPloneSkinDump import isValidDestinationDir |
|---|
| 16 | errors = state.getErrors() |
|---|
| 17 | |
|---|
| 18 | def 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 |
|---|
| 26 | REQUIRED_FIELDS = ['ZMISkinName', 'ZMIBaseSkinName', 'FSProductName', 'FSSkinDirectory', 'FSDestinationDirectory'] |
|---|
| 27 | theform = {} |
|---|
| 28 | for 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 | |
|---|
| 34 | if not( theform["FSDestinationDirectory"] and isValidDestinationDir(theform["FSDestinationDirectory"]) ): |
|---|
| 35 | update_errors(errors, {"FSDestinationDirectory": u"Not valid Destination directory"}) |
|---|
| 36 | |
|---|
| 37 | if 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 | |
|---|
| 41 | if not( theform['FSSkinDirectory'] and isValidDirName(theform['FSSkinDirectory']) ): |
|---|
| 42 | update_errors(errors, {'FSSkinDirectory': u"Not valid Skin name - read help attentively."}) |
|---|
| 43 | |
|---|
| 44 | if errors: |
|---|
| 45 | return state.set(status='failure', errors=errors, portal_status_message='Please correct the indicated errors.') |
|---|
| 46 | |
|---|
| 47 | return state |
|---|