[gen] pod field: bugfix with attr 'formats' without method 'showTemplate'; [shared] bugfix: renamed module ldap to ldap_connector.

This commit is contained in:
Gaetan Delannay 2014-10-07 13:14:16 +02:00
parent 5ac8e71a6f
commit c2676c9cf8
7 changed files with 25 additions and 26 deletions

View file

@ -1,6 +1,6 @@
'''This script allows to check a LDAP connection.'''
import sys
from appy.shared.ldap import LdapConnector
from appy.shared.ldap_connector import LdapConnector
# ------------------------------------------------------------------------------
class LdapTester:

View file

@ -38,6 +38,15 @@ def osPathJoin(*pathElems):
strings.'''
return os.path.join(*pathElems).rstrip(os.sep)
def getShownSize(size):
'''Express p_size (a file size in bytes) in a human-readable way.'''
# Display the size in bytes if smaller than 1024 bytes
if size < 1024: return '%d byte(s)' % size
size = size / 1024.0 # This is the size, in Kb
if size < 1024: return '%s Kb' % sutils.formatNumber(size, precision=1)
size = size / 1024.0 # This is the size, in Mb
return '%s Mb' % sutils.formatNumber(size, precision=1)
# ------------------------------------------------------------------------------
class FileInfo:
'''A FileInfo instance holds metadata about a file on the filesystem.
@ -113,14 +122,7 @@ class FileInfo:
'''Normalizes file p_name.'''
return name[max(name.rfind('/'), name.rfind('\\'), name.rfind(':'))+1:]
def getShownSize(self):
'''Displays this file's size in the user interface.'''
if self.size < 1024:
# Display the size in bytes
return '%d byte(s)' % self.size
else:
# Display the size in Kb
return '%d Kb' % (self.size / 1024)
def getShownSize(self): return getShownSize(self.size)
def replicateFile(self, src, dest):
'''p_src and p_dest are open file handlers. This method copies content

View file

@ -236,8 +236,7 @@ class Pod(Field):
# What are the output formats when generating documents from this pod ?
self.formats = formats
if not formats: # Compute default ones
ext = self.getExtension(self.template[0])
self.formats = Pod.allFormats[ext]
self.formats = self.getAllFormats(self.template[0])
# Parameter "getChecked" can specify the name of a Ref field belonging
# to the same gen class. If it is the case, the context of the pod
# template will contain an additional object, name "_checked", and
@ -294,7 +293,7 @@ class Pod(Field):
def getAllFormats(self, template):
'''Gets all the output formats that are available for a given
p_template.'''
return self.allFormats[self.getExtension(template)]
return Pod.allFormats[self.getExtension(template)]
def setTemplateFolder(self, folder):
'''This methods adds a prefix to every template name in
@ -363,10 +362,9 @@ class Pod(Field):
'''Returns, among self.template, the template(s) that can be shown.'''
res = []
if not self.showTemplate:
# Show them all in any format.
# Show them all in the formats spoecified in self.formats.
for template in self.template:
res.append(Object(template=template,
formats=self.getAllFormats(template),
res.append(Object(template=template, formats=self.formats,
freezeFormats=self.getFreezeFormats(obj, template)))
else:
isManager = obj.user.has_role('Manager')

View file

@ -11,7 +11,7 @@ from appy.gen.descriptors import ClassDescriptor
from appy.shared import mimeTypes
from appy.shared import utils as sutils
from appy.shared.data import languages
from appy.shared.ldap import LdapConnector
from appy.shared.ldap_connector import LdapConnector
try:
from AccessControl.ZopeSecurityPolicy import _noroles
except ImportError:
@ -1257,7 +1257,7 @@ class ToolMixin(BaseMixin):
def generateUid(self, className):
'''Generates a UID for an instance of p_className.'''
name = className.split('_')[-1]
randomNumber = str(random.random()).split('.')[1]
randomNumber = str(random.random()).split('.')[1].replace('e-', '')
timestamp = ('%f' % time.time()).replace('.', '')
return '%s%s%s' % (name, timestamp, randomNumber)

View file

@ -171,12 +171,11 @@ class BaseMixin:
history = []
from DateTime import DateTime
eventToDelete = DateTime(rq['eventTime'])
key = self.workflow_history.keys()[0]
for event in self.workflow_history[key]:
for event in self.workflow_history['appy']:
if (event['action'] != '_datachange_') or \
(event['time'] != eventToDelete):
history.append(event)
self.workflow_history[key] = tuple(history)
self.workflow_history['appy'] = tuple(history)
appy = self.appy()
self.log('data change event deleted for %s (UID=%s).' % \
(appy.klass.__name__, appy.uid))
@ -606,8 +605,7 @@ class BaseMixin:
event.update(kw)
if 'review_state' not in event: event['review_state'] = self.State()
# Add the event to the history
histKey = self.workflow_history.keys()[0]
self.workflow_history[histKey] += (event,)
self.workflow_history['appy'] += (event,)
def addDataChange(self, changes, notForPreviouslyEmptyValues=False):
'''This method allows to add "manually" a data change into the objet's
@ -1384,8 +1382,7 @@ class BaseMixin:
break
else:
# Return info about the current object state
key = self.workflow_history.keys()[0]
res = self.workflow_history[key][-1]['review_state']
res = self.workflow_history['appy'][-1]['review_state']
# Return state name or state definition?
if name: return res
else: return getattr(wf, res)

View file

@ -417,7 +417,9 @@ class XmlUnmarshaller(XmlParser):
# will act in m_endElement, when the object will be finalized.
pass
elif isinstance(currentContainer, UnmarshalledFile):
currentContainer.content += value or ''
val = value or ''
currentContainer.content += val
currentContainer.size += len(val)
else:
# Current container is an object
if hasattr(currentContainer, name) and \