def save_object(self, obj, **kwargs): request_user = self.context['request'].user errors = CollectionVersion.persist_new(obj, user=request_user, **kwargs) if errors: self._errors.update(errors) else: update_children_for_resource_version.delay(obj.id, 'collection')
def save_object(self, obj, **kwargs): request_user = self.context['request'].user snap_serializer = CollectionDetailSerializer(kwargs['versioned_object']) snapshot_data = snap_serializer.data snapshot_data.pop('references') obj.collection_snapshot = snapshot_data errors = CollectionVersion.persist_new(obj, user=request_user, **kwargs) if errors: self._errors.update(errors) else: update_children_for_resource_version.delay(obj.id, 'collection')
def save_object(self, obj, **kwargs): request_user = self.context['request'].user snap_serializer = CollectionDetailSerializer( kwargs['versioned_object']) snapshot_data = snap_serializer.data snapshot_data.pop('references') obj.collection_snapshot = snapshot_data errors = CollectionVersion.persist_new(obj, user=request_user, **kwargs) if errors: self._errors.update(errors) else: update_children_for_resource_version.delay(obj.id, 'collection')
def test_collections_version_ids(self): kwargs = {'parent_resource': self.userprofile1} collection = Collection( name='collection2', mnemonic='collection2', full_name='Collection Two', collection_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.collection2.com', description='This is the second test collection') Collection.persist_new(collection, self.user1, **kwargs) source = Source(name='source', mnemonic='source', full_name='Source One', source_type='Dictionary', public_access=ACCESS_TYPE_EDIT, default_locale='en', supported_locales=['en'], website='www.source1.com', description='This is the first test source') kwargs = {'parent_resource': self.org1} Source.persist_new(source, self.user1, **kwargs) concept1 = Concept( mnemonic='concept12', created_by=self.user1, updated_by=self.user1, parent=source, concept_class='First', names=[LocalizedText.objects.create(name='User', locale='es')], ) kwargs = { 'parent_resource': source, } Concept.persist_new(concept1, self.user1, **kwargs) another_concept = Concept( mnemonic='anotherConcept', created_by=self.user1, updated_by=self.user1, parent=source, concept_class='First', names=[LocalizedText.objects.create(name='User', locale='es')], ) kwargs = { 'parent_resource': source, } Concept.persist_new(another_concept, self.user1, **kwargs) another_concept_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get( mnemonic=another_concept.mnemonic).mnemonic + '/' concept1_reference = '/orgs/org1/sources/source/concepts/' + Concept.objects.get( mnemonic=concept1.mnemonic).mnemonic + '/' references = [concept1_reference, another_concept_reference] collection.expressions = references collection.full_clean() collection.save() concept_version = ConceptVersion.objects.get( versioned_object_id=Concept.objects.get( mnemonic=another_concept.mnemonic).id) version = CollectionVersion.for_base_object(collection, 'version1') kwargs = {} CollectionVersion.persist_new(version, **kwargs) self.assertEquals( concept_version.collection_version_ids, [CollectionVersion.objects.get(mnemonic='version1').id])
def save_object(self, obj, **kwargs): errors = CollectionVersion.persist_new(obj, **kwargs) self._errors.update(errors)