def start(self, context, request, appstruct, **kw): root = getSite() user = get_current() proposal = context.proposal working_group = proposal.working_group author = working_group.get_member(user) copy_of_amendment = copy(context, (proposal, 'amendments'), omit=('created_at', 'modified_at', 'explanations')) copy_of_amendment.set_data(appstruct) copy_of_amendment.text = html_diff_wrapper.normalize_text( copy_of_amendment.text) copy_of_amendment.setproperty('originalentity', context) copy_of_amendment.state = PersistentList(['draft']) copy_of_amendment.setproperty('author', author) localizer = request.localizer copy_of_amendment.title = localizer.translate( _('Amended version ')) + str( getattr(proposal, '_amendments_counter', 1)) grant_roles(user=author, roles=(('Owner', copy_of_amendment), )) copy_of_amendment.text_diff = get_text_amendment_diff( proposal, copy_of_amendment) copy_of_amendment.reindex() proposal._amendments_counter = getattr(proposal, '_amendments_counter', 1) + 1 context.reindex() request.registry.notify(ActivityExecuted(self, [context], author)) return {'newcontext': copy_of_amendment}
def get_version(self, user, parent): old_version = self.version copy_of_proposal = copy( self, parent, omit=('len_selections', 'graph'), roles=True) if old_version: copy_of_proposal.setproperty('version', old_version) copy_of_proposal.init_graph() copy_of_proposal.state = PersistentList(['version', 'archived']) copy_of_proposal.setproperty('author', self.author) copy_of_proposal.setproperty('originalentity', self.originalentity) for amendment in self.amendments: copy_of_proposal.addtoproperty('amendments', amendment) for correction in self.corrections: copy_of_proposal.addtoproperty('corrections', correction) for file_ in self.attached_files: copy_of_proposal.addtoproperty('attached_files', file_) copy_of_proposal.set_related_ideas( self.related_ideas, user) copy_of_proposal.reindex() return copy_of_proposal
def start(self, context, request, appstruct, **kw): root = getSite() copy_of_amendment = copy(context, (context.proposal, 'amendments'), omit=('created_at', 'modified_at', 'explanations')) keywords_ids = appstruct.pop('keywords') result, newkeywords = root.get_keywords(keywords_ids) for nkw in newkeywords: root.addtoproperty('keywords', nkw) result.extend(newkeywords) appstruct['keywords_ref'] = result copy_of_amendment.set_data(appstruct) copy_of_amendment.text = normalize_text(copy_of_amendment.text) copy_of_amendment.setproperty('originalentity', context) copy_of_amendment.state = PersistentList(['draft']) copy_of_amendment.setproperty('author', get_current()) localizer = request.localizer # copy_of_amendment.title = context.proposal.title + \ # localizer.translate(_('_Amended version ')) + \ # str(getattr(context.proposal, # '_amendments_counter', 1)) copy_of_amendment.title = localizer.translate(_('Amended version ')) + \ str(getattr(context.proposal, '_amendments_counter', 1)) grant_roles(roles=(('Owner', copy_of_amendment), )) copy_of_amendment.text_diff = get_text_amendment_diff( context.proposal, copy_of_amendment) copy_of_amendment.reindex() context.proposal._amendments_counter = getattr(context.proposal, '_amendments_counter', 1) + 1 context.reindex() return {'newcontext': copy_of_amendment}
def start(self, context, request, appstruct, **kw): root = getSite() user = get_current() proposal = context.proposal working_group = proposal.working_group author = working_group.get_member(user) copy_of_amendment = copy(context, (proposal, 'amendments'), omit=('created_at', 'modified_at', 'explanations')) copy_of_amendment.set_data(appstruct) copy_of_amendment.text = html_diff_wrapper.normalize_text( copy_of_amendment.text) copy_of_amendment.setproperty('originalentity', context) copy_of_amendment.state = PersistentList(['draft']) copy_of_amendment.setproperty('author', author) localizer = request.localizer copy_of_amendment.title = localizer.translate( _('Amended version ')) + str(getattr(proposal, '_amendments_counter', 1)) grant_roles(user=author, roles=(('Owner', copy_of_amendment), )) copy_of_amendment.text_diff = get_text_amendment_diff( proposal, copy_of_amendment) copy_of_amendment.reindex() proposal._amendments_counter = getattr( proposal, '_amendments_counter', 1) + 1 context.reindex() request.registry.notify(ActivityExecuted(self, [context], author)) return {'newcontext': copy_of_amendment}
def start(self, context, request, appstruct, **kw): root = getSite() user = get_current() mask = user.get_mask(root) if hasattr(user, 'get_mask') else user author = mask if appstruct.pop('anonymous', False) and mask else user files = [f['_object_data'] for f in appstruct.pop('attached_files')] appstruct['attached_files'] = files copy_of_idea = copy( context, (root, 'ideas'), omit=('created_at', 'modified_at', 'opinion', 'examined_at', 'published_at', 'len_selections', 'graph')) copy_of_idea.opinion = PersistentDict({}) copy_of_idea.init_graph() copy_of_idea.setproperty('originalentity', context) copy_of_idea.state = PersistentList(['to work']) copy_of_idea.setproperty('author', author) grant_roles(user=author, roles=(('Owner', copy_of_idea), )) copy_of_idea.set_data(appstruct) copy_of_idea.modified_at = datetime.datetime.now(tz=pytz.UTC) copy_of_idea.subscribe_to_channel(user) copy_of_idea.format(request) copy_of_idea.reindex() context.reindex() request.registry.notify(ActivityExecuted( self, [context, copy_of_idea], author)) return {'newcontext': copy_of_idea}
def test_copy_composite_unique_and_role(self): container, folder, item = self._create_objects() system = self.app['principals']['users']['system'] from dace.objectofcollaboration.principal.util import (grant_roles, get_roles) grant_roles(system, (('System', folder), )) roles = get_roles(user=system, obj=folder) self.assertEqual(roles, ['System']) folder.composition_u = item from dace.util import copy foldercopy = copy(folder, container) self.assertIs(folder.composition_u, item) self.assertIs(item.shared2_u, folder) self.assertIs(foldercopy.composition_u, None) self.assertTrue(hasattr(foldercopy, '__oid__')) self.assertEqual(foldercopy.__name__, 'copy_of_folder') # verify roles weren't copied roles = get_roles(user=system, obj=foldercopy) self.assertEqual(roles, []) foldercopy2 = copy(folder, container, composite_properties=True, roles=True) self.assertEqual(foldercopy2.__name__, 'copy_of_folder-2') # no change for folder and item self.assertIs(folder.composition_u, item) self.assertIs(item.shared2_u, folder) # the copy foldercopy2 of folder contains a copy of item # which is item2 here self.assertIsNot(foldercopy2.composition_u, None) item2 = foldercopy2.composition_u self.assertIsNot(item, item2) # item2 has the same name of item self.assertEqual(item2.__name__, 'item') self.assertTrue(hasattr(item2, '__oid__')) # and the copied composition item2 point to foldercopy2 self.assertIs(item2.shared2_u, foldercopy2) # roles should be copied roles = get_roles(user=system, obj=foldercopy2) self.assertEqual(roles, ['System'])
def test_copy_composite_relations(self): container, folder, item = self._create_objects() folder.addtoproperty('composition_m', item) container['item2'] = item2 = Object2() folder.composition_u = item2 from dace.util import copy foldercopy = copy(folder, container, composite_properties=True) self.assertEqual(len(foldercopy.composition_m), 1) self.assertIsNot(foldercopy.composition_u, None)
def test_copy_composite_relations(self): container, folder, item = self._create_objects() folder.addtoproperty('composition_m', item) container['item2'] = item2 = Object2() folder.composition_u = item2 from dace.util import copy foldercopy = copy(folder, container, composite_properties=True) self.assertEqual(len(foldercopy.composition_m), 1) self.assertIsNot(foldercopy.composition_u, None)
def test_copy_composite_unique_and_role(self): container, folder, item = self._create_objects() system = self.app['principals']['users']['system'] from dace.objectofcollaboration.principal.util import ( grant_roles, get_roles) grant_roles(system, (('System', folder),)) roles = get_roles(user=system, obj=folder) self.assertEqual(roles, ['System']) folder.composition_u = item from dace.util import copy foldercopy = copy(folder, container) self.assertIs(folder.composition_u, item) self.assertIs(item.shared2_u, folder) self.assertIs(foldercopy.composition_u, None) self.assertTrue(hasattr(foldercopy, '__oid__')) self.assertEqual(foldercopy.__name__, 'copy_of_folder') # verify roles weren't copied roles = get_roles(user=system, obj=foldercopy) self.assertEqual(roles, []) foldercopy2 = copy(folder, container, composite_properties=True, roles=True) self.assertEqual(foldercopy2.__name__, 'copy_of_folder-2') # no change for folder and item self.assertIs(folder.composition_u, item) self.assertIs(item.shared2_u, folder) # the copy foldercopy2 of folder contains a copy of item # which is item2 here self.assertIsNot(foldercopy2.composition_u, None) item2 = foldercopy2.composition_u self.assertIsNot(item, item2) # item2 has the same name of item self.assertEqual(item2.__name__, 'item') self.assertTrue(hasattr(item2, '__oid__')) # and the copied composition item2 point to foldercopy2 self.assertIs(item2.shared2_u, foldercopy2) # roles should be copied roles = get_roles(user=system, obj=foldercopy2) self.assertEqual(roles, ['System'])
def test_copy_composite_relations_select_and_omit_composition_m(self): container, folder, item = self._create_objects() folder.addtoproperty('composition_m', item) container['item2'] = item2 = Object2() folder.composition_u = item2 from dace.util import copy foldercopy = copy(folder, container, composite_properties=True, omit=('composition_m',), select=('composition_m',)) # omit overrides select self.assertEqual(len(foldercopy.composition_m), 0) self.assertIs(foldercopy.composition_u, None)
def test_dont_copy_composite_multiple(self): container, folder, item = self._create_objects() folder.addtoproperty('composition_m', item) from dace.util import copy foldercopy = copy(folder, container) # no change for folder and item self.assertEqual(folder.composition_m, [item]) self.assertIs(item.shared21_u, folder) # new foldercopy is empty self.assertEqual(len(foldercopy.composition_m), 0) # The copy has been indexed in objectmap self.assertTrue(hasattr(foldercopy, '__oid__')) self.assertEqual(foldercopy.__name__, 'copy_of_folder')
def test_dont_copy_composite_multiple(self): container, folder, item = self._create_objects() folder.addtoproperty('composition_m', item) from dace.util import copy foldercopy = copy(folder, container) # no change for folder and item self.assertEqual(folder.composition_m, [item]) self.assertIs(item.shared21_u, folder) # new foldercopy is empty self.assertEqual(len(foldercopy.composition_m), 0) # The copy has been indexed in objectmap self.assertTrue(hasattr(foldercopy, '__oid__')) self.assertEqual(foldercopy.__name__, 'copy_of_folder')
def test_copy_composite_relations_select_and_omit_composition_m(self): container, folder, item = self._create_objects() folder.addtoproperty('composition_m', item) container['item2'] = item2 = Object2() folder.composition_u = item2 from dace.util import copy foldercopy = copy(folder, container, composite_properties=True, omit=('composition_m', ), select=('composition_m', )) # omit overrides select self.assertEqual(len(foldercopy.composition_m), 0) self.assertIs(foldercopy.composition_u, None)
def start(self, context, request, appstruct, **kw): root = getSite() last_version = context.version copy_of_idea = copy(context, (context, 'version'), new_name=context.__name__, select=('modified_at',), omit=('created_at',), roles=True) copy_keywords, newkeywords = root.get_keywords(context.keywords) copy_of_idea.setproperty('keywords_ref', copy_keywords) copy_of_idea.setproperty('version', last_version) copy_of_idea.setproperty('originalentity', context.originalentity) if last_version is not None: grant_roles(roles=(('Owner', last_version), )) files = [f['_object_data'] for f in appstruct.pop('attached_files')] appstruct['attached_files'] = files keywords_ids = appstruct.pop('keywords') result, newkeywords = root.get_keywords(keywords_ids) for nkw in newkeywords: root.addtoproperty('keywords', nkw) result.extend(newkeywords) appstruct['keywords_ref'] = result copy_of_idea.state = PersistentList(['archived', 'version']) copy_of_idea.setproperty('author', get_current()) note = appstruct.pop('note', '') context.note = note context.set_data(appstruct) context.modified_at = datetime.datetime.today() copy_of_idea.reindex() context.reindex() if 'archived' in context.state: recuperate_actions = getBusinessAction(context, request, 'ideamanagement', 'recuperate') if recuperate_actions: recuperate_actions[0].execute(context, request, appstruct, **kw) return {}
def test_copy_composite_multiple(self): container, folder, item = self._create_objects() folder.addtoproperty('composition_m', item) from dace.util import copy foldercopy = copy(folder, container, composite_properties=True) self.assertEqual(foldercopy.__name__, 'copy_of_folder') # no change for folder and item self.assertEqual(folder.composition_m, [item]) self.assertIs(item.shared21_u, folder) # the copy foldercopy of folder contains a copy of item # which is item2 here self.assertEqual(len(foldercopy.composition_m), 1) item2 = foldercopy.composition_m[0] self.assertIsNot(item, item2) # item2 has the same name of item self.assertEqual(item2.__name__, 'item') self.assertTrue(hasattr(item2, '__oid__')) # and the copied composition item2 point to foldercopy self.assertIs(item2.shared21_u, foldercopy)
def start(self, context, request, appstruct, **kw): root = getSite() copy_of_idea = copy(context, (root, 'ideas')) keywords_ids = appstruct.pop('keywords') result, newkeywords = root.get_keywords(keywords_ids) for nkw in newkeywords: root.addtoproperty('keywords', nkw) result.extend(newkeywords) appstruct['keywords_ref'] = result files = [f['_object_data'] for f in appstruct.pop('attached_files')] appstruct['attached_files'] = files copy_of_idea.setproperty('originalentity', context) copy_of_idea.state = PersistentList(['to work']) copy_of_idea.setproperty('author', get_current()) grant_roles(roles=(('Owner', copy_of_idea), )) copy_of_idea.set_data(appstruct) copy_of_idea.reindex() context.reindex() return {'newcontext': copy_of_idea}
def test_copy_composite_multiple(self): container, folder, item = self._create_objects() folder.addtoproperty('composition_m', item) from dace.util import copy foldercopy = copy(folder, container, composite_properties=True) self.assertEqual(foldercopy.__name__, 'copy_of_folder') # no change for folder and item self.assertEqual(folder.composition_m, [item]) self.assertIs(item.shared21_u, folder) # the copy foldercopy of folder contains a copy of item # which is item2 here self.assertEqual(len(foldercopy.composition_m), 1) item2 = foldercopy.composition_m[0] self.assertIsNot(item, item2) # item2 has the same name of item self.assertEqual(item2.__name__, 'item') self.assertTrue(hasattr(item2, '__oid__')) # and the copied composition item2 point to foldercopy self.assertIs(item2.shared21_u, foldercopy)
def start(self, context, request, appstruct, **kw): root = getSite() user = context.author last_version = context.version copy_of_idea = copy( context, (context, 'version'), new_name=context.__name__, select=('modified_at',), omit=('created_at',), roles=True) copy_of_idea.keywords = context.keywords copy_of_idea.setproperty('version', last_version) copy_of_idea.setproperty('originalentity', context.originalentity) if last_version is not None: grant_roles(user=user, roles=(('Owner', last_version), )) files = [f['_object_data'] for f in appstruct.pop('attached_files')] appstruct['attached_files'] = files copy_of_idea.state = PersistentList(['version', 'archived']) copy_of_idea.setproperty('author', user) note = appstruct.pop('note', '') context.note = note context.set_data(appstruct) context.modified_at = datetime.datetime.now(tz=pytz.UTC) copy_of_idea.reindex() context.format(request) context.reindex() if 'archived' in context.state: recuperate_actions = getBusinessAction(context, request, 'ideamanagement', 'recuperate') if recuperate_actions: recuperate_actions[0].execute(context, request, appstruct, **kw) request.registry.notify(ActivityExecuted(self, [context], user)) return {}