本文整理匯總了Python中concepts.models.Concept.persist_new方法的典型用法代碼示例。如果您正苦於以下問題:Python Concept.persist_new方法的具體用法?Python Concept.persist_new怎麽用?Python Concept.persist_new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類concepts.models.Concept
的用法示例。
在下文中一共展示了Concept.persist_new方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_concept
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
def create_concept(user, source, names=None, mnemonic=None, descriptions=None, concept_class=None, datatype=None, force=False):
suffix = generate_random_string()
if not names and not force:
names = [create_localized_text("name{0}".format(suffix))]
if not mnemonic and not force:
mnemonic = 'concept{0}'.format(suffix)
if not descriptions and not force:
descriptions = [create_localized_text("desc{0}".format(suffix))]
concept = Concept(
mnemonic=mnemonic,
updated_by=user,
datatype=datatype if datatype else "None",
concept_class = concept_class if concept_class else 'Diagnosis',
names=names,
descriptions=descriptions,
)
if source is not None:
kwargs = {
'parent_resource': source,
}
errors = Concept.persist_new(concept, user, **kwargs)
else:
errors = Concept.persist_new(concept, user)
return concept, errors
示例2: test_import_job_for_change_in_data
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
def test_import_job_for_change_in_data(self):
stdout_stub = TestStream()
concept = Concept(
mnemonic='1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='Diagnosis',
external_id='1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
names=[self.name])
kwargs = {
'parent_resource': self.source1,
}
Concept.persist_new(concept, self.user1, **kwargs)
importer = ConceptsImporter(self.source1, self.testfile, 'test', stdout_stub, TestStream())
importer.import_concepts(total=1)
all_concept_versions = ConceptVersion.objects.all()
self.assertEquals(len(all_concept_versions), 2)
latest_concept_version = [version for version in all_concept_versions if version.previous_version][0]
self.assertEquals(len(latest_concept_version.names), 4)
self.assertTrue((
'Updated concept, replacing version ID ' + latest_concept_version.previous_version.id) in stdout_stub.getvalue())
self.assertTrue('concepts of 1 1 - 1 updated' in stdout_stub.getvalue())
示例3: setUp
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
def setUp(self):
super(ConceptVersionStaticMethodsTest, self).setUp()
self.concept1 = Concept(
mnemonic='concept1', concept_class='First', public_access=ACCESS_TYPE_EDIT)
display_name = LocalizedText(name='concept1', locale='en')
self.concept1.names.append(display_name)
kwargs = {
'parent_resource': self.source1,
}
Concept.persist_new(self.concept1, self.user1, **kwargs)
initial_version = ConceptVersion.get_latest_version_of(self.concept1)
self.concept2 = Concept(mnemonic='concept2', concept_class='Second', names=[self.name])
kwargs = {
'parent_resource': self.source2,
}
Concept.persist_new(self.concept2, self.user1, **kwargs)
self.concept_version = ConceptVersion(
mnemonic='version1',
versioned_object=self.concept1,
concept_class='First',
names=self.concept1.names,
previous_version=initial_version,
created_by=self.user1.username,
updated_by=self.user1.username,
version_created_by=self.user1.username,
)
self.concept_version.full_clean()
self.concept_version.save()
示例4: test_persist_new_negative__repeated_mnemonic
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
def test_persist_new_negative__repeated_mnemonic(self):
concept = Concept(
mnemonic='concept1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='First',
names=[self.name],
)
source_version = SourceVersion.get_latest_version_of(self.source1)
self.assertEquals(0, len(source_version.concepts))
kwargs = {
'parent_resource': self.source1,
}
errors = Concept.persist_new(concept, self.user1, **kwargs)
self.assertEquals(0, len(errors))
self.assertTrue(Concept.objects.filter(mnemonic='concept1').exists())
self.assertFalse(concept.retired)
self.assertEquals(self.name.name, concept.display_name)
self.assertEquals(self.name.locale, concept.display_locale)
self.assertEquals(self.source1.owner_name, concept.owner_name)
self.assertEquals(self.source1.owner_type, concept.owner_type)
self.assertEquals(self.source1.public_access, concept.public_access)
self.assertEquals(1, concept.num_versions)
concept_version = ConceptVersion.get_latest_version_of(concept)
source_version = SourceVersion.objects.get(id=source_version.id)
self.assertEquals(1, len(source_version.concepts))
self.assertTrue(concept_version.id in source_version.concepts)
# Repeat with same mnemonic
concept = Concept(
mnemonic='concept1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='First',
names=[self.name],
)
kwargs = {
'parent_resource': self.source1,
}
errors = Concept.persist_new(concept, self.user1, **kwargs)
self.assertEquals(1, len(errors))
self.assertTrue('__all__' in errors)
self.assertEquals(0, concept.num_versions)
source_version = SourceVersion.objects.get(id=source_version.id)
self.assertEquals(1, len(source_version.concepts))
示例5: test_dispatch_with_head_and_versions
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
def test_dispatch_with_head_and_versions(self):
source_version = SourceVersion(
name='version1',
mnemonic='version1',
versioned_object=self.source1,
released=True,
created_by=self.user1,
updated_by=self.user1,
)
source_version.full_clean()
source_version.save()
concept2 = Concept(
mnemonic='concept2',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='not First',
external_id='EXTID',
names=[self.name],
)
display_name = LocalizedText(
name='concept2',
locale='en'
)
concept2.names.append(display_name)
kwargs = {
'parent_resource': self.source1,
}
Concept.persist_new(concept2, self.user1, **kwargs)
self.client.login(username='user1', password='user1')
kwargs = {
'org': self.org1.mnemonic,
'source': self.source1.mnemonic
}
response = self.client.get(reverse('concept-create', kwargs=kwargs))
self.assertEquals(response.status_code, 200)
content = json.loads(response.content)
self.assertEquals(2, len(content))
source_head_concepts = SourceVersion.objects.get(mnemonic='HEAD', versioned_object_id=self.source1.id).concepts
self.assertEquals(2, len(source_head_concepts))
for concept in content:
self.assertTrue(concept['version'] in source_head_concepts)
示例6: test_update_concept_with_invalid_record
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
def test_update_concept_with_invalid_record(self):
concept = Concept(
mnemonic='1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='Diagnosis',
external_id='1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
names=[self.name])
kwargs = {
'parent_resource': self.source1,
}
Concept.persist_new(concept, self.user1, **kwargs)
self.testfile = open('./integration_tests/fixtures/concept_without_fully_specified_name.json', 'rb')
stderr_stub = TestStream()
importer = ConceptsImporter(self.source1, self.testfile, 'test', TestStream(), stderr_stub)
importer.import_concepts(total=1)
self.assertTrue('Concept requires at least one fully specified name' in stderr_stub.getvalue())
self.assertEquals(1, Concept.objects.count())
self.assertEquals(1, ConceptVersion.objects.count())
示例7: test_retire_positive
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
def test_retire_positive(self):
source_version = SourceVersion.get_latest_version_of(self.source1)
self.assertEquals(0, len(source_version.concepts))
concept = Concept(
mnemonic='concept1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='First',
names=[self.name],
)
kwargs = {
'parent_resource': self.source1,
}
errors = Concept.persist_new(concept, self.user1, **kwargs)
self.assertEquals(0, len(errors))
self.assertTrue(Concept.objects.filter(mnemonic='concept1').exists())
self.assertFalse(concept.retired)
self.assertEquals(1, concept.num_versions)
concept_version = ConceptVersion.get_latest_version_of(concept)
self.assertTrue(concept_version.is_latest_version)
self.assertFalse(concept_version.retired)
source_version = SourceVersion.get_latest_version_of(self.source1)
self.assertEquals(1, len(source_version.concepts))
self.assertEquals(concept_version.id, source_version.concepts[0])
errors = Concept.retire(concept, self.user1)
self.assertFalse(errors)
self.assertTrue(Concept.objects.filter(mnemonic='concept1').exists())
self.assertTrue(concept.retired)
self.assertEquals(2, concept.num_versions)
previous_version = ConceptVersion.objects.get(id=concept_version.id)
self.assertFalse(previous_version.is_latest_version)
self.assertFalse(previous_version.retired)
concept_version = ConceptVersion.get_latest_version_of(concept)
self.assertTrue(concept_version.is_latest_version)
self.assertTrue(concept_version.retired)
self.assertEquals(self.user1.username, concept_version.version_created_by)
source_version = SourceVersion.get_latest_version_of(self.source1)
self.assertEquals(1, len(source_version.concepts))
self.assertEquals(concept_version.id, source_version.concepts[0])
self.assertEquals(
1, ConceptVersion.objects.filter(versioned_object_id=concept.id, retired=True).count())
self.assertEquals(
1, ConceptVersion.objects.filter(versioned_object_id=concept.id, retired=False).count())
errors = Concept.retire(concept, self.user1)
self.assertEquals(1, len(errors))
示例8: test_persist_new_negative__no_parent
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
def test_persist_new_negative__no_parent(self):
concept = Concept(
mnemonic='concept1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='First',
names=[self.name],
)
source_version = SourceVersion.get_latest_version_of(self.source1)
self.assertEquals(0, len(source_version.concepts))
errors = Concept.persist_new(concept, self.user1)
self.assertEquals(1, len(errors))
self.assertTrue('parent' in errors)
self.assertFalse(Concept.objects.filter(mnemonic='concept1').exists())
self.assertEquals(0, concept.num_versions)
source_version = SourceVersion.objects.get(id=source_version.id)
self.assertEquals(0, len(source_version.concepts))
示例9: test_persist_new_positive__earlier_source_version
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
def test_persist_new_positive__earlier_source_version(self):
version1 = SourceVersion.get_latest_version_of(self.source1)
self.assertEquals(0, len(version1.concepts))
version2 = SourceVersion.for_base_object(self.source1, label='version2')
version2.save()
self.assertEquals(0, len(version2.concepts))
concept = Concept(
mnemonic='concept1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='First',
names=[self.name],
)
kwargs = {
'parent_resource': self.source1,
'parent_resource_version': version1
}
errors = Concept.persist_new(concept, self.user1, **kwargs)
self.assertEquals(0, len(errors))
self.assertTrue(Concept.objects.filter(mnemonic='concept1').exists())
self.assertFalse(concept.retired)
self.assertEquals(self.name.name, concept.display_name)
self.assertEquals(self.name.locale, concept.display_locale)
self.assertEquals(self.source1.owner_name, concept.owner_name)
self.assertEquals(self.source1.owner_type, concept.owner_type)
self.assertEquals(self.source1.public_access, concept.public_access)
self.assertEquals(1, concept.num_versions)
concept_version = ConceptVersion.get_latest_version_of(concept)
self.assertEquals(concept_version, concept_version.root_version)
version1 = SourceVersion.objects.get(id=version1.id)
self.assertEquals(1, len(version1.concepts))
self.assertTrue(concept_version.id in version1.concepts)
version2 = SourceVersion.objects.get(id=version2.id)
self.assertEquals(0, len(version2.concepts))
self.assertFalse(concept_version.id in version2.concepts)
示例10: save_object
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
def save_object(self, obj, **kwargs):
request_user = self.context['request'].user
errors = Concept.persist_new(obj, request_user, **kwargs)
self._errors.update(errors)
示例11: test_collections_version_ids
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
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', type='FULLY_SPECIFIED')],
)
kwargs = {
'parent_resource': source,
}
Concept.persist_new(concept1, self.user1, **kwargs)
fromConcept = Concept(
mnemonic='fromConcept',
created_by=self.user1,
updated_by=self.user1,
parent=source,
concept_class='First',
names=[LocalizedText.objects.create(name='User', locale='es', type='FULLY_SPECIFIED')],
)
kwargs = {
'parent_resource': source,
}
Concept.persist_new(fromConcept, self.user1, **kwargs)
toConcept = Concept(
mnemonic='toConcept',
created_by=self.user1,
updated_by=self.user1,
parent=source,
concept_class='First',
names=[LocalizedText.objects.create(name='User', locale='es', type='FULLY_SPECIFIED')],
)
kwargs = {
'parent_resource': source,
}
Concept.persist_new(toConcept, self.user1, **kwargs)
mapping = Mapping(
map_type='Same As',
from_concept=fromConcept,
to_concept=toConcept,
external_id='mapping',
)
kwargs = {
'parent_resource': source,
}
Mapping.persist_new(mapping, self.user1, **kwargs)
mapping = Mapping.objects.filter()[1]
mapping_reference = '/orgs/org1/sources/source/mappings/' + mapping.id + '/'
references = [mapping_reference]
collection.expressions = references
collection.full_clean()
collection.save()
mapping_version = MappingVersion.objects.filter()[0]
collection_version = CollectionVersion(
name='version1',
mnemonic='version1',
versioned_object=collection,
released=True,
#.........這裏部分代碼省略.........
示例12: setUp
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import persist_new [as 別名]
def setUp(self):
self.user1 = User.objects.create_user(
username='user1',
email='[email protected]',
password='user1',
last_name='One',
first_name='User'
)
self.user2 = User.objects.create_user(
username='user2',
email='[email protected]',
password='user2',
last_name='Two',
first_name='User'
)
self.userprofile1 = UserProfile.objects.create(user=self.user1, mnemonic='user1')
self.userprofile2 = UserProfile.objects.create(user=self.user2, mnemonic='user2')
self.org1 = Organization.objects.create(name='org1', mnemonic='org1')
self.org2 = Organization.objects.create(name='org2', mnemonic='org2')
add_user_to_org(self.userprofile2, self.org2)
self.source1 = Source(
name='source1',
mnemonic='source1',
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.userprofile1
}
Source.persist_new(self.source1, self.user1, **kwargs)
self.source1 = Source.objects.get(id=self.source1.id)
self.source2 = Source(
name='source2',
mnemonic='source2',
full_name='Source Two',
source_type='Reference',
public_access=ACCESS_TYPE_VIEW,
default_locale='fr',
supported_locales=['fr'],
website='www.source2.com',
description='This is the second test source',
)
kwargs = {
'parent_resource': self.org2,
}
Source.persist_new(self.source2, self.user1, **kwargs)
self.source2 = Source.objects.get(id=self.source2.id)
self.name = LocalizedText.objects.create(name='Fred', locale='en', type='FULLY_SPECIFIED')
self.concept1 = Concept(
mnemonic='concept1',
updated_by=self.user1,
parent=self.source1,
concept_class='First',
names=[self.name],
)
kwargs = {
'parent_resource': self.source1,
}
Concept.persist_new(self.concept1, self.user1, **kwargs)
self.concept2 = Concept(
mnemonic='concept2',
updated_by=self.user1,
parent=self.source1,
concept_class='Second',
names=[self.name],
)
kwargs = {
'parent_resource': self.source1,
}
Concept.persist_new(self.concept2, self.user1, **kwargs)
self.concept3 = Concept(
mnemonic='concept3',
updated_by=self.user1,
parent=self.source2,
concept_class='Third',
names=[self.name],
)
kwargs = {
'parent_resource': self.source2,
}
Concept.persist_new(self.concept3, self.user1, **kwargs)
self.concept4 = Concept(
mnemonic='concept4',
updated_by=self.user2,
parent=self.source2,
concept_class='Fourth',
#.........這裏部分代碼省略.........