[ Index ]
 

Code source de Kupu-1.3.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/plone/kupu_plone_layer/ -> kupuUploadImage.py (source)

   1  ## Script (Python) "kupuUploadImage"
   2  ##bind container=container
   3  ##bind context=context
   4  ##bind namespace=
   5  ##bind script=script
   6  ##bind subpath=traverse_subpath
   7  ##parameters=node_prop_caption, node_prop_image
   8  
   9  from Products.CMFCore.utils import getToolByName
  10  request = context.REQUEST
  11  RESPONSE =  request.RESPONSE
  12  
  13  TEMPLATE = """
  14  <html>
  15  <head></head>
  16  <body onload="window.parent.drawertool.current_drawer.%s('%s');">
  17  </body>
  18  </html>
  19  """
  20  
  21  def Error(fmt, *args):
  22      msg = fmt % args
  23      script = TEMPLATE % ('cancelUpload', msg.replace("'", "\\'"))
  24      return script
  25  
  26  kupu_tool = getToolByName(context, 'kupu_library_tool')
  27  ctr_tool = getToolByName(context, 'content_type_registry')
  28  
  29  id = request['node_prop_image'].filename
  30  linkbyuid = kupu_tool.getLinkbyuid();
  31  base = context.absolute_url()
  32  
  33  # MTR would also do content-based classification, alas, we don't want it as a dependency here
  34  # content_type= getToolByName(context,'mimetypes_registry').classify(node_prop_image)
  35  
  36  content_type = request['node_prop_image'].headers["Content-Type"]
  37  typename = ctr_tool.findTypeName(id, content_type, "")
  38  
  39  # Permission checks based on code by Danny Bloemendaal
  40  
  41  # 1) check if we are allowed to create an Image in folder 
  42  if not typename in [t.id for t in context.getAllowedTypes()]: 
  43     return Error("Creation of '%s' content is not allowed in %s", typename, context.title_or_id())
  44  
  45  # 2) check if the current user has permissions to add stuff 
  46  if not context.portal_membership.checkPermission('Add portal content',context): 
  47      return Error("You do not have permission to add content in %s", context.getId())
  48  
  49  # IE submits whole path to file, moz just the filename
  50  id = id.split("\\")[-1]
  51  
  52  # check for a bad id
  53  if context.check_id(id) is not None or getattr(context,id,None) is not None:
  54     id = context.generateUniqueId(typename)
  55  
  56  # check for a duplicate
  57  newid = context.invokeFactory(type_name=typename, id=id, title=node_prop_caption, file=node_prop_image)
  58  
  59  if newid is None or newid == '':
  60     newid = id 
  61  
  62  obj = getattr(context,newid, None)
  63  
  64  if not obj:
  65     return Error("Could not create %s with %s as id and %s as title!", typename,newid, node_prop_caption)
  66  
  67  obj.reindexObject() 
  68  if linkbyuid and hasattr(obj, 'UID'):
  69      url = base+'/resolveuid/%s' % obj.UID()
  70  else:
  71      url = obj.absolute_url()
  72  
  73  return TEMPLATE % ('finishUpload', url)
  74  
  75  


Généré le : Sun Feb 25 15:30:41 2007 par Balluche grâce à PHPXref 0.7