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.shared.data import countries
|
||||
from appy.shared.utils import Traceback, getOsTempFolder, formatNumber, \
|
||||
cleanXhtml, FileWrapper, sequenceTypes
|
||||
XhtmlCleaner, FileWrapper, sequenceTypes
|
||||
|
||||
# Default Appy permissions -----------------------------------------------------
|
||||
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
|
||||
# can't remove style-related information.
|
||||
keepStyles = self.allowImageUpload or self.richText
|
||||
value = cleanXhtml(value, keepStyles=keepStyles)
|
||||
value = XhtmlCleaner.clean(value, keepStyles=keepStyles)
|
||||
Type.store(self, obj, value)
|
||||
|
||||
def getFormattedValue(self, obj, value):
|
||||
|
|
|
@ -340,7 +340,8 @@ class BaseMixin:
|
|||
obj = self.getTool().getObject(rq['objectUid'])
|
||||
else:
|
||||
obj = self
|
||||
return obj.getMethod('on'+action)()
|
||||
if rq.get('appy', None) == '1': obj = obj.appy()
|
||||
return getattr(obj, 'on'+action)()
|
||||
|
||||
def rememberPreviousData(self):
|
||||
'''This method is called before updating an object and remembers, for
|
||||
|
|
|
@ -193,7 +193,7 @@ def executeCommand(cmd):
|
|||
return res
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
unwantedChars = ('\\', '/', ':', '*', '?', '"', '<', '>', '|', ' ', '\t')
|
||||
unwantedChars = ('\\', '/', ':', '*', '?', '"', '<', '>', '|', ' ', '\t', "'")
|
||||
alphaRex = re.compile('[a-zA-Z]')
|
||||
alphanumRex = re.compile('[a-zA-Z0-9]')
|
||||
def normalizeString(s, usage='fileName'):
|
||||
|
@ -264,20 +264,32 @@ def formatNumber(n, sep=',', precision=2, tsep=' '):
|
|||
return res
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
xhtmlClassAttr = re.compile('class\s*=\s*".*?"')
|
||||
xhtmlStyleAttr = re.compile('style\s*=\s*".*?"')
|
||||
xhtmlComment = re.compile('<!--.*?-->', re.S)
|
||||
class XhtmlCleaner:
|
||||
# Regular expressions used for cleaning.
|
||||
classAttr = re.compile('class\s*=\s*".*?"')
|
||||
comment = re.compile('<!--.*?-->', re.S)
|
||||
|
||||
def cleanXhtml(s, keepStyles=False):
|
||||
'''Returns a version of XHTML string p_s where:
|
||||
* attributes "class" and "style" have been removed (only if p_keepStyles
|
||||
is False);
|
||||
* XHTML comments have been removed.
|
||||
'''This class has 2 objectives:
|
||||
|
||||
1. The main objective is to format XHTML p_s to be storable in the ZODB
|
||||
according to Appy rules.
|
||||
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.
|
||||
'''
|
||||
@classmethod
|
||||
def clean(klass, s, keepStyles=False):
|
||||
'''Returns the cleaned variant of p_s.'''
|
||||
if not keepStyles:
|
||||
s = xhtmlClassAttr.sub('', s)
|
||||
s = xhtmlStyleAttr.sub('', s)
|
||||
s = xhtmlComment.sub('', 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
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue