Applied patch from Frederic Peters for bug https://bugs.launchpad.net/appy/+bug/485815 and another bugfix.
This commit is contained in:
parent
1227f0ed5e
commit
3a7b5be03b
6 changed files with 78 additions and 24 deletions
|
@ -2,11 +2,11 @@
|
|||
developer the real classes used by the underlying web framework.'''
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
import os, os.path, time, mimetypes, unicodedata, random
|
||||
import os, os.path, time, mimetypes, random
|
||||
import appy.pod
|
||||
from appy.gen import Search
|
||||
from appy.gen.utils import sequenceTypes
|
||||
from appy.shared.utils import getOsTempFolder, executeCommand
|
||||
from appy.shared.utils import getOsTempFolder, executeCommand, normalizeString
|
||||
from appy.shared.xml_parser import XmlMarshaller
|
||||
|
||||
# Some error messages ----------------------------------------------------------
|
||||
|
@ -256,18 +256,7 @@ class AbstractWrapper:
|
|||
def normalize(self, s, usage='fileName'):
|
||||
'''Returns a version of string p_s whose special chars have been
|
||||
replaced with normal chars.'''
|
||||
# We work in unicode. Convert p_s to unicode if not unicode.
|
||||
if isinstance(s, str): s = s.decode('utf-8')
|
||||
elif not isinstance(s, unicode): s = unicode(s)
|
||||
if usage == 'fileName':
|
||||
# Remove any char that can't be found within a file name under
|
||||
# Windows.
|
||||
res = ''
|
||||
for char in s:
|
||||
if char not in self.unwantedChars:
|
||||
res += char
|
||||
s = res
|
||||
return unicodedata.normalize('NFKD', s).encode("ascii","ignore")
|
||||
return normalizeString(s, usage)
|
||||
|
||||
def search(self, klass, sortBy='', maxResults=None, noSecurity=False,
|
||||
**fields):
|
||||
|
|
33
gen/utils.py
33
gen/utils.py
|
@ -196,4 +196,37 @@ class SomeObjects:
|
|||
if self.noSecurity: getMethod = '_unrestrictedGetObject'
|
||||
else: getMethod = 'getObject'
|
||||
self.objects = [getattr(b, getMethod)() for b in brains]
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
class Keywords:
|
||||
'''This class allows to handle keywords that a user enters and that will be
|
||||
used as basis for performing requests in a Zope ZCTextIndex.'''
|
||||
|
||||
toRemove = '?-+*()'
|
||||
def __init__(self, keywords, operator='AND'):
|
||||
# Clean the p_keywords that the user has entered.
|
||||
words = keywords.strip()
|
||||
if words == '*': words = ''
|
||||
for c in self.toRemove: words = words.replace(c, ' ')
|
||||
self.keywords = words.split()
|
||||
# Store the operator to apply to the keywords (AND or OR)
|
||||
self.operator = operator
|
||||
|
||||
def merge(self, other, append=False):
|
||||
'''Merges our keywords with those from p_other. If p_append is True,
|
||||
p_other keywords are appended at the end; else, keywords are appended
|
||||
at the begin.'''
|
||||
for word in other.keywords:
|
||||
if word not in self.keywords:
|
||||
if append:
|
||||
self.keywords.append(word)
|
||||
else:
|
||||
self.keywords.insert(0, word)
|
||||
|
||||
def get(self):
|
||||
'''Returns the keywords as needed by the ZCTextIndex.'''
|
||||
if self.keywords:
|
||||
op = ' %s ' % self.operator
|
||||
return op.join(self.keywords)+'*'
|
||||
return ''
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue