|
Pour le premier point, voici (en pièce jointe) un script très simple
(arbo.py) qui initialise une arborescence à partir d'un simple texte
tabulé. Pour l'utiliser, tu poses arbo.py et init_arbo.pt dans un skin. Ensuite, tu appelles init_arbo dans le contexte où tu souhaite créé ton arborescence. (par exemple, à la racine de l'espace de pulication : http://.../site/sections/init_arbo) et tu colles le texte décrivant l'arborescence dans la zone de texte. Le texte est de la forme : Section 1 tab Sous-section 11 tab Sous-section 12 tab tab Sous-section 121 tab tab Sous-section 122 tab Sous-section 13 Section 2 tab Sous-section 21 ... Les objets créés sont tous de type "Section" mais sur la base de ce script tu peux facilement créer d'autres types de contenus. Bon courage, Pierre Anne-Laure JOUANNET a écrit :
|
##parameters=source=None
import os
import sys
from zLOG import DEBUG, INFO, LOG
from string import maketrans
from random import randrange
def getFolder(dest, title):
if title:
id = testid(title)
if not hasattr(dest, id):
dest.invokeFactory('Section', id)
ob = getattr(dest, id)
doc = ob.getEditableContent()
dico = {'Title':title}
doc.edit(dico)
return getattr(dest, id)
else:
return None
max_chars_for_id=40
def testid(compute_from):
# Create, no id, get from title
newid = compute_from.strip()[:max_chars_for_id]
# Normalization
newid = newid.replace('Æ', 'AE')
newid = newid.replace('æ', 'ae')
newid = newid.replace('¼', 'OE')
newid = newid.replace('½', 'oe')
newid = newid.replace('ß', 'ss')
tr = maketrans(
r"'\;/ &:ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ",
r'_______AAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy')
newid = newid.translate(tr)
ok = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.'
newid = ''.join([c for c in newid if c in ok])
while newid.startswith('_') or newid.startswith('.'):
newid = newid[1:]
while newid.endswith('_'):
newid = newid[:-1]
if newid:
newid = newid.lower()
else:
# Fallback if empty
newid = str(randrange(1000, 10000))
return newid
racine = dest = context
report = 'report\n'
chemin = []
if source:
arbre = source.split('\n')
niveauPrec = 0
dossierPrec = dest
for branche in arbre:
fields = branche.split('\t')
niveau = 0
while (fields[niveau]==''):
niveau = niveau+1
if niveau > niveauPrec:
niveauPrec = niveau
chemin.append(dest)
dest = dossierPrec
if niveau < niveauPrec:
dest = chemin.pop()
niveauPrec = niveau
nom = fields[niveau]
dossier = getFolder(dest, nom)
dossierPrec = dossier
report = report+str(niveau)+':'+nom+'\n'
return report
This message contains information that may be privileged or confidential and is
the property of the Capgemini Group. It is intended only for the person to whom
it is addressed. If you are not the intended recipient, you are not authorized
to read, print, retain, copy, disseminate, distribute, or use this message or
any part thereof. If you receive this message in error, please notify the
sender immediately and delete all copies of this message.
Initialisation d'une arborescence
Coller le source de l'arbre ici..._______________________________________________ cps-users-fr Adresse de la liste : [email protected] Gestion de l'abonnement : <http://lists.nuxeo.com/mailman/listinfo/cps-users-fr>
