Ménage
[photoprint.git] / skins / photoprint_templates_edit_form.py
1 ##parameters=addTemplate='', edit='', deleteOptionContainer='', createOptionsContainer=''
2 from Products.CMFCore.utils import getToolByName
3 from Products.photoprint.utils import translate as _
4
5 utool = getToolByName(context, 'portal_url')
6 pptool = getToolByName(context, 'portal_photo_print')
7 form = context.REQUEST.form.copy()
8
9 if addTemplate:
10 context.REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml;;charset=utf-8');
11 fg = form.get
12
13 try :
14 orderTemplate = pptool.addPrintOrderTemplate( context
15 , title=fg('title')
16 , description=fg('description')
17 , productReference=fg('productReference')
18 , maxCopies=fg('maxCopies')
19 , price=fg('price')
20 , VATRate=fg('VATRate')
21 )
22 templateOptions = {}
23 templateOptions['o'] = orderTemplate
24 classRowName = 'odd'
25 if context.printingOptions.getObjectPosition(orderTemplate.getId()) % 2 == 0 :
26 classRowName = 'even'
27 templateOptions['classRowName'] = classRowName
28 templateOptions['portal_url'] = utool()
29 widget = context.get_photo_print_order_template(**templateOptions).encode('utf-8').strip()
30 return '<computedField type="added">%s</computedField>' % widget
31
32 except ValueError, e:
33 return '<error>%s</error>' % _(e)
34
35 elif edit:
36 context.REQUEST.RESPONSE.setHeader('Content-Type', 'text/xml;;charset=utf-8');
37 id = form.pop('id')
38 try :
39 orderTemplate = pptool.editPrintOrderTemplate(context, id, **form)
40
41 templateOptions = {}
42 templateOptions['o'] = orderTemplate
43 classRowName = 'odd'
44 if context.printingOptions.getObjectPosition(orderTemplate.getId()) % 2 == 0 :
45 classRowName = 'even'
46 templateOptions['classRowName'] = classRowName
47 templateOptions['portal_url'] = utool()
48 widget = context.get_photo_print_order_template(**templateOptions).encode('utf-8').strip()
49 return '<computedField type="edited">%s</computedField>' % widget
50 except ValueError, e :
51 return '<error>%s</error>' % _(e)
52
53 elif createOptionsContainer :
54 pptool.createPrintingOptionsContainer(context)
55 context.setStatus(True, _('Printing options added.'))
56
57 elif deleteOptionContainer :
58 pptool.deletePrintingOptionsContainer(context)
59 context.setStatus(True, _('Printing options deleted.'))
60
61
62 options = {}
63 options['pptool'] = pptool
64 options['hasPO'] = pptool.hasPrintingOptions(context)
65 pOptionsSrc = pptool.getPrintingOptionsSrc(context)
66 if pOptionsSrc :
67 pourl = pOptionsSrc.getActionInfo('object/printing_settings')['url']
68 else :
69 pourl = None
70 options['pourl'] = pourl
71
72 return context.photoprint_templates_edit_template(**options)