本文整理汇总了Python中openatlas.models.entity.EntityMapper.insert方法的典型用法代码示例。如果您正苦于以下问题:Python EntityMapper.insert方法的具体用法?Python EntityMapper.insert怎么用?Python EntityMapper.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openatlas.models.entity.EntityMapper
的用法示例。
在下文中一共展示了EntityMapper.insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_data
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def import_data(project, class_code, data):
from openatlas.models.entity import EntityMapper
for row in data:
system_type = None
if class_code == 'E33': # pragma: no cover
system_type = 'source content'
elif class_code == 'E18':
system_type = 'place'
desc = row['description'] if 'description' in row and row['description'] else None
entity = EntityMapper.insert(code=class_code,
name=row['name'],
description=desc,
system_type=system_type)
sql = """
INSERT INTO import.entity (project_id, origin_id, entity_id, user_id)
VALUES (%(project_id)s, %(origin_id)s, %(entity_id)s, %(user_id)s);"""
g.cursor.execute(sql, {
'project_id': project.id,
'origin_id': row['id'] if 'id' in row and row['id'] else None,
'entity_id': entity.id,
'user_id': current_user.id})
if class_code == 'E18':
location = EntityMapper.insert(
'E53', 'Location of ' + row['name'], 'place location')
entity.link('P53', location)
示例2: save_date
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def save_date(id_, form, name, code, link_mapper):
""" Saves a date taken from a form and creates links to the entity
:param id_: id of an entity of link
:param form: a form with date fields
:param name: can be a string with the values "begin" or "end"
:param code: an OpenAtlas shortcut code e.g. 'OA5'
:param link_mapper: whether to use LinkMapper (for entity) or LinkPropertyMapper (for link)
:return:
"""
from openatlas.models.entity import EntityMapper
if not getattr(form, 'date_' + name + '_year').data:
return # return because no year given
description = getattr(form, 'date_' + name + '_info').data
date = {} # put date form values in a dictionary
for item in ['year', 'month', 'day', 'year2', 'month2', 'day2']:
value = getattr(form, 'date_' + name + '_' + item).data
date[item] = int(value) if value else ''
if date['year2']: # Time span
date_from = DateMapper.form_to_datetime64(date['year'], date['month'], date['day'])
date_from = EntityMapper.insert('E61', DateMapper.datetime64_to_timestamp(date_from),
'from date value', description, date_from)
link_mapper.insert(id_, code, date_from)
date_to = DateMapper.form_to_datetime64(date['year2'], date['month2'], date['day2'])
date_to = EntityMapper.insert('E61', DateMapper.datetime64_to_timestamp(date_to),
system_type='to date value', date=date_to)
link_mapper.insert(id_, code, date_to)
else: # Exact date
date = DateMapper.form_to_datetime64(date['year'], date['month'], date['day'])
exact_date = EntityMapper.insert('E61', DateMapper.datetime64_to_timestamp(date),
'exact date value', description, date)
link_mapper.insert(id_, code, exact_date)
示例3: save
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def save(form, actor=None, code=None, origin=None):
g.cursor.execute('BEGIN')
try:
log_action = 'update'
if actor:
actor.delete_links(['P74', 'OA8', 'OA9'])
for alias in actor.get_linked_entities('P131'):
alias.delete()
else:
actor = EntityMapper.insert(code, form.name.data)
log_action = 'insert'
actor.name = form.name.data
actor.description = form.description.data
actor.update()
actor.save_dates(form)
actor.save_nodes(form)
url = url_for('actor_view', id_=actor.id)
if form.residence.data:
object_ = EntityMapper.get_by_id(form.residence.data)
actor.link('P74', object_.get_linked_entity('P53'))
if form.appears_first.data:
object_ = EntityMapper.get_by_id(form.appears_first.data)
actor.link('OA8', object_.get_linked_entity('P53'))
if form.appears_last.data:
object_ = EntityMapper.get_by_id(form.appears_last.data)
actor.link('OA9', object_.get_linked_entity('P53'))
for alias in form.alias.data:
if alias.strip(): # Check if it isn't empty
actor.link('P131', EntityMapper.insert('E82', alias))
if origin:
if origin.view_name == 'reference':
link_id = origin.link('P67', actor)
url = url_for('reference_link_update', link_id=link_id, origin_id=origin.id)
elif origin.view_name == 'source':
origin.link('P67', actor)
url = url_for('source_view', id_=origin.id) + '#tab-actor'
elif origin.view_name == 'event':
link_id = origin.link('P11', actor)
url = url_for('involvement_update', id_=link_id, origin_id=origin.id)
elif origin.view_name == 'actor':
link_id = origin.link('OA7', actor)
url = url_for('relation_update', id_=link_id, origin_id=origin.id)
if form.continue_.data == 'yes' and code:
url = url_for('actor_insert', code=code)
logger.log_user(actor.id, log_action)
g.cursor.execute('COMMIT')
flash(_('entity created') if log_action == 'insert' else _('info update'), 'info')
except Exception as e: # pragma: no cover
g.cursor.execute('ROLLBACK')
logger.log('error', 'database', 'transaction failed', e)
flash(_('error transaction'), 'error')
return redirect(url_for('actor_index'))
return url
示例4: test_member
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def test_member(self):
with app.app_context():
self.login()
with app.test_request_context():
app.preprocess_request()
actor_id = EntityMapper.insert('E21', 'Ripley').id
group_id = EntityMapper.insert('E74', 'Space Marines').id
# Add membership
rv = self.app.get(url_for('member_insert', origin_id=group_id))
assert b'Actor Function' in rv.data
data = {'group': '[' + str(group_id) + ']'}
rv = self.app.post(
url_for('membership_insert', origin_id=actor_id), data=data, follow_redirects=True)
assert b'Space Marines' in rv.data
data = {'group': '[' + str(group_id) + ']', 'continue_': 'yes'}
rv = self.app.post(
url_for('membership_insert', origin_id=actor_id), data=data, follow_redirects=True)
assert b'Space Marines' in rv.data
rv = self.app.post(
url_for('membership_insert', origin_id=group_id), data=data, follow_redirects=True)
assert b"Can't link to itself" in rv.data
rv = self.app.post(url_for('member_insert', origin_id=actor_id),
data={'actor': '[' + str(actor_id) + ']'}, follow_redirects=True)
assert b"Can't link to itself" in rv.data
# Add member to group
data = {'actor': '[' + str(actor_id) + ']'}
rv = self.app.post(
url_for('member_insert', origin_id=group_id), data=data, follow_redirects=True)
assert b'Ripley' in rv.data
data['continue_'] = 'yes'
rv = self.app.post(
url_for('member_insert', origin_id=group_id), data=data, follow_redirects=True)
assert b'Ripley' in rv.data
# Update
with app.test_request_context():
app.preprocess_request()
link_id = LinkMapper.get_links(group_id, 'P107')[0].id
rv = self.app.get(url_for('member_update', id_=link_id, origin_id=group_id))
assert b'Ripley' in rv.data
rv = self.app.post(
url_for('member_update', id_=link_id, origin_id=group_id),
data={'description': 'We are here to help you.'},
follow_redirects=True)
assert b'here to help' in rv.data
示例5: test_source
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def test_source(self):
with app.app_context():
self.login()
with app.test_request_context():
app.preprocess_request()
source_id = EntityMapper.insert('E33', 'Necronomicon', 'source content').id
rv = self.app.get(url_for('translation_insert', source_id=source_id))
assert b'+ Text' in rv.data
data = {'name': 'Test translation'}
rv = self.app.post(url_for('translation_insert', source_id=source_id), data=data)
with app.test_request_context():
app.preprocess_request()
translation_id = rv.location.split('/')[-1]
rv = self.app.get(url_for('source_view', id_=source_id))
assert b'Test translation' in rv.data
self.app.get(url_for('translation_update', id_=translation_id, source_id=source_id))
rv = self.app.post(
url_for('translation_update', id_=translation_id, source_id=source_id),
data={'name': 'Translation updated'},
follow_redirects=True)
assert b'Translation updated' in rv.data
rv = self.app.get(
url_for('translation_delete', id_=translation_id, source_id=source_id),
follow_redirects=True)
assert b'The entry has been deleted.' in rv.data
data = {'name': 'Translation continued', 'continue_': 'yes'}
self.app.post(url_for('translation_insert', source_id=source_id), data=data)
示例6: save
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def save(form, source=None, origin=None):
g.cursor.execute('BEGIN')
log_action = 'update'
try:
if not source:
source = EntityMapper.insert('E33', form.name.data, 'source content')
log_action = 'insert'
source.name = form.name.data
source.description = form.description.data
source.update()
source.save_nodes(form)
url = url_for('source_view', id_=source.id)
if origin:
url = url_for(origin.view_name + '_view', id_=origin.id) + '#tab-source'
if origin.view_name == 'reference':
link_ = origin.link('P67', source)
url = url_for('reference_link_update', link_id=link_, origin_id=origin)
elif origin.view_name == 'file':
origin.link('P67', source)
else:
source.link('P67', origin)
g.cursor.execute('COMMIT')
if form.continue_.data == 'yes':
url = url_for('source_insert', origin_id=origin.id if origin else None)
logger.log_user(source.id, log_action)
flash(_('entity created') if log_action == 'insert' else _('info update'), 'info')
except Exception as e: # pragma: no cover
g.cursor.execute('ROLLBACK')
logger.log('error', 'database', 'transaction failed', e)
flash(_('error transaction'), 'error')
url = url_for('source_insert', origin_id=origin.id if origin else None)
return url
示例7: save
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def save(form, reference=None, code=None, origin=None):
g.cursor.execute('BEGIN')
log_action = 'update'
try:
if not reference:
log_action = 'insert'
class_code = 'E84' if code == 'carrier' else 'E31'
system_type = 'information carrier' if code == 'carrier' else code
reference = EntityMapper.insert(class_code, form.name.data, system_type)
reference.name = form.name.data
reference.description = form.description.data
reference.update()
reference.save_nodes(form)
url = url_for('reference_view', id_=reference.id)
if origin:
link_id = reference.link('P67', origin)
url = url_for('reference_link_update', link_id=link_id, origin_id=origin.id)
if form.continue_.data == 'yes' and code:
url = url_for('reference_insert', code=code)
g.cursor.execute('COMMIT')
logger.log_user(reference.id, log_action)
flash(_('entity created') if log_action == 'insert' else _('info update'), 'info')
except Exception as e: # pragma: no cover
g.cursor.execute('ROLLBACK')
logger.log('error', 'database', 'transaction failed', e)
flash(_('error transaction'), 'error')
url = url_for('reference_index')
return url
示例8: test_content_and_newsletter
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def test_content_and_newsletter(self):
with app.app_context():
self.login()
self.app.post(url_for('actor_insert', code='E21'), data={'name': 'Oliver Twist'})
with app.test_request_context():
app.preprocess_request()
EntityMapper.insert('E61', '2017-04-01') # Add orphaned date
EntityMapper.insert('E31', 'One forsaken file entity', 'file') # Add orphaned file
rv = self.app.get(url_for('admin_orphans'))
assert all(x in rv.data for x in [b'Oliver Twist', b'2017-04-01', b'forsaken'])
rv = self.app.get(url_for('admin_orphans_delete', parameter='orphans'))
assert b'2017-04-01' not in rv.data
self.app.get(url_for('admin_orphans_delete', parameter='unlinked'))
self.app.get(url_for('admin_orphans_delete', parameter='types'))
self.app.get(url_for('admin_orphans_delete', parameter='whatever bogus string'))
rv = self.app.get(url_for('admin_newsletter'))
assert b'Newsletter' in rv.data
示例9: test_dates
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def test_dates(self):
self.login()
with app.app_context():
with app.test_request_context():
app.preprocess_request()
# Create invalid date links
person_a = EntityMapper.insert('E21', 'Person A')
person_b = EntityMapper.insert('E21', 'Person B')
begin_date = EntityMapper.insert('E61', 'Begin date', 'exact date value',
date='2018-01-31')
end_date = EntityMapper.insert('E61', 'End date', 'exact date value',
date='2018-01-01')
person_a.link('OA1', begin_date)
person_a.link('OA2', end_date)
relation_id = person_a.link('OA7', person_b)
LinkPropertyMapper.insert(relation_id, 'OA1', begin_date)
LinkPropertyMapper.insert(relation_id, 'OA2', end_date)
rv = self.app.get(url_for('admin_check_dates'))
assert b'Invalid dates (1)' in rv.data
assert b'Invalid link dates (1)' in rv.data
示例10: test_model
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def test_model(self):
with app.app_context():
rv = self.app.get(url_for('model_index'))
assert b'Browse' in rv.data
rv = self.app.get(url_for('class_index'))
assert b'E1' in rv.data
rv = self.app.get(url_for('class_view', code='E4'))
assert b'Domain for' in rv.data
rv = self.app.get(url_for('property_index'))
assert b'P1' in rv.data
rv = self.app.get(url_for('property_view', code='P68'))
assert b'P68' in rv.data
data = {'domain': 'E1', 'range': 'E1', 'property': 'P13'}
rv = self.app.post(url_for('model_index'), data=data)
assert b'Wrong domain' in rv.data
data = {'domain': 'E1', 'range': 'E1', 'property': 'P67'}
self.app.post(url_for('model_index'), data=data)
self.login()
with app.test_request_context(): # Insert data to display in network view
app.preprocess_request()
actor = EntityMapper.insert('E21', 'King Arthur')
event = EntityMapper.insert('E7', 'Battle of Camlann')
source = EntityMapper.insert('E33', 'Tha source')
actor.link('P11', event)
actor.link('P67', EntityMapper.insert('E89', 'Propositional Object'))
source.link('P67', event)
rv = self.app.get(url_for('model_network'))
assert b'orphans' in rv.data
data = {'orphans': True, 'width': 100, 'height': 40, 'distance': -666, 'charge': 500}
rv = self.app.post(url_for('model_network'), data=data)
assert b'666' in rv.data
# Translations
self.app.get('/index/setlocale/de')
rv = self.app.get(url_for('property_view', code='P68'))
assert b'verweist auf' in rv.data
rv = self.app.get(url_for('class_view', code='E4'))
assert b'Phase' in rv.data
示例11: save
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def save(form, event=None, code=None, origin=None):
g.cursor.execute('BEGIN')
try:
log_action = 'insert'
if event:
log_action = 'update'
event.delete_links(['P117', 'P7', 'P24'])
else:
event = EntityMapper.insert(code, form.name.data)
event.name = form.name.data
event.description = form.description.data
event.update()
event.save_dates(form)
event.save_nodes(form)
if form.event.data:
entity = EntityMapper.get_by_id(form.event.data)
event.link('P117', entity)
if form.place.data:
place = LinkMapper.get_linked_entity(int(form.place.data), 'P53')
event.link('P7', place)
if event.class_.code == 'E8' and form.given_place.data: # Link place for acquisition
places = [EntityMapper.get_by_id(i) for i in ast.literal_eval(form.given_place.data)]
event.link('P24', places)
url = url_for('event_view', id_=event.id)
if origin:
url = url_for(origin.view_name + '_view', id_=origin.id) + '#tab-event'
if origin.view_name == 'reference':
link_id = origin.link('P67', event)
url = url_for('reference_link_update', link_id=link_id, origin_id=origin.id)
elif origin.view_name == 'source':
origin.link('P67', event)
elif origin.view_name == 'actor':
link_id = event.link('P11', origin)
url = url_for('involvement_update', id_=link_id, origin_id=origin.id)
elif origin.view_name == 'file':
origin.link('P67', event)
if form.continue_.data == 'yes':
url = url_for('event_insert', code=code, origin_id=origin.id if origin else None)
g.cursor.execute('COMMIT')
logger.log_user(event.id, log_action)
flash(_('entity created') if log_action == 'insert' else _('info update'), 'info')
except Exception as e: # pragma: no cover
g.cursor.execute('ROLLBACK')
logger.log('error', 'database', 'transaction failed', e)
flash(_('error transaction'), 'error')
url = url_for('event_index')
return url
示例12: test_involvement
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def test_involvement(self):
with app.app_context():
self.login()
rv = self.app.post(url_for('event_insert', code='E8'),
data={
'name': 'Event Horizon',
'date_begin_year': '1949',
'date_begin_month': '10',
'date_begin_day': '8',
'date_end_year': '1951'})
event_id = int(rv.location.split('/')[-1])
with app.test_request_context():
app.preprocess_request()
actor_id = EntityMapper.insert('E21', 'Captain Miller').id
involvement_id = NodeMapper.get_hierarchy_by_name('Involvement').id
# Add involvement
rv = self.app.get(url_for('involvement_insert', origin_id=actor_id))
assert b'Involvement' in rv.data
data = {'event': '[' + str(event_id) + ']', 'activity': 'P11',
involvement_id: involvement_id}
rv = self.app.post(url_for('involvement_insert', origin_id=actor_id), data=data,
follow_redirects=True)
assert b'Event Horizon' in rv.data
data = {'actor': '[' + str(actor_id) + ']', 'continue_': 'yes', 'activity': 'P22'}
rv = self.app.post(url_for('involvement_insert', origin_id=event_id), data=data,
follow_redirects=True)
assert b'Event Horizon' in rv.data
self.app.get(url_for('event_view', id_=event_id))
# Update involvement
with app.test_request_context():
app.preprocess_request()
link_id = LinkMapper.get_links(event_id, 'P22')[0].id
rv = self.app.get(url_for('involvement_update', id_=link_id, origin_id=event_id))
assert b'Captain' in rv.data
rv = self.app.post(
url_for('involvement_update', id_=link_id, origin_id=actor_id),
data={'description': 'Infinite Space - Infinite Terror', 'activity': 'P23'},
follow_redirects=True)
assert b'Infinite Space - Infinite Terror' in rv.data
self.app.get(url_for('event_view', id_=event_id))
示例13: test_relation
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def test_relation(self):
with app.app_context():
self.login()
with app.test_request_context():
app.preprocess_request()
actor_id = EntityMapper.insert('E21', 'Connor MacLeod').id
related_id = EntityMapper.insert('E21', 'The Kurgan').id
# Add relationship
rv = self.app.get(url_for('relation_insert', origin_id=actor_id))
assert b'Actor Actor Relation' in rv.data
relation_id = NodeMapper.get_hierarchy_by_name('Actor Actor Relation').id
relation_sub_id = g.nodes[relation_id].subs[0]
data = {
'actor': '[' + str(related_id) + ']',
relation_id: relation_sub_id,
'inverse': None,
'date_begin_year': '-1949',
'date_begin_month': '10',
'date_begin_day': '8',
'date_begin_year2': '-1948',
'date_end_year': '2049',
'date_end_year2': '2050'}
rv = self.app.post(
url_for('relation_insert', origin_id=actor_id), data=data, follow_redirects=True)
assert b'The Kurgan' in rv.data
rv = self.app.get(url_for('node_view', id_=relation_sub_id))
assert b'Connor' in rv.data
data['continue_'] = 'yes'
data['inverse'] = True
rv = self.app.post(
url_for('relation_insert', origin_id=actor_id), data=data, follow_redirects=True)
assert b'The Kurgan' in rv.data
rv = self.app.get(url_for('actor_view', id_=actor_id))
assert b'The Kurgan' in rv.data
rv = self.app.post(
url_for('relation_insert', origin_id=related_id), data=data, follow_redirects=True)
assert b"Can't link to itself." in rv.data
# Relation types
rv = self.app.get(url_for('node_move_entities', id_=relation_sub_id))
assert b'The Kurgan' in rv.data
# Update relationship
with app.test_request_context():
app.preprocess_request()
link_id = LinkMapper.get_links(actor_id, 'OA7')[0].id
link_id2 = LinkMapper.get_links(actor_id, 'OA7', True)[0].id
rv = self.app.get(url_for('relation_update', id_=link_id, origin_id=related_id))
assert b'Connor' in rv.data
rv = self.app.post(
url_for('relation_update', id_=link_id, origin_id=actor_id),
data={'description': 'There can be only one!', 'inverse': True},
follow_redirects=True)
assert b'only one' in rv.data
rv = self.app.post(
url_for('relation_update', id_=link_id2, origin_id=actor_id),
data={'description': 'There can be only one!', 'inverse': None},
follow_redirects=True)
assert b'only one' in rv.data
示例14: test_place
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def test_place(self):
with app.app_context():
self.login()
rv = self.app.get(url_for('place_insert'))
assert b'+ Place' in rv.data
with app.test_request_context():
app.preprocess_request()
unit_node = NodeMapper.get_hierarchy_by_name('Administrative Unit')
unit_sub1 = g.nodes[unit_node.subs[0]]
unit_sub2 = g.nodes[unit_node.subs[1]]
reference_id = EntityMapper.insert('E31', 'Ancient Books', 'edition').id
place_node = NodeMapper.get_hierarchy_by_name('Place')
source_id = EntityMapper.insert('E33', 'Tha source').id
data = {'name': 'Asgard', 'alias-0': 'Valhöll',
unit_node.id: '[' + str(unit_sub1.id) + ',' + str(unit_sub2.id) + ']'}
rv = self.app.post(url_for('place_insert', origin_id=reference_id), data=data,
follow_redirects=True)
assert b'Asgard' in rv.data
gis_points = """[{"type":"Feature", "geometry":{"type":"Point", "coordinates":[9,17]},
"properties":{"name":"Valhalla","description":"","shapeType":"centerpoint"}}]"""
data['gis_points'] = gis_points
data['gis_polygons'] = """[{"geometry":{
"coordinates":[[[9.75307425847859,17.8111792731339],
[9.75315472474904,17.8110005175436],[9.75333711496205,17.8110873417098],
[9.75307425847859,17.8111792731339]]],"type":"Polygon"},
"properties":{"count":4,"description":"","id":8,"name":"",
"objectDescription":"","objectId":185,"shapeType":"Shape",
"siteType":"Settlement","title":""},"type":"Feature"}]"""
data[place_node.id] = place_node.subs
data['continue_'] = 'yes'
rv = self.app.post(
url_for('place_insert', origin_id=source_id), data=data, follow_redirects=True)
assert b'Tha source' in rv.data
with app.test_request_context():
app.preprocess_request()
places = EntityMapper.get_by_codes('place')
place_id = places[0].id
place2 = places[1]
location = place2.get_linked_entity('P53')
actor = EntityMapper.insert('E21', 'Milla Jovovich')
actor.link('P74', location)
assert b'Tha source' in rv.data
rv = self.app.get(url_for('place_index'))
assert b'Asgard' in rv.data
rv = self.app.get(url_for('place_update', id_=place_id))
assert b'Valhalla' in rv.data
data['continue_'] = ''
data['alias-1'] = 'Val-hall'
rv = self.app.post(
url_for('place_update', id_=place_id), data=data, follow_redirects=True)
assert b'Val-hall' in rv.data
with app.test_request_context():
app.preprocess_request()
event = EntityMapper.insert('E8', 'Valhalla rising')
event.link('P7', location)
event.link('P24', location)
rv = self.app.get(url_for('place_view', id_=place2.id))
assert rv.data and b'Valhalla rising' in rv.data
# Test invalid geom
data['gis_polygons'] = """[{"type": "Feature", "geometry":
{"type": "Polygon", "coordinates": [
[[298.9893436362036, -5.888919049309554], [299.00444983737543, -5.9138487869408545],
[299.00650977389887, -5.893358673645309], [298.9848804404028, -5.9070188333813585],
[298.9893436362036, -5.888919049309554]]]},
"properties": {"name": "", "description": "", "shapeType": "shape"}}]"""
rv = self.app.post(
url_for('place_insert', origin_id=source_id), data=data, follow_redirects=True)
assert b'An invalid geometry was entered' in rv.data
# Place types
rv = self.app.get(url_for('node_move_entities', id_=unit_sub1.id))
assert b'Asgard' in rv.data
# Test move entities of multiple node if link to new node exists
rv = self.app.post(url_for('node_move_entities', id_=unit_sub1.id),
data={unit_node.id: unit_sub2.id, 'selection': location.id},
follow_redirects=True)
assert b'Entities where updated' in rv.data
# Test move entities of multiple node if link to new node doesn't exists
rv = self.app.post(url_for('node_move_entities', id_=unit_sub2.id),
data={unit_node.id: unit_sub1.id, 'selection': location.id},
follow_redirects=True)
assert b'Entities where updated' in rv.data
# Subunits
with app.app_context():
self.app.get(url_for('place_insert', origin_id=place_id))
rv = self.app.post(url_for('place_insert', origin_id=place_id),
data={'name': "It's not a bug, it's a feature!"})
feat_id = rv.location.split('/')[-1]
self.app.get(url_for('place_insert', origin_id=feat_id))
self.app.get(url_for('place_update', id_=feat_id))
self.app.post(url_for('place_update', id_=feat_id),
data={'name': "It's not a bug, it's a feature!"})
rv = self.app.post(url_for('place_insert', origin_id=feat_id),
data={'name': "I'm a stratigraphic unit"})
stratigraphic_id = rv.location.split('/')[-1]
#.........这里部分代码省略.........
示例15: test_reference
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import insert [as 别名]
def test_reference(self):
with app.app_context():
self.login()
# Reference insert
rv = self.app.get(url_for('reference_insert', code='bibliography'))
assert b'+ Bibliography' in rv.data
rv = self.app.get(url_for('reference_insert', code='edition'))
assert b'+ Edition' in rv.data
rv = self.app.get(url_for('reference_insert', code='carrier'))
assert b'+ Carrier' in rv.data
data = {'name': 'Test reference', 'description': 'Reference description'}
rv = self.app.post(url_for('reference_insert', code='bibliography'), data=data)
with app.test_request_context():
app.preprocess_request()
bibliography = EntityMapper.get_by_id(rv.location.split('/')[-1])
data['continue_'] = 'yes'
rv = self.app.post(url_for('reference_insert', code='carrier'), data=data,
follow_redirects=True)
assert b'An entry has been created' in rv.data
rv = self.app.get(url_for('reference_index'))
# Reference update
assert b'Test reference' in rv.data
rv = self.app.get(url_for('reference_update', id_=bibliography.id))
assert b'Test reference' in rv.data
data['name'] = 'Test reference updated'
rv = self.app.post(url_for('reference_update', id_=bibliography.id), data=data,
follow_redirects=True)
assert b'Test reference updated' in rv.data
# Reference link
with app.test_request_context():
app.preprocess_request()
batman = EntityMapper.insert('E21', 'Batman')
rv = self.app.get(url_for('reference_add', origin_id=batman.id))
assert b'Batman' in rv.data
rv = self.app.post(url_for('reference_add', origin_id=batman.id),
data={'reference': bibliography.id}, follow_redirects=True)
assert b'Test reference updated' in rv.data
rv = self.app.get(
url_for('reference_add2', reference_id=bibliography.id, class_name='actor'))
assert b'Batman' in rv.data
rv = self.app.post(
url_for('reference_add2', reference_id=bibliography.id, class_name='actor'),
data={'actor': batman.id},
follow_redirects=True)
assert b'Test reference updated' in rv.data
# Reference link update
with app.test_request_context():
app.preprocess_request()
link_id = batman.get_links('P67', True)[0].id
file = EntityMapper.insert('E31', 'The X-Files', 'file')
file.link('P67', bibliography)
rv = self.app.post(url_for(
'reference_link_update', link_id=link_id,
origin_id=bibliography.id), data={'page': '666'}, follow_redirects=True)
assert b'Changes have been saved' in rv.data
# Reference delete
rv = self.app.get(url_for('reference_delete', id_=bibliography.id),
follow_redirects=True)
assert b'The entry has been deleted.' in rv.data