source: trunk/skins/lemill/start_story.py @ 495

Revision 495, 1.4 KB checked in by vahur, 13 years ago (diff)

made a list of content types. Also made config.py accessible from python scripts and page templates.

Line 
1## Script (Python) "useContent"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=return_id=None
8##title=Created an object in to user's home folder. type "Story".
9
10from Products.CMFCore.utils import getToolByName
11from Products.LeMill.config import CONTENT_TYPES
12
13this_uid = context.UID()
14
15mtool = getToolByName(context, "portal_membership")
16
17home = mtool.getHomeFolder()
18if home is None:
19    mtool.createMemberArea()
20    home = mtool.getHomeFolder()
21
22new_id = context.generateUniqueId('Story')
23new_ob_id = home.invokeFactory(id=new_id, type_name='Story', title='About: '+context.Title())
24
25obj = getattr(home, new_ob_id, None)
26if not obj:
27    raise 'ops'
28
29refers = context.getRefsToResources()
30refs_to_content = []
31refs_to_activities = []
32refs_to_tools = []
33for ref in refers:
34    if ref.meta_type == 'Activity':
35        refs_to_activities.append(ref.UID())
36    elif ref.meta_type == 'Tool':
37        refs_to_tools.append(ref.UID())
38    elif ref.meta_type in CONTENT_TYPES:
39        refs_to_content.append(ref.UID())
40    else:
41        # junk in collections. what should we do?
42        pass
43
44obj.setRelatedActivities(refs_to_activities)
45obj.setRelatedTools(refs_to_tools)
46obj.setRelatedContent(refs_to_content)
47
48if return_id:
49    return new_id
50else:
51    return context.REQUEST.RESPONSE.redirect(obj.absolute_url()+'/story_edit')
Note: See TracBrowser for help on using the repository browser.