[gen] Created param config.groupsForGlobalRoles that disabled by default creation of a group for every global role. On a appy class it is now possible to define a static method 'generateUid' that generates a UID for every instance of this class, instead of using the standard Appy way to produce such UIDs. [shared] dav.Resource: allow to retrieve the result encoded or not in utf8.
This commit is contained in:
parent
d385b8514e
commit
88bd5e5bce
|
@ -262,6 +262,7 @@ class String(Field):
|
||||||
if letter.match(c): nv += str(ord(c.upper()) - 55)
|
if letter.match(c): nv += str(ord(c.upper()) - 55)
|
||||||
else: nv += c
|
else: nv += c
|
||||||
return int(nv) % 97 == 1
|
return int(nv) % 97 == 1
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def BIC(obj, value):
|
def BIC(obj, value):
|
||||||
'''Checks that p_value corresponds to a valid BIC number. BIC stands
|
'''Checks that p_value corresponds to a valid BIC number. BIC stands
|
||||||
|
|
|
@ -599,4 +599,6 @@ class Config:
|
||||||
self.ogone = None
|
self.ogone = None
|
||||||
# When using Google analytics, specify here the Analytics ID
|
# When using Google analytics, specify here the Analytics ID
|
||||||
self.googleAnalyticsId = None
|
self.googleAnalyticsId = None
|
||||||
|
# Create a group for every global role?
|
||||||
|
self.groupsForGlobalRoles = False
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
|
@ -608,6 +608,7 @@ class ZopeGenerator(Generator):
|
||||||
repls['ogone'] = repr(self.config.ogone)
|
repls['ogone'] = repr(self.config.ogone)
|
||||||
repls['googleAnalyticsId'] = repr(self.config.googleAnalyticsId)
|
repls['googleAnalyticsId'] = repr(self.config.googleAnalyticsId)
|
||||||
repls['activateForgotPassword'] = self.config.activateForgotPassword
|
repls['activateForgotPassword'] = self.config.activateForgotPassword
|
||||||
|
repls['groupsForGlobalRoles'] = self.config.groupsForGlobalRoles
|
||||||
self.copyFile('config.pyt', repls, destName='config.py')
|
self.copyFile('config.pyt', repls, destName='config.py')
|
||||||
|
|
||||||
def generateInit(self):
|
def generateInit(self):
|
||||||
|
|
|
@ -250,14 +250,16 @@ class ZopeInstaller:
|
||||||
appyTool.log('Group "admins" created.')
|
appyTool.log('Group "admins" created.')
|
||||||
|
|
||||||
# Create a group for every global role defined in the application
|
# Create a group for every global role defined in the application
|
||||||
for role in self.config.applicationGlobalRoles:
|
# (if required).
|
||||||
relatedGroup = '%s_group' % role
|
if self.app.config.getProductConfig().groupsForGlobalRoles:
|
||||||
if appyTool.count('Group', noSecurity=True, login=relatedGroup):
|
for role in self.config.applicationGlobalRoles:
|
||||||
continue
|
groupId = role.lower()
|
||||||
appyTool.create('groups', noSecurity=True, login=relatedGroup,
|
if appyTool.count('Group', noSecurity=True, login=groupId):
|
||||||
title=relatedGroup, roles=[role])
|
continue
|
||||||
appyTool.log('Group "%s", related to global role "%s", was ' \
|
appyTool.create('groups', noSecurity=True, login=groupId,
|
||||||
'created.' % (relatedGroup, role))
|
title=role, roles=[role])
|
||||||
|
appyTool.log('Group "%s", related to global role "%s", was ' \
|
||||||
|
'created.' % (groupId, role))
|
||||||
|
|
||||||
# Create POD templates within the tool if required
|
# Create POD templates within the tool if required
|
||||||
for contentType in self.config.attributes.iterkeys():
|
for contentType in self.config.attributes.iterkeys():
|
||||||
|
@ -307,11 +309,8 @@ class ZopeInstaller:
|
||||||
id=language, title=title)
|
id=language, title=title)
|
||||||
appyTool.log('Translation object created for "%s".' % language)
|
appyTool.log('Translation object created for "%s".' % language)
|
||||||
|
|
||||||
# Execute custom installation code if any
|
# Synchronize, if required, synchronise every Translation object with
|
||||||
if hasattr(appyTool, 'onInstall'): appyTool.onInstall()
|
# the corresponding "po" file on disk.
|
||||||
|
|
||||||
# Now, if required, we synchronise every Translation object with the
|
|
||||||
# corresponding "po" file on disk.
|
|
||||||
if appyTool.loadTranslationsAtStartup:
|
if appyTool.loadTranslationsAtStartup:
|
||||||
appFolder = self.config.diskFolder
|
appFolder = self.config.diskFolder
|
||||||
appName = self.config.PROJECTNAME
|
appName = self.config.PROJECTNAME
|
||||||
|
@ -325,6 +324,9 @@ class ZopeInstaller:
|
||||||
appyTool.log('Translation "%s" updated from "%s".' % \
|
appyTool.log('Translation "%s" updated from "%s".' % \
|
||||||
(translation.id, poName))
|
(translation.id, poName))
|
||||||
|
|
||||||
|
# Execute custom installation code if any.
|
||||||
|
if hasattr(appyTool, 'onInstall'): appyTool.onInstall()
|
||||||
|
|
||||||
def configureSessions(self):
|
def configureSessions(self):
|
||||||
'''Configure the session machinery.'''
|
'''Configure the session machinery.'''
|
||||||
# Register a function warning us when a session object is deleted. When
|
# Register a function warning us when a session object is deleted. When
|
||||||
|
|
|
@ -57,7 +57,15 @@ class BaseMixin:
|
||||||
if created and rq:
|
if created and rq:
|
||||||
# Create the final object and put it at the right place.
|
# Create the final object and put it at the right place.
|
||||||
tool = self.getTool()
|
tool = self.getTool()
|
||||||
id = tool.generateUid(obj.portal_type)
|
# The app may define a method klass.generateUid for producing an UID
|
||||||
|
# for instance of this class. If no such method is found, we use the
|
||||||
|
# standard Appy method to produce an UID.
|
||||||
|
id = None
|
||||||
|
klass = tool.getAppyClass(obj.portal_type)
|
||||||
|
if hasattr(klass, 'generateUid'):
|
||||||
|
id = klass.generateUid(obj.REQUEST)
|
||||||
|
if not id:
|
||||||
|
id = tool.generateUid(obj.portal_type)
|
||||||
if not initiator:
|
if not initiator:
|
||||||
folder = tool.getPath('/data')
|
folder = tool.getPath('/data')
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -52,6 +52,7 @@ enableSessionTimeout = <!enableSessionTimeout!>
|
||||||
discreetLogin = <!discreetLogin!>
|
discreetLogin = <!discreetLogin!>
|
||||||
ogone = <!ogone!>
|
ogone = <!ogone!>
|
||||||
googleAnalyticsId = <!googleAnalyticsId!>
|
googleAnalyticsId = <!googleAnalyticsId!>
|
||||||
|
groupsForGlobalRoles = <!groupsForGlobalRoles!>
|
||||||
|
|
||||||
# When Zope is starting or runs in test mode, there is no request object. We
|
# When Zope is starting or runs in test mode, there is no request object. We
|
||||||
# create here a fake one for storing Appy wrappers.
|
# create here a fake one for storing Appy wrappers.
|
||||||
|
|
|
@ -9,7 +9,7 @@ class GroupWrapper(AbstractWrapper):
|
||||||
def showLogin(self):
|
def showLogin(self):
|
||||||
'''When must we show the login field?'''
|
'''When must we show the login field?'''
|
||||||
if self.o.isTemporary(): return 'edit'
|
if self.o.isTemporary(): return 'edit'
|
||||||
return 'view'
|
return ('view', 'result')
|
||||||
|
|
||||||
def showGroups(self):
|
def showGroups(self):
|
||||||
'''Only the admin can view or edit roles.'''
|
'''Only the admin can view or edit roles.'''
|
||||||
|
|
|
@ -134,7 +134,11 @@ class UserWrapper(AbstractWrapper):
|
||||||
return self._callCustom('validate', new, errors)
|
return self._callCustom('validate', new, errors)
|
||||||
|
|
||||||
def onEdit(self, created):
|
def onEdit(self, created):
|
||||||
self.title = self.login
|
# Set a title for this user.
|
||||||
|
if self.firstName and self.name:
|
||||||
|
self.title = '%s %s' % (self.name, self.firstName)
|
||||||
|
else:
|
||||||
|
self.title = self.login
|
||||||
aclUsers = self.o.acl_users
|
aclUsers = self.o.acl_users
|
||||||
login = self.login
|
login = self.login
|
||||||
if created:
|
if created:
|
||||||
|
|
|
@ -68,7 +68,7 @@ class SoapDataEncoder:
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
class HttpResponse:
|
class HttpResponse:
|
||||||
'''Stores information about a HTTP response.'''
|
'''Stores information about a HTTP response.'''
|
||||||
def __init__(self, response, body, duration=None):
|
def __init__(self, response, body, duration=None, utf8=True):
|
||||||
self.code = response.status # The return code, ie 404, 200, 500...
|
self.code = response.status # The return code, ie 404, 200, 500...
|
||||||
self.text = response.reason # Textual description of the code
|
self.text = response.reason # Textual description of the code
|
||||||
self.headers = response.msg # A dict-like object containing the headers
|
self.headers = response.msg # A dict-like object containing the headers
|
||||||
|
@ -76,6 +76,7 @@ class HttpResponse:
|
||||||
# p_duration, if given, is the time, in seconds, we have waited, before
|
# p_duration, if given, is the time, in seconds, we have waited, before
|
||||||
# getting this response after having sent the request.
|
# getting this response after having sent the request.
|
||||||
self.duration = duration
|
self.duration = duration
|
||||||
|
self.utf8 = utf8
|
||||||
# The following attribute may contain specific data extracted from
|
# The following attribute may contain specific data extracted from
|
||||||
# the previous fields. For example, when response if 302 (Redirect),
|
# the previous fields. For example, when response if 302 (Redirect),
|
||||||
# self.data contains the URI where we must redirect the user to.
|
# self.data contains the URI where we must redirect the user to.
|
||||||
|
@ -108,7 +109,7 @@ class HttpResponse:
|
||||||
# Return an unmarshalled version of the XML content, for
|
# Return an unmarshalled version of the XML content, for
|
||||||
# easy use in Python.
|
# easy use in Python.
|
||||||
try:
|
try:
|
||||||
return XmlUnmarshaller().parse(self.body)
|
return XmlUnmarshaller(utf8=self.utf8).parse(self.body)
|
||||||
except xml.sax.SAXParseException, se:
|
except xml.sax.SAXParseException, se:
|
||||||
raise ResourceError('Invalid XML response (%s)'%str(se))
|
raise ResourceError('Invalid XML response (%s)'%str(se))
|
||||||
|
|
||||||
|
@ -120,7 +121,8 @@ class Resource:
|
||||||
'''Every instance of this class represents some web resource accessible
|
'''Every instance of this class represents some web resource accessible
|
||||||
through HTTP.'''
|
through HTTP.'''
|
||||||
|
|
||||||
def __init__(self, url, username=None, password=None, measure=False):
|
def __init__(self, url, username=None, password=None, measure=False,
|
||||||
|
utf8=True):
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
self.url = url
|
self.url = url
|
||||||
|
@ -142,6 +144,7 @@ class Resource:
|
||||||
# If some headers must be sent with any request sent through this
|
# If some headers must be sent with any request sent through this
|
||||||
# resource (like a cookie), you can store them in the following dict.
|
# resource (like a cookie), you can store them in the following dict.
|
||||||
self.headers = {'Host': self.host}
|
self.headers = {'Host': self.host}
|
||||||
|
self.utf8 = utf8
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Dav resource at %s>' % self.url
|
return '<Dav resource at %s>' % self.url
|
||||||
|
@ -190,7 +193,7 @@ class Resource:
|
||||||
if self.measure:
|
if self.measure:
|
||||||
duration = endTime - startTime
|
duration = endTime - startTime
|
||||||
self.serverTime += duration
|
self.serverTime += duration
|
||||||
return HttpResponse(response, body, duration=duration)
|
return HttpResponse(response, body, duration=duration, utf8=self.utf8)
|
||||||
|
|
||||||
def mkdir(self, name):
|
def mkdir(self, name):
|
||||||
'''Creates a folder named p_name in this resource.'''
|
'''Creates a folder named p_name in this resource.'''
|
||||||
|
|
Loading…
Reference in a new issue