[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.''' '''This script allows to check a LDAP connection.'''
import sys import sys
from appy.shared.ldap import LdapConnector from appy.shared.ldap_connector import LdapConnector
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
class LdapTester: class LdapTester:

View file

@ -38,6 +38,15 @@ def osPathJoin(*pathElems):
strings.''' strings.'''
return os.path.join(*pathElems).rstrip(os.sep) 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: class FileInfo:
'''A FileInfo instance holds metadata about a file on the filesystem. '''A FileInfo instance holds metadata about a file on the filesystem.
@ -113,14 +122,7 @@ class FileInfo:
'''Normalizes file p_name.''' '''Normalizes file p_name.'''
return name[max(name.rfind('/'), name.rfind('\\'), name.rfind(':'))+1:] return name[max(name.rfind('/'), name.rfind('\\'), name.rfind(':'))+1:]
def getShownSize(self): def getShownSize(self): return getShownSize(self.size)
'''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 replicateFile(self, src, dest): def replicateFile(self, src, dest):
'''p_src and p_dest are open file handlers. This method copies content '''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 ? # What are the output formats when generating documents from this pod ?
self.formats = formats self.formats = formats
if not formats: # Compute default ones if not formats: # Compute default ones
ext = self.getExtension(self.template[0]) self.formats = self.getAllFormats(self.template[0])
self.formats = Pod.allFormats[ext]
# Parameter "getChecked" can specify the name of a Ref field belonging # 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 # to the same gen class. If it is the case, the context of the pod
# template will contain an additional object, name "_checked", and # template will contain an additional object, name "_checked", and
@ -294,7 +293,7 @@ class Pod(Field):
def getAllFormats(self, template): def getAllFormats(self, template):
'''Gets all the output formats that are available for a given '''Gets all the output formats that are available for a given
p_template.''' p_template.'''
return self.allFormats[self.getExtension(template)] return Pod.allFormats[self.getExtension(template)]
def setTemplateFolder(self, folder): def setTemplateFolder(self, folder):
'''This methods adds a prefix to every template name in '''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.''' '''Returns, among self.template, the template(s) that can be shown.'''
res = [] res = []
if not self.showTemplate: 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: for template in self.template:
res.append(Object(template=template, res.append(Object(template=template, formats=self.formats,
formats=self.getAllFormats(template),
freezeFormats=self.getFreezeFormats(obj, template))) freezeFormats=self.getFreezeFormats(obj, template)))
else: else:
isManager = obj.user.has_role('Manager') 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 mimeTypes
from appy.shared import utils as sutils from appy.shared import utils as sutils
from appy.shared.data import languages from appy.shared.data import languages
from appy.shared.ldap import LdapConnector from appy.shared.ldap_connector import LdapConnector
try: try:
from AccessControl.ZopeSecurityPolicy import _noroles from AccessControl.ZopeSecurityPolicy import _noroles
except ImportError: except ImportError:
@ -1257,7 +1257,7 @@ class ToolMixin(BaseMixin):
def generateUid(self, className): def generateUid(self, className):
'''Generates a UID for an instance of p_className.''' '''Generates a UID for an instance of p_className.'''
name = className.split('_')[-1] name = className.split('_')[-1]
randomNumber = str(random.random()).split('.')[1] randomNumber = str(random.random()).split('.')[1].replace('e-', '')
timestamp = ('%f' % time.time()).replace('.', '') timestamp = ('%f' % time.time()).replace('.', '')
return '%s%s%s' % (name, timestamp, randomNumber) return '%s%s%s' % (name, timestamp, randomNumber)

View file

@ -171,12 +171,11 @@ class BaseMixin:
history = [] history = []
from DateTime import DateTime from DateTime import DateTime
eventToDelete = DateTime(rq['eventTime']) eventToDelete = DateTime(rq['eventTime'])
key = self.workflow_history.keys()[0] for event in self.workflow_history['appy']:
for event in self.workflow_history[key]:
if (event['action'] != '_datachange_') or \ if (event['action'] != '_datachange_') or \
(event['time'] != eventToDelete): (event['time'] != eventToDelete):
history.append(event) history.append(event)
self.workflow_history[key] = tuple(history) self.workflow_history['appy'] = tuple(history)
appy = self.appy() appy = self.appy()
self.log('data change event deleted for %s (UID=%s).' % \ self.log('data change event deleted for %s (UID=%s).' % \
(appy.klass.__name__, appy.uid)) (appy.klass.__name__, appy.uid))
@ -606,8 +605,7 @@ class BaseMixin:
event.update(kw) event.update(kw)
if 'review_state' not in event: event['review_state'] = self.State() if 'review_state' not in event: event['review_state'] = self.State()
# Add the event to the history # Add the event to the history
histKey = self.workflow_history.keys()[0] self.workflow_history['appy'] += (event,)
self.workflow_history[histKey] += (event,)
def addDataChange(self, changes, notForPreviouslyEmptyValues=False): def addDataChange(self, changes, notForPreviouslyEmptyValues=False):
'''This method allows to add "manually" a data change into the objet's '''This method allows to add "manually" a data change into the objet's
@ -1384,8 +1382,7 @@ class BaseMixin:
break break
else: else:
# Return info about the current object state # Return info about the current object state
key = self.workflow_history.keys()[0] res = self.workflow_history['appy'][-1]['review_state']
res = self.workflow_history[key][-1]['review_state']
# Return state name or state definition? # Return state name or state definition?
if name: return res if name: return res
else: return getattr(wf, 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. # will act in m_endElement, when the object will be finalized.
pass pass
elif isinstance(currentContainer, UnmarshalledFile): elif isinstance(currentContainer, UnmarshalledFile):
currentContainer.content += value or '' val = value or ''
currentContainer.content += val
currentContainer.size += len(val)
else: else:
# Current container is an object # Current container is an object
if hasattr(currentContainer, name) and \ if hasattr(currentContainer, name) and \