Back to index

plone3  3.1.7
generateUniqueId.py
Go to the documentation of this file.
00001 ## Script (Python) "generateUniqueId"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=type_name=None
00008 ##title=
00009 ##
00010 from DateTime import DateTime
00011 from random import random
00012 
00013 now=DateTime()
00014 time='%s.%s' % (now.strftime('%Y-%m-%d'), str(now.millis())[7:])
00015 rand=str(random())[2:6]
00016 prefix=''
00017 suffix=''
00018 
00019 if type_name is not None:
00020     prefix = type_name.replace(' ', '_')+'.'
00021 prefix=prefix.lower()
00022 
00023 return prefix+time+rand+suffix