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, isValidDirName |
---|
14 | errors = state.getErrors() |
---|
15 | |
---|
16 | def update_errors(existent_errors, new_errors): |
---|
17 | for e_name, e_value in new_errors.items(): |
---|
18 | if e_name in existent_errors.keys(): |
---|
19 | existent_errors[e_name] = existent_errors[e_name] + e_value |
---|
20 | else: |
---|
21 | existent_errors[e_name] = e_value |
---|
22 | |
---|
23 | # Check REQUIRED fields |
---|
24 | REQUIRED_FIELDS = ['ZMISkinName', 'ZMIBaseSkinName', 'FSProductName', 'FSSkinDirectory'] |
---|
25 | theform = {} |
---|
26 | for f in REQUIRED_FIELDS: |
---|
27 | fdata = context.REQUEST.get(f, None) |
---|
28 | if not fdata: |
---|
29 | update_errors(errors, {f:u'Field is required.'}) |
---|
30 | theform[f]=fdata |
---|
31 | |
---|
32 | if not( theform['FSProductName'] and isValidProductName(theform['FSProductName']) ): |
---|
33 | update_errors(errors, {'FSProductName': u"Not valid Product name - read help attentively."}) |
---|
34 | |
---|
35 | if not( theform['FSSkinDirectory'] and isValidDirName(theform['FSSkinDirectory']) ): |
---|
36 | update_errors(errors, {'FSSkinDirectory': u"Not valid Skin name - read help attentively."}) |
---|
37 | |
---|
38 | if errors: |
---|
39 | return state.set(status='failure', errors=errors, portal_status_message='Please correct the indicated errors.') |
---|
40 | |
---|
41 | return state |
---|