[px] Implemented attribute values containing Python expressions, and errors management.
This commit is contained in:
parent
be3cc6ae59
commit
bf98b2cdf2
13
gen/ogone.py
13
gen/ogone.py
|
@ -2,6 +2,17 @@
|
|||
import sha
|
||||
from appy import Object
|
||||
from appy.gen import Type
|
||||
from appy.px import Px
|
||||
|
||||
view = Px('''
|
||||
<p>Hello PX world.</p>
|
||||
<x for="x in value.keys()">
|
||||
<div if="len(x) < 5">
|
||||
<x>:x</x> : <x>:value[x]</x>
|
||||
</div>
|
||||
<a href=":'http://www.cetic.be/%s' % value[x]">:x</a>
|
||||
</x>
|
||||
''')
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
class OgoneConfig:
|
||||
|
@ -146,4 +157,6 @@ class Ogone(Type):
|
|||
# some URL, use it. Else, use the view page of p_obj.
|
||||
if not url: url = obj.absolute_url()
|
||||
obj.goto(url)
|
||||
|
||||
def getPx(self, context): return view(context).encode('utf-8')
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
<metal:view define-macro="view">
|
||||
<tal:comment replace="nothing">var "value" is misused and contains the contact params for Ogone.</tal:comment>
|
||||
<tal:comment replace="nothing">The form for sending the payment request to Ogone.</tal:comment>
|
||||
<p tal:content="value"></p>
|
||||
<form method="post" id="form1" name="form1"
|
||||
tal:define="env value/env"
|
||||
tal:attributes="action string: https://secure.ogone.com/ncol/$env/orderstandard.asp">
|
||||
|
@ -13,6 +14,9 @@
|
|||
<input type="image" id="submit2" name="submit2"
|
||||
tal:attributes="src string: $appUrl/ui/ogone.gif; title python: _('custom_pay')"/>
|
||||
</form>
|
||||
<tal:comment replace="nothing">Ogone PX test</tal:comment>
|
||||
<div>PX</div>
|
||||
<tal:px replace="structure python: contextObj.callField(name, 'getPx', {'obj': contextObj, 'value': value})"/>
|
||||
</metal:view>
|
||||
|
||||
<tal:comment replace="nothing">Edit macro (none)</tal:comment>
|
||||
|
|
|
@ -150,7 +150,14 @@ class Buffer:
|
|||
self.write('<%s' % elem)
|
||||
for name, value in attrs.items():
|
||||
if ignoreAttrs and (name in ignoreAttrs): continue
|
||||
self.write(' %s=%s' % (name, quoteattr(value)))
|
||||
# If the value begins with ':', it is a Python expression. Else,
|
||||
# it is a static value.
|
||||
if not value.startswith(':'):
|
||||
self.write(' %s=%s' % (name, quoteattr(value)))
|
||||
else:
|
||||
self.write(' %s="' % name)
|
||||
self.addExpression(value[1:])
|
||||
self.write('"')
|
||||
if insertAttributesHook:
|
||||
res = self.addAttributes()
|
||||
else:
|
||||
|
@ -605,8 +612,11 @@ class MemoryBuffer(Buffer):
|
|||
try:
|
||||
result.dumpContent(evalEntry.evaluate(self.env.context))
|
||||
except Exception, e:
|
||||
PodError.dump(result, EVAL_EXPR_ERROR % (
|
||||
evalEntry.expr, e), dumpTb=False)
|
||||
if self.caller() == 'pod':
|
||||
PodError.dump(result, EVAL_EXPR_ERROR % (
|
||||
evalEntry.expr, e), dumpTb=False)
|
||||
else: # px
|
||||
raise Exception(EVAL_EXPR_ERROR %(evalEntry.expr,e))
|
||||
elif isinstance(evalEntry, Attributes):
|
||||
result.write(evalEntry.evaluate(self.env.context))
|
||||
else: # It is a subBuffer
|
||||
|
@ -621,4 +631,9 @@ class MemoryBuffer(Buffer):
|
|||
def clean(self):
|
||||
'''Cleans the buffer content.'''
|
||||
self.content = u''
|
||||
|
||||
def caller(self):
|
||||
'''Returns "pod" if the caller is appy.pod, "px" if it is appy.px.'''
|
||||
if self.env.__class__.__name__ == 'PxEnvironment': return 'px'
|
||||
return 'pod'
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue