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

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

fixing tests and other minor fixes

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
11
12this_uid = context.UID()
13
14mtool = getToolByName(context, "portal_membership")
15
16home = mtool.getHomeFolder()
17if home is None:
18    mtool.createMemberArea()
19    home = mtool.getHomeFolder()
20
21new_id = context.generateUniqueId('Story')
22new_ob_id = home.invokeFactory(id=new_id, type_name='Story', title='About: '+context.Title())
23
24obj = getattr(home, new_ob_id, None)
25if not obj:
26    raise 'ops'
27
28refers = context.getRefsToResources()
29refs_to_content = []
30refs_to_activities = []
31refs_to_tools = []
32for ref in refers:
33    if ref.meta_type == 'Activity':
34        refs_to_activities.append(ref.UID())
35    elif ref.meta_type == 'Tool':
36        refs_to_tools.append(ref.UID())
37    elif ref.meta_type in ['Piece', 'Material', 'PresentationMaterial']:
38        refs_to_content.append(ref.UID())
39    else:
40        # junk in collections. what should we do?
41        pass
42
43obj.setRelatedActivities(refs_to_activities)
44obj.setRelatedTools(refs_to_tools)
45obj.setRelatedContent(refs_to_content)
46
47if return_id:
48    return new_id
49else:
50    return context.REQUEST.RESPONSE.redirect(obj.absolute_url()+'/story_edit')
Note: See TracBrowser for help on using the repository browser.