本文整理匯總了Python中concepts.models.Concept.save方法的典型用法代碼示例。如果您正苦於以下問題:Python Concept.save方法的具體用法?Python Concept.save怎麽用?Python Concept.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類concepts.models.Concept
的用法示例。
在下文中一共展示了Concept.save方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_concept_display_name_preferred
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import save [as 別名]
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)
示例2: test_create_concept_negative__no_class
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import save [as 別名]
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()
示例3: _remote_concept
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import save [as 別名]
def _remote_concept(uri, authority):
"""
Retrieve a Concept from a remote authority service.
"""
logging.debug("Retrieve remote concept for {0}.".format(uri))
querystring = authority.retrieveformat.format(uri) # "/Concept?id="+uri
response = urllib2.urlopen(authority.host+querystring).read()
root = ET.fromstring(response)
data = {}
if len(root) > 0:
for node in root:
if node.tag == '{'+authority.namespace+'/}conceptEntry':
for sn in node:
dkey = sn.tag.replace('{'+authority.namespace+'/}','')
data[dkey] = sn.text
if sn.tag == '{'+authority.namespace+'/}type':
data['type_id'] = sn.get('type_id')
data['type_uri'] = sn.get('type_uri')
if data == {}: # Nothing retrieved
logging.warning("No such concept in ConceptAuthority for " +\
" namespace {0}".format(authority.namespace))
raise ValueError("No such concept in ConceptAuthority for " +\
" namespace {0}".format(authority.namespace))
# Get Concept type.
ctype = ConceptType.objects.get_unique(data['type'], data['type_uri'])
concept = Concept(uri=uri,
name=data['lemma'],
type=ctype,
equalto=data['equal_to'],
similarto=data['similar_to'])
concept.save()
logging.debug("Concept saved.")
# Check for geonames URI in similar_to field, and get the corresponding
# Location.
if data['similar_to'] is not None:
logging.debug("similar_to field is not empty.")
try:
location = retrieve_location(data['similar_to'])
except RuntimeError:
location = None
if location is not None:
logging.debug("Found a Location based on similar_to field")
concept.location_id = location.id
concept.save()
else:
logging.debug("No Location found.")
return concept
示例4: test_resolve
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import save [as 別名]
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')
示例5: add_concept
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import save [as 別名]
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,)))
示例6: test_create_concept_positive
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import save [as 別名]
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)
示例7: test_concept_access_changes_with_source
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import save [as 別名]
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)
示例8: ConceptVersionStaticMethodsTest
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import save [as 別名]
class ConceptVersionStaticMethodsTest(ConceptBaseTest):
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()
def test_for_concept_positive(self):
self.concept1.datatype = 'Boolean'
self.concept1.save()
label = 'version1'
version = ConceptVersion.for_concept(self.concept1, label)
self.assertEquals(label, version.mnemonic)
self.assertEquals(self.concept1, version.versioned_object)
self.assertEquals(self.concept1.concept_class, version.concept_class)
self.assertEquals(self.concept1.datatype, version.datatype)
self.assertEquals(self.concept1.names, version.names)
self.assertEquals(self.concept1.descriptions, version.descriptions)
self.assertEquals(self.concept1.retired, version.retired)
self.assertEquals(self.concept1.public_access, version.public_access)
self.assertEquals(self.concept1.external_id, version.external_id)
self.assertFalse(version.released)
def test_persist_clone_positive(self):
self.assertEquals(2, self.concept1.num_versions)
self.assertEquals(
self.concept_version, ConceptVersion.get_latest_version_of(self.concept1))
source_version = SourceVersion.get_latest_version_of(self.source1)
source_version.update_concept_version(self.concept_version)
self.assertEquals(1, len(source_version.concepts))
self.assertEquals(self.concept_version.id, source_version.concepts[0])
version2 = self.concept_version.clone()
errors = ConceptVersion.persist_clone(version2, self.user1)
self.assertEquals(0, len(errors))
self.assertEquals(3, self.concept1.num_versions)
self.assertEquals(version2, ConceptVersion.get_latest_version_of(self.concept1))
self.assertEquals(self.concept_version.public_access, version2.public_access)
self.assertEquals(self.concept_version, version2.previous_version)
self.assertEquals(self.concept_version.root_version, version2.root_version)
self.assertEquals(self.concept_version.external_id, version2.external_id)
self.assertEquals(self.user1.username, version2.version_created_by)
source_version.update_concept_version(version2)
self.assertEquals(1, len(source_version.concepts))
self.assertEquals(version2.id, source_version.concepts[0])
def test_persist_clone_negative__no_user(self):
self.assertEquals(2, self.concept1.num_versions)
self.assertEquals(
self.concept_version, ConceptVersion.get_latest_version_of(self.concept1))
source_version = SourceVersion.get_latest_version_of(self.source1)
source_version.update_concept_version(self.concept_version)
self.assertEquals(1, len(source_version.concepts))
self.assertEquals(self.concept_version.id, source_version.concepts[0])
version2 = self.concept_version.clone()
errors = ConceptVersion.persist_clone(version2)
self.assertEquals(1, len(errors))
self.assertTrue('version_created_by' in errors)
self.assertEquals(2, self.concept1.num_versions)
self.assertEquals(
self.concept_version, ConceptVersion.get_latest_version_of(self.concept1))
示例9: create_concept
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import save [as 別名]
def create_concept():
concept = Concept( name = 'namestring',
uri = 'uristring',
type = 'E21 Person' )
concept.save()
return concept
示例10: retrieve_concept
# 需要導入模塊: from concepts.models import Concept [as 別名]
# 或者: from concepts.models.Concept import save [as 別名]
def retrieve_concept(uri):
# Determine namespace and find matching ConceptAuthority.
o = urlparse(uri)
namespace = o.scheme + "://" + o.netloc
if o.scheme == '' or o.netloc == '':
logging.error("Could not determine namespace for concept {0}".format(uri))
raise ValueError("Could not determine namespace for concept {0}".format(uri))
try:
authority = ConceptAuthority.objects.filter(namespace=namespace).get()
except ObjectDoesNotExist:
logging.error("No ConceptAuthority for namespace {0}.".format(namespace))
raise RuntimeError("No ConceptAuthority for namespace {0}.".format(namespace))
# Check for existing concept before calling the authority.
try:
concept = Concept.objects.filter(uri=uri).get()
logging.debug("Concept already exists.")
except ObjectDoesNotExist:
logging.debug("Concept does not exist.")
querystring = authority.retrieveformat.format(uri) # "/Concept?id="+uri
response = urllib2.urlopen(authority.host+querystring).read()
root = ET.fromstring(response)
data = {}
if len(root) > 0:
for node in root:
if node.tag == '{'+authority.namespace+'/}conceptEntry':
for sn in node:
dkey = sn.tag.replace('{'+authority.namespace+'/}','')
data[dkey] = sn.text
if sn.tag == '{'+authority.namespace+'/}type':
data['type_id'] = sn.get('type_id')
data['type_uri'] = sn.get('type_uri')
if data == {}: # Nothing retrieved
logging.warning("No such concept in ConceptAuthority for " +\
" namespace {0}".format(authority.namespace))
raise ValueError("No such concept in ConceptAuthority for " +\
" namespace {0}".format(authority.namespace))
concept = Concept(uri=uri,
name=data['lemma'],
type=data['type'],
equalto=data['equal_to'],
similarto=data['similar_to'])
concept.save()
logging.debug("Concept saved.")
# Check for geonames URI in similar_to field, and get the corresponding
# Location.
if data['similar_to'] is not None:
logging.debug("similar_to field is not empty.")
location = retrieve_location(data['similar_to'])
if location is not None:
logging.debug("Found a Location based on similar_to field")
concept.location_id = location.id
else:
logging.debug("No Location found.")
return concept