From bf98b2cdf2ef48b45be189dc6b1ba1e69b416224 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Sat, 16 Mar 2013 00:02:16 +0100 Subject: [PATCH] [px] Implemented attribute values containing Python expressions, and errors management. --- gen/ogone.py | 13 +++++++++++++ gen/ui/widgets/ogone.pt | 4 ++++ pod/buffers.py | 21 ++++++++++++++++++--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/gen/ogone.py b/gen/ogone.py index cb6c3b0..9bdf7ac 100644 --- a/gen/ogone.py +++ b/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(''' +

Hello PX world.

+ +
+ :x : :value[x] +
+ :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') # ------------------------------------------------------------------------------ diff --git a/gen/ui/widgets/ogone.pt b/gen/ui/widgets/ogone.pt index 739c32c..cb4f745 100644 --- a/gen/ui/widgets/ogone.pt +++ b/gen/ui/widgets/ogone.pt @@ -2,6 +2,7 @@ var "value" is misused and contains the contact params for Ogone. The form for sending the payment request to Ogone. +

@@ -13,6 +14,9 @@
+ Ogone PX test +
PX
+
Edit macro (none) diff --git a/pod/buffers.py b/pod/buffers.py index 7ebf3d1..0c7df0a 100644 --- a/pod/buffers.py +++ b/pod/buffers.py @@ -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' # ------------------------------------------------------------------------------