本文整理汇总了Python中openatlas.models.entity.EntityMapper.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python EntityMapper.get_by_id方法的具体用法?Python EntityMapper.get_by_id怎么用?Python EntityMapper.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openatlas.models.entity.EntityMapper
的用法示例。
在下文中一共展示了EntityMapper.get_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: involvement_update
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def involvement_update(id_, origin_id):
link_ = LinkMapper.get_by_id(id_)
event = EntityMapper.get_by_id(link_.domain.id)
actor = EntityMapper.get_by_id(link_.range.id)
origin = event if origin_id == event.id else actor
form = build_form(ActorForm, 'Involvement', link_, request)
form.save.label.text = _('save')
del form.actor, form.event, form.insert_and_continue
form.activity.choices = [('P11', g.properties['P11'].name)]
if event.class_.code in ['E7', 'E8', 'E12']:
form.activity.choices.append(('P14', g.properties['P14'].name))
if event.class_.code == 'E8':
form.activity.choices.append(('P22', g.properties['P22'].name))
form.activity.choices.append(('P23', g.properties['P23'].name))
if form.validate_on_submit():
g.cursor.execute('BEGIN')
try:
link_.delete()
link_id = event.link(form.activity.data, actor, form.description.data)
DateMapper.save_link_dates(link_id, form)
NodeMapper.save_link_nodes(link_id, form)
g.cursor.execute('COMMIT')
except Exception as e: # pragma: no cover
g.cursor.execute('ROLLBACK')
logger.log('error', 'database', 'transaction failed', e)
flash(_('error transaction'), 'error')
tab = 'actor' if origin.view_name == 'event' else 'event'
return redirect(url_for(origin.view_name + '_view', id_=origin.id) + '#tab-' + tab)
form.activity.data = link_.property.code
form.description.data = link_.description
link_.set_dates()
form.populate_dates(link_)
return render_template('involvement/update.html', origin=origin, form=form,
linked_object=event if origin_id != event.id else actor)
示例2: relation_update
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def relation_update(id_, origin_id):
link_ = LinkMapper.get_by_id(id_)
domain = EntityMapper.get_by_id(link_.domain.id)
range_ = EntityMapper.get_by_id(link_.range.id)
origin = range_ if origin_id == range_.id else domain
related = range_ if origin_id == domain.id else domain
form = build_form(RelationForm, 'Actor Actor Relation', link_, request)
del form.actor, form.insert_and_continue, form.origin_id
if form.validate_on_submit():
g.cursor.execute('BEGIN')
try:
link_.delete()
if form.inverse.data:
link_id = related.link('OA7', origin, form.description.data)
else:
link_id = origin.link('OA7', related, form.description.data)
DateMapper.save_link_dates(link_id, form)
NodeMapper.save_link_nodes(link_id, form)
g.cursor.execute('COMMIT')
flash(_('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_view', id_=origin.id) + '#tab-relation')
if origin.id == range_.id:
form.inverse.data = True
form.save.label.text = _('save')
link_.set_dates()
form.populate_dates(link_)
return render_template('relation/update.html', origin=origin, form=form, related=related)
示例3: node_view
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def node_view(id_):
from openatlas.models.linkProperty import LinkPropertyMapper
node = g.nodes[id_]
root = g.nodes[node.root[-1]] if node.root else None
super_ = g.nodes[node.root[0]] if node.root else None
header = [_('name'), _('class'), _('info')]
if root and root.value_type: # pragma: no cover
header = [_('name'), _('value'), _('class'), _('info')]
tables = {'entities': {'id': 'entities', 'header': header, 'data': []},
'info': get_entity_data(node)}
for entity in node.get_linked_entities(['P2', 'P89'], True):
# If it is a place location get the corresponding object
entity = entity if node.class_.code == 'E55' else entity.get_linked_entity('P53', True)
if entity: # If not entity it is a place node, so do not add
data = [link(entity)]
if root and root.value_type: # pragma: no cover
data.append(format_number(entity.nodes[node]))
data.append(g.classes[entity.class_.code].name)
data.append(truncate_string(entity.description))
tables['entities']['data'].append(data)
tables['link_entities'] = {'id': 'link_items', 'header': [_('domain'), _('range')], 'data': []}
for row in LinkPropertyMapper.get_entities_by_node(node):
tables['link_entities']['data'].append([link(EntityMapper.get_by_id(row.domain_id)),
link(EntityMapper.get_by_id(row.range_id))])
tables['subs'] = {'id': 'subs', 'header': [_('name'), _('count'), _('info')], 'data': []}
for sub_id in node.subs:
sub = g.nodes[sub_id]
tables['subs']['data'].append([link(sub), sub.count, truncate_string(sub.description)])
return render_template('types/view.html', node=node, super_=super_, tables=tables, root=root)
示例4: member_update
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def member_update(id_, origin_id):
link_ = LinkMapper.get_by_id(id_)
domain = EntityMapper.get_by_id(link_.domain.id)
range_ = EntityMapper.get_by_id(link_.range.id)
origin = range_ if origin_id == range_.id else domain
form = build_form(MemberForm, 'Member', link_, request)
del form.actor, form.group, form.insert_and_continue
if form.validate_on_submit():
g.cursor.execute('BEGIN')
try:
link_.delete()
link_id = domain.link('P107', range_, form.description.data)
DateMapper.save_link_dates(link_id, form)
NodeMapper.save_link_nodes(link_id, form)
g.cursor.execute('COMMIT')
except Exception as e: # pragma: no cover
g.cursor.execute('ROLLBACK')
logger.log('error', 'database', 'transaction failed', e)
flash(_('error transaction'), 'error')
tab = '#tab-member-of' if origin.id == range_.id else '#tab-member'
return redirect(url_for('actor_view', id_=origin.id) + tab)
form.save.label.text = _('save')
link_.set_dates()
form.populate_dates(link_)
related = range_ if origin_id == domain.id else domain
return render_template('member/update.html', origin=origin, form=form, related=related)
示例5: build_move_form
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def build_move_form(form, node) -> Form:
root = g.nodes[node.root[-1]]
setattr(form, str(root.id), TreeField(str(root.id)))
form_instance = form(obj=node)
# Delete custom fields except the ones specified for the form
delete_list = [] # Can't delete fields in the loop so creating a list for later deletion
for field in form_instance:
if type(field) is TreeField and int(field.id) != root.id:
delete_list.append(field.id)
for item in delete_list:
delattr(form_instance, item)
choices = []
if root.class_.code == 'E53':
for entity in node.get_linked_entities('P89', True):
place = entity.get_linked_entity('P53', True)
if place:
choices.append((entity.id, place.name))
elif root.name in app.config['PROPERTY_TYPES']:
for row in LinkMapper.get_entities_by_node(node):
domain = EntityMapper.get_by_id(row.domain_id)
range_ = EntityMapper.get_by_id(row.range_id)
choices.append((row.id, domain.name + ' - ' + range_.name))
else:
for entity in node.get_linked_entities('P2', True):
choices.append((entity.id, entity.name))
form_instance.selection.choices = choices
return form_instance
示例6: reference_add
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def reference_add(origin_id):
""" Link an entity to reference coming from the entity."""
origin = EntityMapper.get_by_id(origin_id)
form = AddReferenceForm()
if form.validate_on_submit():
EntityMapper.get_by_id(form.reference.data).link('P67', origin, form.page.data)
return redirect(url_for(origin.view_name + '_view', id_=origin.id) + '#tab-reference')
return render_template('reference/add.html', origin=origin, form=form)
示例7: reference_add2
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def reference_add2(reference_id, class_name):
""" Link an entity to reference coming from the reference."""
reference_ = EntityMapper.get_by_id(reference_id)
form = getattr(openatlas.views.reference, 'Add' + uc_first(class_name) + 'Form')()
if form.validate_on_submit():
property_code = 'P128' if reference_.class_.code == 'E84' else 'P67'
entity = EntityMapper.get_by_id(getattr(form, class_name).data)
reference_.link(property_code, entity, form.page.data)
return redirect(url_for('reference_view', id_=reference_.id) + '#tab-' + class_name)
return render_template('reference/add2.html', reference=reference_, form=form,
class_name=class_name)
示例8: save
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [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
示例9: index
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def index():
tables = {
'counts': {'id': 'overview', 'header': [], 'data': [], 'show_pager': False},
'bookmarks': {'id': 'bookmarks', 'data': [], 'show_pager': False,
'header': ['name', 'class', 'first', 'last']},
'latest': {'id': 'latest', 'data': [], 'show_pager': False,
'header': ['name', 'class', 'first', 'last', 'date', 'user']}}
if current_user.is_authenticated and hasattr(current_user, 'bookmarks'):
for entity_id in current_user.bookmarks:
entity = EntityMapper.get_by_id(entity_id)
tables['bookmarks']['data'].append([
link(entity),
g.classes[entity.class_.code].name,
entity.first,
entity.last,
bookmark_toggle(entity.id, True)])
for name, count in EntityMapper.get_overview_counts().items():
count = format_number(count) if count else ''
tables['counts']['data'].append([
'<a href="' + url_for(name + '_index') + '">' + uc_first(_(name)) + '</a>', count])
for entity in EntityMapper.get_latest(8):
tables['latest']['data'].append([
link(entity),
g.classes[entity.class_.code].name,
entity.first,
entity.last,
format_date(entity.created),
link(logger.get_log_for_advanced_view(entity.id)['creator'])])
intro = ContentMapper.get_translation('intro')
return render_template('index/index.html', intro=intro, tables=tables)
示例10: reference_view
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def reference_view(id_):
reference = EntityMapper.get_by_id(id_)
tables = {
'info': get_entity_data(reference),
'file': {'id': 'files', 'data': [],
'header': app.config['TABLE_HEADERS']['file'] + ['page'] + [_('main image')]}}
for name in ['source', 'event', 'actor', 'place', 'feature', 'stratigraphic-unit', 'find']:
header = app.config['TABLE_HEADERS'][name] + ['page']
tables[name] = {'id': name, 'header': header, 'data': []}
for link_ in reference.get_links('P67', True):
domain = link_.domain
data = get_base_table_data(domain)
if is_authorized('editor'):
url = url_for('link_delete', id_=link_.id, origin_id=reference.id) + '#tab-file'
data.append(display_remove_link(url, domain.name))
tables['file']['data'].append(data)
profile_image_id = reference.get_profile_image_id()
for link_ in reference.get_links(['P67', 'P128']):
range_ = link_.range
data = get_base_table_data(range_)
data.append(truncate_string(link_.description))
if range_.view_name == 'file': # pragma: no cover
ext = data[3].replace('.', '')
data.append(get_profile_image_table_link(range_, reference, ext, profile_image_id))
if not profile_image_id and ext in app.config['DISPLAY_FILE_EXTENSIONS']:
profile_image_id = range_.id
if is_authorized('editor'):
url = url_for('reference_link_update', link_id=link_.id, origin_id=reference.id)
data.append('<a href="' + url + '">' + uc_first(_('edit')) + '</a>')
url = url_for('link_delete', id_=link_.id, origin_id=reference.id)
data.append(display_remove_link(url + '#tab-' + range_.table_name, range_.name))
tables[range_.table_name]['data'].append(data)
return render_template('reference/view.html', reference=reference, tables=tables,
profile_image_id=profile_image_id)
示例11: check_single_type_duplicates
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def check_single_type_duplicates() -> list:
# Find entities with multiple types attached which should be single
from openatlas.models.node import NodeMapper
from openatlas.models.entity import EntityMapper
data = []
for id_, node in g.nodes.items():
if not node.root and not node.multiple and not node.value_type:
node_ids = NodeMapper.get_all_sub_ids(node)
if node_ids:
sql = """
SELECT domain_id FROM model.link
WHERE property_code = 'P2' AND range_id IN %(node_ids)s
GROUP BY domain_id HAVING COUNT(*) > 1;"""
g.cursor.execute(sql, {'node_ids': tuple(node_ids)})
debug_model['link sql'] += 1
for row in g.cursor.fetchall():
offending_nodes = []
entity = EntityMapper.get_by_id(row.domain_id, nodes=True)
for entity_node in entity.nodes:
if g.nodes[entity_node.root[-1]].id == node.id:
url = url_for('admin_delete_single_type_duplicate',
entity_id=entity.id, node_id=entity_node.id)
offending_nodes.append(
'<a href="' + url + '">' + uc_first(_('remove')) + '</a> ' +
entity_node.name)
data.append([link(entity), entity.class_.name,
link(g.nodes[id_]), '<br />'.join(offending_nodes)])
return data
示例12: get_invalid_dates
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def get_invalid_dates():
""" Search for entities with invalid date combinations, e.g. begin after end"""
from openatlas.models.entity import EntityMapper
sql = """
SELECT e.id FROM model.entity e
LEFT JOIN model.link bl1 ON e.id = bl1.domain_id
AND bl1.property_code IN ('OA1', 'OA3', 'OA5')
LEFT JOIN model.entity b1 ON bl1.range_id = b1.id
AND b1.system_type IN ('from date value', 'exact date value')
LEFT JOIN model.link bl2 ON e.id = bl2.domain_id
AND bl2.property_code IN ('OA1', 'OA3', 'OA5')
LEFT JOIN model.entity b2 ON bl2.range_id = b2.id AND b2.system_type = 'to date value'
LEFT JOIN model.link el1 ON e.id = el1.domain_id
AND el1.property_code IN ('OA2', 'OA4', 'OA6')
LEFT JOIN model.entity e1 ON el1.range_id = e1.id
AND e1.system_type IN ('from date value', 'exact date value')
LEFT JOIN model.link el2 ON e.id = el2.domain_id
AND el2.property_code IN ('OA2', 'OA4', 'OA6')
LEFT JOIN model.entity e2 ON el2.range_id = e2.id AND e2.system_type = 'to date value'
GROUP BY e.id
HAVING e.class_code IN ('E6', 'E7', 'E8', 'E12', 'E18', 'E21', 'E22', 'E40', 'E74')
AND (max(b1.value_timestamp) > max(b2.value_timestamp)
OR max(e1.value_timestamp) > max(e2.value_timestamp)
OR (max(b1.value_timestamp) IS NOT NULL AND max(e1.value_timestamp) IS NOT NULL
AND max(b1.value_timestamp) > max(e1.value_timestamp))
OR (max(b2.value_timestamp) IS NOT NULL AND max(e2.value_timestamp) IS NOT NULL
AND max(b2.value_timestamp) > max(e2.value_timestamp)));"""
g.cursor.execute(sql)
debug_model['div sql'] += 1
return [EntityMapper.get_by_id(row.id)for row in g.cursor.fetchall()]
示例13: save
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [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
示例14: reference_insert
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def reference_insert(code, origin_id=None):
origin = EntityMapper.get_by_id(origin_id) if origin_id else None
form = build_form(ReferenceForm, uc_first('Information Carrier' if code == 'carrier' else code))
if origin:
del form.insert_and_continue
if form.validate_on_submit():
return redirect(save(form, code=code, origin=origin))
return render_template('reference/insert.html', form=form, code=code, origin=origin)
示例15: source_insert
# 需要导入模块: from openatlas.models.entity import EntityMapper [as 别名]
# 或者: from openatlas.models.entity.EntityMapper import get_by_id [as 别名]
def source_insert(origin_id=None):
origin = EntityMapper.get_by_id(origin_id) if origin_id else None
form = build_form(SourceForm, 'Source')
if origin:
del form.insert_and_continue
if form.validate_on_submit():
return redirect(save(form, origin=origin))
return render_template('source/insert.html', form=form, origin=origin)