| 268 | | sm = getSecurityManager() |
|---|
| 269 | | m_tool = getToolByName(self, 'portal_membership') |
|---|
| 270 | | user = m_tool.getMemberById(username) |
|---|
| 271 | | uf = getToolByName(self, 'acl_users') |
|---|
| 272 | | if not hasattr(user, 'aq_base'): |
|---|
| 273 | | user = user.__of__(uf) |
|---|
| 274 | | newSecurityManager(None, user) |
|---|
| 275 | | |
|---|
| 276 | | sbtool = getToolByName(self, 'simpleblog_tool') |
|---|
| 277 | | |
|---|
| | 270 | sbtool = getToolByName(self, 'simpleblog_tool') |
|---|
| 280 | | media_name = struct.get('name', struct.get('name')) |
|---|
| 281 | | mime_type = struct.get('type', struct.get('type')) |
|---|
| 282 | | data = struct.get('bits', struct.get('bits')) |
|---|
| 283 | | |
|---|
| 284 | | if not 'images' in blog.objectIds(): |
|---|
| 285 | | blog.invokeFactory('BlogFolder', id = 'images', title='Container for images') |
|---|
| 286 | | images = getattr(blog, 'images') |
|---|
| 287 | | else: |
|---|
| 288 | | images = blog.images |
|---|
| 289 | | |
|---|
| | 273 | media_name = struct.get('name', None) |
|---|
| | 274 | mime_type = struct.get('type', None) |
|---|
| | 275 | data = struct.get('bits', '') |
|---|
| | 276 | |
|---|
| | 277 | if not media_name or media_name.startswith('.'): |
|---|
| | 278 | return "No 'name' of media object supply or starts with '.'" |
|---|
| | 279 | if not mime_type: |
|---|
| | 280 | return "No 'type' of media object supply" |
|---|
| 295 | | blog.images.invokeFactory('Image', id=id, title=media_name) #, file=data) |
|---|
| 296 | | image = getattr(blog.images, id) |
|---|
| 297 | | url = image.absolute_url() |
|---|
| 298 | | return url |
|---|
| | 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:] |
|---|
| | 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() |
|---|