From 18103733043dbb3d79fa14353d69254d24a4ecd9 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Mon, 15 Jul 2013 11:23:29 +0200 Subject: [PATCH] [gen] Optimized PXs. [px] added tag 'var2', similar to 'var', but that is executed after tags 'for' and 'if'. --- fields/action.py | 8 +- fields/calendar.py | 313 +++++++++--------- fields/computed.py | 36 +-- fields/date.py | 39 ++- fields/float.py | 37 ++- fields/integer.py | 31 +- fields/list.py | 30 +- fields/ogone.py | 27 +- fields/pod.py | 30 +- fields/ref.py | 244 +++++++------- fields/string.py | 94 +++--- gen/mixins/ToolMixin.py | 11 + gen/utils.py | 57 ++-- gen/wrappers/ToolWrapper.py | 192 +++++------ gen/wrappers/__init__.py | 630 +++++++++++++++++------------------- pod/actions.py | 5 +- pod/buffers.py | 2 +- px/px_parser.py | 4 +- 18 files changed, 834 insertions(+), 956 deletions(-) diff --git a/fields/action.py b/fields/action.py index 4034316..849f40e 100644 --- a/fields/action.py +++ b/fields/action.py @@ -33,17 +33,15 @@ class Action(Field): - - + style=":img('buttonAction', bg=True)"/> ''') # It is not possible to edit an action, not to search it. diff --git a/fields/calendar.py b/fields/calendar.py index d8007c1..9ec7970 100644 --- a/fields/calendar.py +++ b/fields/calendar.py @@ -36,25 +36,22 @@ class Calendar(Field): otherCalendars=field.getOtherCalendars(contextObj, preComputed)" id=":ajaxHookId"> - + - -
- - + + - - - + - - - - :_('month_%s' % monthDayOne.aMonth()) - :month.split('/')[0] -
+ :_('month_%s' % monthDayOne.aMonth()) + :month.split('/')[0] + - - - - - - - - - - + +
:dayName
+ + + + + + + - - - + if="info['eventTypes']" src=":img('plus')" + onclick=":'openEventPopup(%s, %s, %s, null, %s, %s)' % \ + (q('new'), q(field.name), q(dayString), q(info['eventTypes']),\ + q(info['message']))"/> + + + + +
+ :field.getEventName(contextObj, \ + eventType)"> +
+ + +
:event['name']
+
+ + ::info + - - -
:dayName
- - :day - :_('month_%s_short' % date.aMonth())"> - - - + :day + :_('month_%s_short' % date.aMonth())"> + + + - - - - - -
- :field.getEventName(contextObj, \ - eventType)"> -
-
- - - -
:event['name']
-
-
- - ::info -
-
+ + - - - - ''') + +
+ + + :_('del_next_events')"> +
+ + + + + ''') pxView = pxCell = Px(''' - :field.pxMonthView - ''') + x=req.set('month', defaultDate.strftime('%Y/%m')); + x=req.set('fieldName', field.name)">:field.pxMonthView''') pxEdit = pxSearch = '' diff --git a/fields/computed.py b/fields/computed.py index 6572129..110c36e 100644 --- a/fields/computed.py +++ b/fields/computed.py @@ -28,27 +28,23 @@ class Computed(Field): value=contextObj.getFieldValue(name); sync=True">:field.pxView''') - pxView = pxCell = pxEdit = Px(''' - - - :value - ::value> - - -
- -
-
-
''') + pxView = pxCell = pxEdit = Px(''' + + :value::value> + +
+ var2="ajaxHookId=contextObj.UID() + name" id="ajaxHookId"> + +
+
''') - pxSearch = Px(''' - -
   - -
''') + pxSearch = Px(''' +
   + +
