Added in shared/data some copies of external authentic data (iso country codes and belgian cities).

This commit is contained in:
Gaetan Delannay 2009-10-27 14:48:04 +01:00
parent 605c42d94e
commit cbd6fbbec5
6 changed files with 3504 additions and 21 deletions

View file

@ -4,6 +4,7 @@ from appy.gen.utils import sequenceTypes, PageDescr
# Default Appy permissions -----------------------------------------------------
r, w, d = ('read', 'write', 'delete')
digits = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
# Descriptor classes used for refining descriptions of elements in types
# (pages, groups,...) ----------------------------------------------------------
@ -138,6 +139,39 @@ class String(Type):
ALPHANUMERIC = c('[\w-]+')
URL = c('(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?' \
'(([0-9]{1,5})?\/.*)?')
# Some predefined functions that may also be used as validators
@staticmethod
def _MODULO_97(obj, value, complement=False):
'''p_value must be a string representing a number, like a bank account.
this function checks that the 2 last digits are the result of
computing the modulo 97 of the previous digits. Any non-digit
character is ignored. If p_complement is True, it does compute the
complement of modulo 97 instead of modulo 97. p_obj is not used;
it will be given by the Appy validation machinery, so it must be
specified as parameter.'''
if not value: return True # Plone calls me erroneously for
# non-mandatory fields.
# First, remove any non-digit char
v = ''
for c in value:
if c in digits: v += c
# There must be at least 3 digits for performing the check
if len(v) < 3: return False
# Separate the real number from the check digits
number = int(v[:-2])
checkNumber = int(v[-2:])
# Perform the check
if complement:
return (97 - (number % 97)) == checkNumber
else:
return (number % 97) == checkNumber
@staticmethod
def MODULO_97(obj, value): return String._MODULO_97(obj, value)
@staticmethod
def MODULO_97_COMPLEMENT(obj, value):
return String._MODULO_97(obj, value, True)
# Possible values for "format"
LINE = 0
TEXT = 1

View file

@ -343,15 +343,12 @@ class AbstractMixin:
return False
# Evaluate fieldDescr['show']
if callable(fieldDescr['show']):
obj = self._appy_getWrapper(force=True)
res = fieldDescr['show'](obj)
res = fieldDescr['show'](self.appy())
else:
res = fieldDescr['show']
# Take into account possible values 'view' and 'edit' for 'show' param.
if (res == 'view' and isEdit) or (res == 'edit' and not isEdit):
res = False
else:
res = True
return res
def getAppyFields(self, isEdit, page):
@ -904,7 +901,7 @@ class AbstractMixin:
# Apply the custom validator if it exists
validator = appyType['validator']
if not msgId and (type(validator) in self.validatorTypes):
obj = self._appy_getWrapper(force=True)
obj = self.appy()
if type(validator) == self.validatorTypes[0]:
# It is a custom function. Execute it.
try:

View file

@ -68,24 +68,17 @@ class AbstractWrapper:
else:
exec "self.o.set%s%s(v)" % (name[0].upper(), name[1:])
def __cmp__(self, other):
if other:
return cmp(self.o, other.o)
else:
return 1
def get_tool(self):
return self.o.getTool()._appy_getWrapper(force=True)
if other: return cmp(self.o, other.o)
else: return 1
def get_tool(self): return self.o.getTool().appy()
tool = property(get_tool)
def get_flavour(self):
return self.o.getTool().getFlavour(self.o, appy=True)
def get_flavour(self): return self.o.getTool().getFlavour(self.o, appy=True)
flavour = property(get_flavour)
def get_session(self):
return self.o.REQUEST.SESSION
def get_session(self): return self.o.REQUEST.SESSION
session = property(get_session)
def get_typeName(self):
return self.__class__.__bases__[-1].__name__
def get_typeName(self): return self.__class__.__bases__[-1].__name__
typeName = property(get_typeName)
def get_id(self):
return self.o.id
def get_id(self): return self.o.id
id = property(get_id)
def get_state(self):
return self.o.portal_workflow.getInfoFor(self.o, 'review_state')
@ -94,8 +87,7 @@ class AbstractWrapper:
appName = self.o.getProductConfig().PROJECTNAME
return self.o.utranslate(self.o.getWorkflowLabel(), domain=appName)
stateLabel = property(get_stateLabel)
def get_klass(self):
return self.__class__.__bases__[1]
def get_klass(self): return self.__class__.__bases__[1]
klass = property(get_klass)
def link(self, fieldName, obj):
@ -119,6 +111,14 @@ class AbstractWrapper:
sortedRefField
getattr(self.o, sortedRefField).append(obj.UID())
def sort(self, fieldName):
'''Sorts referred elements linked to p_self via p_fieldName. At
present, it can only sort elements based on their title.'''
sortedUids = getattr(self.o, '_appy_%s' % fieldName)
c = self.o.uid_catalog
sortedUids.sort(lambda x,y: \
cmp(c(UID=x)[0].getObject().Title(),c(UID=y)[0].getObject().Title()))
def create(self, fieldNameOrClass, **kwargs):
'''If p_fieldNameOfClass is the name of a field, this method allows to
create an object and link it to the current one (self) through