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