| 1 | ## Script (Python) "add_moblog_entry2" |
|---|
| 2 | ##bind container=container |
|---|
| 3 | ##bind context=context |
|---|
| 4 | ##bind namespace= |
|---|
| 5 | ##bind script=script |
|---|
| 6 | ##bind subpath=traverse_subpath |
|---|
| 7 | ##parameters=title, body |
|---|
| 8 | ##title= |
|---|
| 9 | ## |
|---|
| 10 | # Add images |
|---|
| 11 | images = [] |
|---|
| 12 | for name, file in context.REQUEST.form.items(): |
|---|
| 13 | if name !='title' and name != 'body': |
|---|
| 14 | if file.headers['Content-Type'].startswith('image/'): |
|---|
| 15 | imageid = context.images.invokeFactory(id=name, type_name='Image') |
|---|
| 16 | context.images[imageid].setImage(file) |
|---|
| 17 | images.append(context.images[imageid]) |
|---|
| 18 | |
|---|
| 19 | # Add object |
|---|
| 20 | entry_id = script.getEntryId() |
|---|
| 21 | new_id = context.invokeFactory(id=entry_id, type_name='COREBlogEntry') |
|---|
| 22 | ent = context[entry_id] |
|---|
| 23 | |
|---|
| 24 | # Set body,title |
|---|
| 25 | ent.setContentType('text/plain','body') |
|---|
| 26 | ent.setTitle(title) |
|---|
| 27 | ent.setBody(body) |
|---|
| 28 | |
|---|
| 29 | # Set category |
|---|
| 30 | cat_id = context.getCategoryFolder()['moblog'].getInternal_id() |
|---|
| 31 | ent.setEntry_categories(str(cat_id)) |
|---|
| 32 | |
|---|
| 33 | # Add image reference and set image title |
|---|
| 34 | for i in range(len(images)): |
|---|
| 35 | image = images[i] |
|---|
| 36 | ent.addReference(image, 'relatesTo') |
|---|
| 37 | if i == 0 and len(images) == 1: |
|---|
| 38 | image.setTitle(title) |
|---|
| 39 | else: |
|---|
| 40 | image.setTitle(title + "(%d)" % (i+1)) |
|---|
| 41 | image.indexObject() |
|---|
| 42 | |
|---|
| 43 | # Set position,size |
|---|
| 44 | # 0(top), 1(left), 2(right), 3(bottom) |
|---|
| 45 | ent.setMedia_position(0) |
|---|
| 46 | # preview(400), mini(200), thumb(128), tile(64) |
|---|
| 47 | ent.setMedia_size('mini') |
|---|
| 48 | |
|---|
| 49 | # Index entry |
|---|
| 50 | ent.indexObject() |
|---|
| 51 | |
|---|
| 52 | # Publish entry |
|---|
| 53 | ent.content_status_modify(workflow_action='publish') |
|---|