Skip to content

Commit

Permalink
get title when adding topic
Browse files Browse the repository at this point in the history
refactor and simplify PasteTopic view
  • Loading branch information
rochecompaan committed Oct 18, 2012
1 parent ded445e commit 10de8b0
Showing 1 changed file with 18 additions and 33 deletions.
51 changes: 18 additions & 33 deletions collective/topictree/browser/views.py
Expand Up @@ -27,7 +27,8 @@ def __call__(self):
request = self.request
context = self.context

context_node_uid = request.get('context_node_uid', '')
context_node_uid = request.get('context_node_uid')
title = request.get('title')
if not context_node_uid:
return 'UNDEFINED'

Expand All @@ -38,7 +39,7 @@ def __call__(self):
obj = brains[0].getObject()
topic = createContentInContainer(obj,
"collective.topictree.topic",
title='New Topic')
title=title)
result = 'success'
return json.dumps({ 'result' : result,
'node_uid' : IUUID(topic) })
Expand Down Expand Up @@ -180,39 +181,23 @@ def __call__(self):
context = self.context
catalog = getToolByName(context, 'portal_catalog')

paste_uid = request.get('paste_uid', '')
cut_source_uid = request.get('cut_source_uid', '')
copy_source_uid = request.get('copy_source_uid', '')

# if cut or copy have not been clicked yet - return
if cut_source_uid == '' and copy_source_uid == '':
return

# client makes sure that only cut or copy are pressed at any given time.
# if cut node_uid has valid uid - cut was pressed
if cut_source_uid != '':
brains = catalog(UID=cut_source_uid)
obj = brains[0].getObject()
source_folder = obj.aq_parent
obj_id = brains[0].id
# cut
cp = source_folder.manage_cutObjects(obj_id)

# if copy node_uid has valid uid - copy was pressed
if copy_source_uid != '':
brains = catalog(UID=copy_source_uid)
obj = brains[0].getObject()
source_folder = obj.aq_parent
obj_id = brains[0].id
# copy
cp = source_folder.manage_copyObjects(obj_id)

# get the paste
brains2 = catalog(UID=paste_uid)
paste_folder = brains2[0].getObject()
source_uid = request.get('source_uid')
target_uid = request.get('target_uid')
is_copy = request.get('is_copy')

brains = catalog(UID=source_uid)
obj = brains[0].getObject()
if is_copy:
cp = obj.aq_parent.manage_copyObjects(obj.getId())
else:
cp = obj.aq_parent.manage_cutObjects(obj.getId())

# get the target folder
brains = catalog(UID=target_uid)
target = brains[0].getObject()

# paste
paste_folder.manage_pasteObjects(cp)
target.manage_pasteObjects(cp)

result = 'success'
return json.dumps({ 'result' : result})
Expand Down

0 comments on commit 10de8b0

Please sign in to comment.