Changeset 280

Show
Ignore:
Timestamp:
02/22/06 14:47:45
Author:
chervol
Message:

fixes for ecto

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • SimpleBlog/branches/plone-2.0.5-Blogging-APIs/MetaWeblogAPI.py

    r279 r280  
    245245    security.declarePublic('getUserInfo') 
    246246    def getUserInfo(self, appkey, username, password): 
    247         """metaWeblog.getUserInfo returns returns a struct containing user's 
     247        """metaWeblog.getUserInfo returns a struct containing user's 
    248248        userid, firstname, lastname, nickname, email, and url.""" 
    249249        self.plone_log('metaWeblog/getUserInfo') 
     
    278278            return "No 'name' of media object supply or starts with '.'" 
    279279        if not mime_type: 
     280            #mime_type = "images/jpg" 
    280281            return "No 'type' of media object supply" 
    281282        if not (mime_type.startswith('image') or mime_type.startswith('application')): 
    282283            return "%s - not supported mime tipe." % mime_type 
    283284 
    284         try: 
    285             if not 'images' in blog.objectIds(): 
    286                 blog.invokeFactory('BlogFolder', id = 'images', title='Container for images') 
    287                 images = getattr(blog, 'images') 
     285        if not 'images' in blog.objectIds(): 
     286            blog.invokeFactory('BlogFolder', id = 'images', title='Container for images') 
     287            images = getattr(blog, 'images') 
     288        else: 
     289            images = blog.images 
     290 
     291        id = re.sub('[^A-Za-z0-9_.]', '', re.sub(' ', '_', media_name)).lower() 
     292        while id in images.objectIds(): 
     293            index = id.rfind('.') 
     294            if index > -1: 
     295                front = id[:index] 
     296                ext = id[index:] 
    288297            else: 
    289                 images = blog.images 
    290  
    291             id = re.sub('[^A-Za-z0-9_.]', '', re.sub(' ', '_', media_name)).lower() 
    292             while id in images.objectIds(): 
    293                 index = id.rfind('.') 
    294                 if index > -1: 
    295                     front = id[:index] 
    296                     ext = id[index:] 
    297                 else: 
    298                     front = id 
    299                     ext = '' 
    300                 id = front + str(random.randint(1,100)) + ext 
    301  
    302             images.invokeFactory('Image', id=id, title=media_name, file=str(data))  
    303             image = getattr(images, id) 
    304  
    305             return image.absolute_url() 
    306         except Exception, e: 
    307             return str(e) 
     298                front = id 
     299                ext = '' 
     300            id = front + str(random.randint(1,100)) + ext 
     301 
     302        images.invokeFactory('Image', id=id, title=media_name, file=str(data))  
     303        image = getattr(images, id) 
     304 
     305        return {'url':image.absolute_url()}