appy.gen: bugfixes.
This commit is contained in:
parent
8cc20b0d34
commit
d3a2b85a10
|
@ -12,7 +12,7 @@ import appy.pod
|
||||||
from appy.pod.renderer import Renderer
|
from appy.pod.renderer import Renderer
|
||||||
from appy.shared.data import countries
|
from appy.shared.data import countries
|
||||||
from appy.shared.utils import Traceback, getOsTempFolder, formatNumber, \
|
from appy.shared.utils import Traceback, getOsTempFolder, formatNumber, \
|
||||||
cleanXhtml, FileWrapper, sequenceTypes
|
XhtmlCleaner, FileWrapper, sequenceTypes
|
||||||
|
|
||||||
# Default Appy permissions -----------------------------------------------------
|
# Default Appy permissions -----------------------------------------------------
|
||||||
r, w, d = ('read', 'write', 'delete')
|
r, w, d = ('read', 'write', 'delete')
|
||||||
|
@ -1239,7 +1239,7 @@ class String(Type):
|
||||||
# (ie for image size when images are resized). So in this case we
|
# (ie for image size when images are resized). So in this case we
|
||||||
# can't remove style-related information.
|
# can't remove style-related information.
|
||||||
keepStyles = self.allowImageUpload or self.richText
|
keepStyles = self.allowImageUpload or self.richText
|
||||||
value = cleanXhtml(value, keepStyles=keepStyles)
|
value = XhtmlCleaner.clean(value, keepStyles=keepStyles)
|
||||||
Type.store(self, obj, value)
|
Type.store(self, obj, value)
|
||||||
|
|
||||||
def getFormattedValue(self, obj, value):
|
def getFormattedValue(self, obj, value):
|
||||||
|
|
|
@ -340,7 +340,8 @@ class BaseMixin:
|
||||||
obj = self.getTool().getObject(rq['objectUid'])
|
obj = self.getTool().getObject(rq['objectUid'])
|
||||||
else:
|
else:
|
||||||
obj = self
|
obj = self
|
||||||
return obj.getMethod('on'+action)()
|
if rq.get('appy', None) == '1': obj = obj.appy()
|
||||||
|
return getattr(obj, 'on'+action)()
|
||||||
|
|
||||||
def rememberPreviousData(self):
|
def rememberPreviousData(self):
|
||||||
'''This method is called before updating an object and remembers, for
|
'''This method is called before updating an object and remembers, for
|
||||||
|
|
|
@ -193,7 +193,7 @@ def executeCommand(cmd):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
unwantedChars = ('\\', '/', ':', '*', '?', '"', '<', '>', '|', ' ', '\t')
|
unwantedChars = ('\\', '/', ':', '*', '?', '"', '<', '>', '|', ' ', '\t', "'")
|
||||||
alphaRex = re.compile('[a-zA-Z]')
|
alphaRex = re.compile('[a-zA-Z]')
|
||||||
alphanumRex = re.compile('[a-zA-Z0-9]')
|
alphanumRex = re.compile('[a-zA-Z0-9]')
|
||||||
def normalizeString(s, usage='fileName'):
|
def normalizeString(s, usage='fileName'):
|
||||||
|
@ -264,21 +264,33 @@ def formatNumber(n, sep=',', precision=2, tsep=' '):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
xhtmlClassAttr = re.compile('class\s*=\s*".*?"')
|
class XhtmlCleaner:
|
||||||
xhtmlStyleAttr = re.compile('style\s*=\s*".*?"')
|
# Regular expressions used for cleaning.
|
||||||
xhtmlComment = re.compile('<!--.*?-->', re.S)
|
classAttr = re.compile('class\s*=\s*".*?"')
|
||||||
|
comment = re.compile('<!--.*?-->', re.S)
|
||||||
|
|
||||||
def cleanXhtml(s, keepStyles=False):
|
'''This class has 2 objectives:
|
||||||
'''Returns a version of XHTML string p_s where:
|
|
||||||
* attributes "class" and "style" have been removed (only if p_keepStyles
|
1. The main objective is to format XHTML p_s to be storable in the ZODB
|
||||||
is False);
|
according to Appy rules.
|
||||||
* XHTML comments have been removed.
|
a. Every <p> or <li> must be on a single line (ending with a carriage
|
||||||
|
return); else, appy.shared.diff will not be able to compute XHTML
|
||||||
|
diffs;
|
||||||
|
b. Optimize size: HTML comments are removed.
|
||||||
|
|
||||||
|
2. If p_keepStyles (or m_clean) is False, some style-related information
|
||||||
|
will be removed, in order to get a standardized content that can be
|
||||||
|
dumped in an elegant and systematic manner into a POD template.
|
||||||
'''
|
'''
|
||||||
if not keepStyles:
|
@classmethod
|
||||||
s = xhtmlClassAttr.sub('', s)
|
def clean(klass, s, keepStyles=False):
|
||||||
s = xhtmlStyleAttr.sub('', s)
|
'''Returns the cleaned variant of p_s.'''
|
||||||
s = xhtmlComment.sub('', s)
|
if not keepStyles:
|
||||||
return s
|
# Format p_s according to objective 2.
|
||||||
|
s = klass.classAttr.sub('', s)
|
||||||
|
# Format p_s according to objective 1.
|
||||||
|
s = klass.comment.sub('', s)
|
||||||
|
return s
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
def lower(s):
|
def lower(s):
|
||||||
|
|
Loading…
Reference in a new issue