appy.gen: bugfixes.

This commit is contained in:
Gaetan Delannay 2012-05-09 09:45:15 +02:00
parent 8cc20b0d34
commit d3a2b85a10
3 changed files with 30 additions and 17 deletions

View file

@ -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):

View file

@ -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

View file

@ -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,20 +264,32 @@ 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.
''' '''
@classmethod
def clean(klass, s, keepStyles=False):
'''Returns the cleaned variant of p_s.'''
if not keepStyles: if not keepStyles:
s = xhtmlClassAttr.sub('', s) # Format p_s according to objective 2.
s = xhtmlStyleAttr.sub('', s) s = klass.classAttr.sub('', s)
s = xhtmlComment.sub('', s) # Format p_s according to objective 1.
s = klass.comment.sub('', s)
return s return s
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------