''') def __init__(self, validator=None, multiplicity=(0,1), default=None, show='view', page='main', group=None, layouts=None, move=0, diff --git a/fields/date.py b/fields/date.py index 0bc8f47..e60bd72 100644 --- a/fields/date.py +++ b/fields/date.py @@ -29,20 +29,20 @@ class Date(Field): @@ -56,7 +56,7 @@ class Date(Field): - + @@ -65,19 +65,18 @@ class Date(Field): : ''') @@ -112,7 +111,7 @@ class Date(Field): - + @@ -145,7 +144,7 @@ class Date(Field): - + diff --git a/fields/float.py b/fields/float.py index 0daaa03..1dd24ee 100644 --- a/fields/float.py +++ b/fields/float.py @@ -31,26 +31,25 @@ class Float(Field): ''') pxEdit = Px(''' - ''') + ''') - pxSearch = Px(''' - -
   - - - - - - - - - -
-
''') + pxSearch = Px(''' +
   + + + + + + + + + +
+
''') def __init__(self, validator=None, multiplicity=(0,1), default=None, show=True, page='main', group=None, layouts=None, move=0, diff --git a/fields/integer.py b/fields/integer.py index 402f2b1..3b470bf 100644 --- a/fields/integer.py +++ b/fields/integer.py @@ -32,22 +32,21 @@ class Integer(Field): maxlength=":field.maxChars" value=":inRequest and requestValue or value" type="text"/>''') - pxSearch = Px(''' - -
   - - - - - - - - - -
-
''') + pxSearch = Px(''' +
   + + + + + + + + + +
+
''') def __init__(self, validator=None, multiplicity=(0,1), default=None, show=True, page='main', group=None, layouts=None, move=0, diff --git a/fields/list.py b/fields/list.py index db2f32f..e654a69 100644 --- a/fields/list.py +++ b/fields/list.py @@ -27,15 +27,14 @@ class List(Field): # PX for rendering a single row. pxRow = Px(''' - - :field.pxView - + :field.pxView - ''') @@ -49,8 +48,7 @@ class List(Field): ::_(info[1].labelId) - @@ -60,17 +58,15 @@ class List(Field): - - :field.pxRow - + :field.pxRow ''') pxView = pxCell = Px(''':field.pxTable''') - pxEdit = Px(''' - - - :field.pxTable - ''') + pxEdit = Px(''' + + :field.pxTable + ''') pxSearch = '' diff --git a/fields/ogone.py b/fields/ogone.py index 3e3e64d..a45eec3 100644 --- a/fields/ogone.py +++ b/fields/ogone.py @@ -30,21 +30,18 @@ class Ogone(Field): '''This field allows to perform payments with the Ogone (r) system.''' urlTypes = ('accept', 'decline', 'exception', 'cancel') - pxView = pxCell = Px(''' - - - -
- - - - - -
-
''') + pxView = pxCell = Px(''' + + +
+ + + +
+
''') pxEdit = pxSearch = '' diff --git a/fields/pod.py b/fields/pod.py index ae4d54b..2c751b1 100644 --- a/fields/pod.py +++ b/fields/pod.py @@ -35,23 +35,19 @@ class Pod(Field): 'contact the system administrator.' DELETE_TEMP_DOC_ERROR = 'A temporary document could not be removed. %s.' - pxView = pxCell = Px(''' - - - - - - - - - - ''') + pxView = pxCell = Px(''' + + + + + + + ''') pxEdit = pxSearch = '' diff --git a/fields/ref.py b/fields/ref.py index acfc6ac..28acf09 100644 --- a/fields/ref.py +++ b/fields/ref.py @@ -56,41 +56,37 @@ class Ref(Field): - - + @@ -100,37 +96,34 @@ class Ref(Field): # Displays the button allowing to add a new object through a Ref field, if # it has been declared as addable and if multiplicities allow it. pxAdd = Px(''' - - - ''') + ''') # This PX displays, in a cell header from a ref table, icons for sorting the # ref field according to the field that corresponds to this column. pxSortIcons = Px(''' - - + - ''') @@ -165,25 +158,21 @@ class Ref(Field): shouldn't check the actual number of referenced objects. But for back references people often forget to specify multiplicities. So concretely, multiplicities (0,None) are coded as (0,1). --> - - -
- + - - :targetObj.appy().pxTransitions - :targetObj.appy().pxTransitions - - + + src=":img('delete')" onclick=":'onDeleteObject(%s)'%q(obj.UID())"/>
- - - - - - - - - - - - - -
:_('no_ref'):field.pxAdd:field.pxObjectTitle
- + + + + + + + + + + + + + +
:_('no_ref'):field.pxAdd:field.pxObjectTitle
@@ -192,8 +181,7 @@ class Ref(Field): :field.pxAdd :_('no_ref')

+ width="100%"> - - - - - + + +
@@ -216,39 +204,32 @@ class Ref(Field): var="columns=objs[0].getColumnsSpecifiers(field.shownInfo, dir)">
- - _(field.labelId) - :field.pxSortIcons - :contextObj.appy(\ - ).pxShowDetails - + align="column['align']" + var2="field=column['field']"> + :_(field.labelId) + :field.pxSortIcons + :contextObj.appy(\ + ).pxShowDetails
- - - - :field.pxObjectTitle -
:field.pxObjectActions
-
- - - - - - -
-
+ + + :field.pxObjectTitle +
:field.pxObjectActions
+
+ + + :field.pxView + +
@@ -256,56 +237,49 @@ class Ref(Field): :contextObj.appy().pxAppyNavigate -
+ ''') pxView = pxCell = Px(''' :field.pxViewContent''') pxEdit = Px(''' - - - ''') + ''') - pxSearch = Px(''' - -
   - - :_(field.labelId)">
   + + - - - -
-
- - -
''') + andName='%s_and' % operName"> + + + +
+
+ + + ''') def __init__(self, klass=None, attribute=None, validator=None, multiplicity=(0,1), default=None, add=False, addConfirm=False, diff --git a/fields/string.py b/fields/string.py index 091575c..ad74267 100644 --- a/fields/string.py +++ b/fields/string.py @@ -108,29 +108,28 @@ class String(Field): isSelect=field.isSelect; isMaster=field.slaves; isOneLine=fmt in (0,3,4)"> - - - + - - :_('captcha_text', \ - mapping=field.getCaptchaChallenge(req.SESSION)) - + + :_('captcha_text', \ + mapping=field.getCaptchaChallenge(req.SESSION)) + -
- -
- - +
+

+ + +

+ :_('workflow_comment') + +
+

+ + -
- + + @@ -526,18 +508,18 @@ class AbstractWrapper(object): - + :self.pxIcons - +
+ style=":img('%s.jpg' % bannerName, bg=True)">
- + @@ -466,14 +449,13 @@ class AbstractWrapper(object): style="cursor:pointer">:_('app_connect') - - - +
:userInfo[0] - - +
@@ -578,130 +560,121 @@ class AbstractWrapper(object): + historyInfo=contextObj.getHistory(startNumber,batchSize=batchSize)" + if="historyInfo['events']" + var2="objs=historyInfo['events']; + totalNumber=historyInfo['totalNumber']; + ajaxHookId='appyHistory'; + navBaseCall='askObjectHistory(%s,%s,%d,**v**)' % \ + (q(ajaxHookId), q(contextObj.absolute_url()), batchSize)"> - - - :self.pxAppyNavigate - - - - - - - - - - - - - - - - - -
:_('object_action'):_('object_author'):_('action_date'):_('action_comment')
- :_('data_change') - - :_(contextObj.getWorkflowLabel(action)) - ? - :ztool.getUserName(actorId) - :ztool.formatDate(event['time'], withHour=True)"> - ::contextObj.formatText(rhComments) - - - - - - - - - - - - - - - -
:_('modified_field'):_('previous_value')
::_(appyType['labelId'])::change[1][0]
-
-
-
- ''') + + :self.pxAppyNavigate + + + + + + + + + + + + + + + + +
:_('object_action'):_('object_author'):_('action_date'):_('action_comment')
+ :_('data_change') + + :_(contextObj.getWorkflowLabel(action)) + ? + :ztool.getUserName(actorId) + :ztool.formatDate(event['time'], withHour=True)"> + ::contextObj.formatText(rhComments) + - + + + + + + + + + + + +
:_('modified_field'):_('previous_value')
::_(appyType['labelId'])::change[1][0]
+
+
''') # Displays an object's transitions(s). pxTransitions = Px(''' - -
- - - - - - - - + +
- - + + + + + + + + + - -
+ + - - -
- - ''') + + +
+ ''') # Displays header information about an object: title, workflow-related info, # history... pxObjectHeader = Px(''' -
- +
- + :_('object_history') || - :_('object_created_by') - :ztool.getUserName(creator) + :_('object_created_by'):ztool.getUserName(creator) :_('object_created_on') @@ -726,18 +699,16 @@ class AbstractWrapper(object): -
- +
+
-
- ''') +
''') # Shows the range of buttons (next, previous, save,...) and the workflow # transitions. @@ -754,73 +725,61 @@ class AbstractWrapper(object): + style=":img('buttonPrevious', bg=True)"/> - - - + + style=":img(buttonSave', bg=True)" value=":_('object_save')"/> + style=":img('buttonCancel', bg=True)" value=":_('object_cancel')"/> - - - - + + - - - - - + + + + + style=":img('buttonNext', bg=True)" value=":_('page_next')"/> - - - + @@ -830,8 +789,8 @@ class AbstractWrapper(object): - + + ''') @@ -869,7 +828,7 @@ class AbstractWrapper(object): cssJs=cssJs)"> :self.pxPagePrologue -
- - - - - - :self.pxLayoutedObject + + + + + + :self.pxLayoutedObject
+ if="confirmMsg">:'askConfirm(%s,%s,%s)' % \ + (q('script'), q('postConfirmedEditForm()'), q(confirmMsg)) :self.pxPageBottom ''', template=pxTemplate, hook='content') diff --git a/pod/actions.py b/pod/actions.py index 38e8cca..d87a7ad 100644 --- a/pod/actions.py +++ b/pod/actions.py @@ -135,7 +135,10 @@ class IfAction(BufferAction): the result or not.''' def do(self, result, context, exprRes): if exprRes: - self.evaluateBuffer(result, context) + if self.subAction: + self.subAction.execute(result, context) + else: + self.evaluateBuffer(result, context) else: if self.buffer.isMainElement(Cell.OD): # Don't leave the current row with a wrong number of cells diff --git a/pod/buffers.py b/pod/buffers.py index c1b1398..6df55f5 100644 --- a/pod/buffers.py +++ b/pod/buffers.py @@ -499,7 +499,7 @@ class MemoryBuffer(Buffer): 'buffer', None) elif actionType == 'if': action= IfAction('if', self, statement, elem, False, 'buffer', None) - elif actionType == 'var': + elif actionType in ('var', 'var2'): variables = self._getVariables(statement) action = VariablesAction('var', self, elem, False, variables, 'buffer', None) diff --git a/px/px_parser.py b/px/px_parser.py index 4777b38..5eca112 100644 --- a/px/px_parser.py +++ b/px/px_parser.py @@ -44,7 +44,7 @@ class PxEnvironment(XmlEnvironment): # ------------------------------------------------------------------------------ class PxParser(XmlParser): '''PX parser that is specific for parsing PX data.''' - pxAttributes = ('var', 'for', 'if') + pxAttributes = ('var', 'for', 'if', 'var2') # No-end tags noEndTags = ('br', 'img', 'link', 'input') noDumpTags = ('selected', 'checked', 'disabled', 'multiple') @@ -79,7 +79,7 @@ class PxParser(XmlParser): # the main element or to a sub-element. e.currentBuffer.addElement(elem, elemType='px') if elem != 'x': - # Dump the start elements and its attributes. But as a preamble, + # Dump the start element and its attributes. But as a preamble, # manage special attributes that could not be dumped at all, like # "selected" or "checked". hook = None