本文整理匯總了Python中concepts.models.Concept類的典型用法代碼示例。如果您正苦於以下問題:Python Concept類的具體用法?Python Concept怎麽用?Python Concept使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Concept類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
def setUp(self):
super(ConceptVersionTest, self).setUp()
self.concept1 = Concept(
mnemonic='concept1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='First',
external_id='EXTID',
names=[self.name],
)
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)
self.concept2 = Concept(
mnemonic='concept2',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='Second',
names=[self.name],
)
kwargs = {
'parent_resource': self.source2,
}
Concept.persist_new(self.concept2, self.user1, **kwargs)
示例2: test_concept_display_name_preferred
def test_concept_display_name_preferred(self):
concept = Concept(
mnemonic='concept1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='First',
)
display_name1 = LocalizedText(
name='concept1',
locale='en',
locale_preferred=True
)
concept.names.append(display_name1)
display_name2 = LocalizedText(
name='le concept1',
locale='fr'
)
concept.names.append(display_name2)
concept.full_clean()
concept.save()
self.assertTrue(Concept.objects.filter(mnemonic='concept1').exists())
self.assertFalse(concept.retired)
self.assertEquals(display_name1.name, concept.display_name)
self.assertEquals(display_name1.locale, concept.display_locale)
self.assertEquals(self.source1.owner_name, concept.owner_name)
self.assertEquals(self.source1.owner_type, concept.owner_type)
self.assertEquals(0, concept.num_versions)
示例3: test_import_job_for_change_in_data
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())
示例4: create_concept
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
示例5: test_retire_positive
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))
示例6: test_create_concept_negative__no_class
def test_create_concept_negative__no_class(self):
with self.assertRaises(ValidationError):
concept = Concept(
mnemonic='concept1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
names=[self.name],
)
concept.full_clean()
concept.save()
示例7: test_resolve
def test_resolve(self):
c = Concept(uri="http://www.digitalhps.org/concepts/CONe5b55803-1ef6-4abe-b81c-1493e97421df",
authority="ConceptpowerAuthority")
c.save()
resolve(Concept, c)
resolve(Type, c.typed)
self.assertTrue(hasattr(c, 'typed'))
self.assertFalse(c.typed is None)
self.assertTrue(c.resolved)
self.assertTrue(c.typed.resolved)
self.assertEqual(c.pos, 'noun')
示例8: test_persist_new_negative__repeated_mnemonic
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))
示例9: test_dispatch_with_head_and_versions
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)
示例10: test_create_concept_positive
def test_create_concept_positive(self):
concept = Concept(
mnemonic='concept1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
concept_class='First',
names=[self.name],
)
concept.full_clean()
concept.save()
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(0, concept.num_versions)
示例11: destroy
def destroy(self, request, *args, **kwargs):
self.permission_classes = (CanEditParentDictionary,)
concept = self.get_object_or_none()
if concept is None:
return Response(
{'non_field_errors': 'Could not find concept to retire'},
status=status.HTTP_404_NOT_FOUND)
errors = Concept.retire(concept, request.user)
if errors:
return Response(errors, status=status.HTTP_400_BAD_REQUEST)
return Response(status=status.HTTP_204_NO_CONTENT)
示例12: test_update_concept_with_invalid_record
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())
示例13: update_concept_retired_status
def update_concept_retired_status(self, concept, new_retired_state):
""" Updates and persists a new retired status for a concept """
# Do nothing if retired status is unchanged
concept_version = ConceptVersion.get_latest_version_of(concept)
if concept_version.retired == new_retired_state:
return ImportActionHelper.IMPORT_ACTION_NONE
# Retire/un-retire the concept
if new_retired_state:
if not self.test_mode:
errors = Concept.retire(concept, self.user)
if errors:
raise IllegalInputException('Failed to retire concept due to %s' % errors)
return ImportActionHelper.IMPORT_ACTION_RETIRE
else:
if not self.test_mode:
errors = Concept.unretire(concept, self.user)
if errors:
raise IllegalInputException('Failed to un-retire concept due to %s' % errors)
return ImportActionHelper.IMPORT_ACTION_UNRETIRE
示例14: test_concept_access_changes_with_source
def test_concept_access_changes_with_source(self):
public_access = self.source1.public_access
concept = Concept(
mnemonic='concept1',
created_by=self.user1,
updated_by=self.user1,
parent=self.source1,
public_access=public_access,
concept_class='First',
names=[self.name],
)
concept.full_clean()
concept.save()
self.assertEquals(self.source1.public_access, concept.public_access)
self.source1.public_access = ACCESS_TYPE_VIEW
self.source1.save()
concept = Concept.objects.get(id=concept.id)
self.assertNotEquals(public_access, self.source1.public_access)
self.assertEquals(self.source1.public_access, concept.public_access)
示例15: add_concept
def add_concept(request):
new_con = Concept()
new_con.title = request.POST['title']
new_con.description = request.POST['description']
new_con.pub_date = datetime.datetime.now()
new_con.date_modified = new_con.pub_date
new_con.id = bson.ObjectId()
new_con.author = request.user
cat_assoc = CategoryAssociation()
cat = Category.objects.get(id=request.POST['category_id'])
cat_assoc.category = cat
new_con.categories.append(cat_assoc)
form_properties = get_new_properties(request, True)
for form_property in form_properties:
#ugly upsert (in case its not in db)
Feature.objects(
title=form_property.title,
is_property=True,
property_type=form_property.property_type
).update_one(
set__title=form_property.title,
set__is_property=True,
set__property_type=form_property.property_type,
upsert=True)
new_feature = Feature.objects.filter(
title=form_property.title,
is_property=True,
property_type=form_property.property_type
)[0]
new_property = Property(
feature=new_feature,
property_id=bson.ObjectId(),
value=form_property.value)
new_con.properties.append(new_property)
new_con.save()
return HttpResponseRedirect(reverse('concepts:conceptdetail', args=(new_con.id,)))