Bugfixes while dumping and converting a file from database to disk; bugfix and minor improvement in layouts.

This commit is contained in:
Gaetan Delannay 2010-11-22 15:34:04 +01:00
parent 502c86dab8
commit 0e83a6f490
4 changed files with 24 additions and 10 deletions

View file

@ -576,10 +576,7 @@ class Type:
if not layouts:
# Get the default layouts as defined by the subclass
areDefault = True
layouts = self.getDefaultLayouts()
if not layouts:
# Get the global default layouts
layouts = copy.deepcopy(defaultFieldLayouts)
layouts = self.computeDefaultLayouts()
else:
if isinstance(layouts, basestring):
# The user specified a single layoutString (the "edit" one)
@ -588,19 +585,24 @@ class Type:
# Idem, but with a Table instance
layouts = {'edit': Table(other=layouts)}
else:
layouts = copy.deepcopy(layouts)
# Here, we make a copy of the layouts, because every layout can
# be different, even if the user decides to reuse one from one
# field to another. This is because we modify every layout for
# adding master/slave-related info, focus-related info, etc,
# which can be different from one field to the other.
layouts = copy.deepcopy(layouts)
if 'edit' not in layouts:
defEditLayout = self.computeDefaultLayouts()
if type(defEditLayout) == dict:
defEditLayout = defEditLayout['edit']
layouts['edit'] = defEditLayout
# We have now a dict of layouts in p_layouts. Ensure now that a Table
# instance is created for every layout (=value from the dict). Indeed,
# a layout could have been expressed as a simple layout string.
for layoutType in layouts.iterkeys():
if isinstance(layouts[layoutType], basestring):
layouts[layoutType] = Table(layouts[layoutType])
# Create the "view" layout from the "edit" layout if not specified
# Derive "view" and "cell" layouts from the "edit" layout when relevant
if 'view' not in layouts:
layouts['view'] = Table(other=layouts['edit'], derivedType='view')
# Create the "cell" layout from the 'view' layout if not specified.
@ -656,6 +658,15 @@ class Type:
default layouts. If None is returned, a global set of default layouts
will be used.'''
def computeDefaultLayouts(self):
'''This method gets the default layouts from an Appy type, or a copy
from the global default field layouts when they are not available.'''
res = self.getDefaultLayouts()
if not res:
# Get the global default layouts
res = copy.deepcopy(defaultFieldLayouts)
return res
def getCss(self, layoutType):
'''This method returns a list of CSS files that are required for
displaying widgets of self's type on a given p_layoutType.'''

View file

@ -123,7 +123,7 @@ class Table(LayoutElement):
'''Represents a table where to dispose graphical elements.'''
simpleParams = ('style', 'css_class', 'cellpadding', 'cellspacing', 'width',
'align')
derivedRepls = {'view': 'hrv', 'cell': 'ld'}
derivedRepls = {'view': 'hrvd', 'cell': 'ld'}
def __init__(self, layoutString=None, style=None, css_class='',
cellpadding=0, cellspacing=0, width='100%', align='left',
other=None, derivedType=None):

View file

@ -35,7 +35,8 @@
size python: isMultiple and widget['height'] or 1">
<option tal:repeat="possibleValue possibleValues"
tal:attributes="value python: possibleValue[0];
selected python:contextObj.fieldValueSelected(name, possibleValue[0], rawValue)"
selected python:contextObj.fieldValueSelected(name, possibleValue[0], rawValue);
title python: possibleValue[1]"
tal:content="python:tool.truncateValue(possibleValue[1], widget)"></option>
</select>
</tal:choice>
@ -100,7 +101,8 @@
<tal:comment replace="nothing">The list of values</tal:comment>
<select tal:attributes="name widgetName" multiple="multiple" size="5">
<option tal:repeat="v python:tool.getPossibleValues(name, withTranslations=True, withBlankValue=False, className=contentType)"
tal:attributes="value python:v[0]" tal:content="python: tool.truncateValue(v[1], widget)">
tal:attributes="value python:v[0]; title python: v[1]"
tal:content="python: tool.truncateValue(v[1], widget)">
</option>
</select>
</tal:selectSearch><br/>

View file

@ -1,6 +1,7 @@
# ------------------------------------------------------------------------------
import re, os, os.path, time
from appy.shared.utils import getOsTempFolder, normalizeString
import appy.pod
from appy.shared.utils import getOsTempFolder, normalizeString, executeCommand
sequenceTypes = (list, tuple)
# Classes used by edit/view templates for accessing information ----------------