Exemplo n.º 1
0
def save(form, source=None, origin=None):
    g.cursor.execute('BEGIN')
    try:
        log_action = 'update'
        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(get_view_name(origin) + '_view', id_=origin.id) + '#tab-source'
            if get_view_name(origin) == 'reference':
                link_ = origin.link('P67', source)
                url = url_for('reference_link_update', link_id=link_, origin_id=origin)
            elif get_view_name(origin) == '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
Exemplo n.º 2
0
def save(form, object_=None, location=None, origin=None):
    g.cursor.execute('BEGIN')
    try:
        log_action = 'update'
        if object_:
            for alias in object_.get_linked_entities('P1'):
                alias.delete()
            GisMapper.delete_by_entity(location)
        else:
            log_action = 'insert'
            if origin and origin.system_type == 'stratigraphic unit':
                object_ = EntityMapper.insert('E22', form.name.data, 'find')
            else:
                system_type = 'place'
                if origin and origin.system_type == 'place':
                    system_type = 'feature'
                elif origin and origin.system_type == 'feature':
                    system_type = 'stratigraphic unit'
                object_ = EntityMapper.insert('E18', form.name.data, system_type)
            location = EntityMapper.insert('E53', 'Location of ' + form.name.data, 'place location')
            object_.link('P53', location)
        object_.name = form.name.data
        object_.description = form.description.data
        object_.update()
        object_.save_dates(form)
        object_.save_nodes(form)
        location.name = 'Location of ' + form.name.data
        location.update()
        location.save_nodes(form)
        if hasattr(form, 'alias'):
            for alias in form.alias.data:
                if alias.strip():  # check if it isn't empty
                    object_.link('P1', EntityMapper.insert('E41', alias))
        url = url_for('place_view', id_=object_.id)
        if origin:
            url = url_for(get_view_name(origin) + '_view', id_=origin.id) + '#tab-place'
            if get_view_name(origin) == 'reference':
                link_id = origin.link('P67', object_)
                url = url_for('reference_link_update', link_id=link_id, origin_id=origin.id)
            elif origin.system_type in ['place', 'feature', 'stratigraphic unit']:
                url = url_for('place_view', id_=object_.id)
                origin.link('P46', object_)
            else:
                origin.link('P67', object_)
        GisMapper.insert(location, form)
        g.cursor.execute('COMMIT')
        if form.continue_.data == 'yes':
            url = url_for('place_insert', origin_id=origin.id if origin else None)
        logger.log_user(object_.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('place_index')
    return url
Exemplo n.º 3
0
def save(form, event=None, code=None, origin=None):
    g.cursor.execute('BEGIN')
    try:
        if event:
            log_action = 'update'
            LinkMapper.delete_by_codes(event, ['P117', 'P7', 'P24'])
        else:
            log_action = 'insert'
            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:
            event.link('P117', int(form.event.data))
        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
            event.link('P24', ast.literal_eval(form.given_place.data))
        url = url_for('event_view', id_=event.id)
        if origin:
            view_name = get_view_name(origin)
            url = url_for(view_name + '_view', id_=origin.id) + '#tab-event'
            if view_name == 'reference':
                link_id = origin.link('P67', event)
                url = url_for('reference_link_update',
                              link_id=link_id,
                              origin_id=origin.id)
            elif view_name == 'source':
                origin.link('P67', event)
            elif view_name == 'actor':
                link_id = event.link('P11', origin)
                url = url_for('involvement_update',
                              id_=link_id,
                              origin_id=origin.id)
            elif 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
Exemplo n.º 4
0
def reference_link_update(link_id, origin_id):
    link_ = LinkMapper.get_by_id(link_id)
    origin = EntityMapper.get_by_id(origin_id)
    view_name = get_view_name(origin)
    form = AddReferenceForm()
    form.save.label.text = _('save')
    del form.reference
    if form.validate_on_submit():
        link_.description = form.page.data
        link_.update()
        flash(_('info update'), 'info')
        tab = '#tab-' + get_view_name(
            link_.range) if view_name == 'reference' else '#tab-reference'
        return redirect(url_for(view_name + '_view', id_=origin.id) + tab)
    form.page.data = link_.description
    return render_template('reference/link-update.html',
                           origin=origin,
                           linked_object=link_.domain
                           if link_.domain.id != origin.id else link_.range,
                           form=form,
                           class_name=view_name)
Exemplo n.º 5
0
def source_view(id_, unlink_id=None):
    source = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    tables = {
        'info': get_entity_data(source),
        'text': {'id': 'translation', 'data': [], 'header': ['text', 'type', 'content']},
        'file': {'id': 'files', 'data': [], 'header': app.config['TABLE_HEADERS']['file']},
        'reference': {
            'id': 'source', 'data': [],
            'header': app.config['TABLE_HEADERS']['reference'] + ['page']}}
    for text in source.get_linked_entities('P73'):
        tables['text']['data'].append([
            link(text),
            next(iter(text.nodes)).name if text.nodes else '',
            truncate_string(text.description)])
    for name in ['actor', 'event', 'place', 'feature', 'stratigraphic-unit', 'find']:
        tables[name] = {'id': name, 'header': app.config['TABLE_HEADERS'][name], 'data': []}
    for link_ in source.get_links('P67'):
        data = get_base_table_data(link_.range)
        view_name = get_view_name(link_.range)
        view_name = view_name if view_name != 'place' else link_.range.system_type.replace(' ', '-')
        if is_authorized('editor'):
            unlink = url_for('source_view', id_=source.id, unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink, link_.range.name))
        tables[view_name]['data'].append(data)
    for link_ in source.get_links(['P67', 'P128'], True):
        data = get_base_table_data(link_.domain)
        view_name = get_view_name(link_.domain)
        if view_name not in ['file']:
            data.append(link_.description)
            if is_authorized('editor'):
                update_url = url_for('reference_link_update', link_id=link_.id, origin_id=source.id)
                data.append('<a href="' + update_url + '">' + uc_first(_('edit')) + '</a>')
        if is_authorized('editor'):
            unlink = url_for('source_view', id_=source.id, unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink, link_.domain.name))
        tables[view_name]['data'].append(data)
    return render_template('source/view.html', source=source, tables=tables)
Exemplo n.º 6
0
def reference_add(origin_id):
    """ Link an entity to reference coming from the entity."""
    origin = EntityMapper.get_by_id(origin_id)
    view_name = get_view_name(origin)
    form = AddReferenceForm()
    if form.validate_on_submit():
        reference = EntityMapper.get_by_id(form.reference.data)
        reference.link('P67', origin.id, form.page.data)
        return redirect(
            url_for(view_name + '_view', id_=origin.id) + '#tab-reference')
    return render_template('reference/add.html',
                           origin=origin,
                           form=form,
                           class_name=view_name)
Exemplo n.º 7
0
def source_add(origin_id):
    """ Link an entity to source coming from the entity."""
    origin = EntityMapper.get_by_id(origin_id)
    if request.method == 'POST':
        g.cursor.execute('BEGIN')
        try:
            for value in request.form.getlist('values'):
                LinkMapper.insert(int(value), 'P67', origin.id)
            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')
        return redirect(url_for(get_view_name(origin) + '_view', id_=origin.id) + '#tab-source')
    form = build_table_form('source', origin.get_linked_entities('P67', True))
    return render_template('source/add.html', origin=origin, form=form)
Exemplo n.º 8
0
def reference_view(id_, unlink_id=None):
    reference = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    tables = {
        'info': get_entity_data(reference),
        'file': {
            'id': 'files',
            'data': [],
            'header': app.config['TABLE_HEADERS']['file'] + ['page']
        }
    }
    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):
        data = get_base_table_data(link_.domain)
        if is_authorized('editor'):
            unlink = url_for('reference_view',
                             id_=reference.id,
                             unlink_id=link_.id) + '#tab-file'
            data.append(display_remove_link(unlink, link_.domain.name))
        tables['file']['data'].append(data)
    for link_ in reference.get_links(['P67', 'P128']):
        view_name = get_view_name(link_.range)
        view_name = view_name if view_name != 'place' else link_.range.system_type.replace(
            ' ', '-')
        data = get_base_table_data(link_.range)
        data.append(truncate_string(link_.description))
        if is_authorized('editor'):
            update_url = url_for('reference_link_update',
                                 link_id=link_.id,
                                 origin_id=reference.id)
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            unlink_url = url_for('reference_view',
                                 id_=reference.id,
                                 unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink_url, link_.range.name))
        tables[view_name]['data'].append(data)
    return render_template('reference/view.html',
                           reference=reference,
                           tables=tables)
Exemplo n.º 9
0
def file_view(id_, unlink_id=None):
    file = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    path = get_file_path(file.id)
    tables = {'info': get_entity_data(file)}
    for name in [
            'source', 'event', 'actor', 'place', 'feature',
            'stratigraphic-unit', 'find', 'reference'
    ]:
        header = app.config['TABLE_HEADERS'][name] + (['page'] if name
                                                      == 'reference' else [])
        tables[name] = {'id': name, 'data': [], 'header': header}
    for link_ in file.get_links('P67'):
        view_name = get_view_name(link_.range)
        view_name = view_name if view_name != 'place' else link_.range.system_type.replace(
            ' ', '-')
        data = get_base_table_data(link_.range)
        if is_authorized('editor'):
            unlink_url = url_for('file_view', id_=file.id,
                                 unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink_url, link_.range.name))
        tables[view_name]['data'].append(data)
    for link_ in file.get_links('P67', True):
        data = get_base_table_data(link_.domain)
        data.append(link_.description)
        if is_authorized('editor'):
            update_url = url_for('reference_link_update',
                                 link_id=link_.id,
                                 origin_id=file.id)
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            unlink_url = url_for('file_view', id_=file.id,
                                 unlink_id=link_.id) + '#tab-reference'
            data.append(display_remove_link(unlink_url, link_.domain.name))
        tables['reference']['data'].append(data)
    return render_template(
        'file/view.html',
        missing_file=False if path else True,
        entity=file,
        tables=tables,
        preview=True if path and preview_file(path) else False,
        filename=os.path.basename(path) if path else False)
Exemplo n.º 10
0
 def print_base_type(self):
     from openatlas.models.node import NodeMapper
     view_name = get_view_name(self)
     if not view_name or view_name == 'actor':  # actors have no base type
         return ''
     root_name = view_name.title()
     if view_name == 'reference':
         root_name = self.system_type.title()
     elif view_name == 'file':
         root_name = 'License'
     elif view_name == 'place':
         root_name = uc_first(self.system_type)
         if self.system_type == 'stratigraphic unit':
             root_name = 'Stratigraphic Unit'
     root_id = NodeMapper.get_hierarchy_by_name(root_name).id
     for node in self.nodes:
         if node.root and node.root[-1] == root_id:
             return node.name
     return ''
Exemplo n.º 11
0
def involvement_insert(origin_id):
    origin = EntityMapper.get_by_id(origin_id)
    view_name = get_view_name(origin)
    form = build_form(ActorForm, 'Involvement')
    if view_name == 'event':
        del form.event
    else:
        del form.actor
    form.activity.choices = [('P11', g.properties['P11'].name_inverse)]
    if origin.class_.code in ['E7', 'E8', 'E12']:
        form.activity.choices.append(('P14', g.properties['P14'].name_inverse))
    if origin.class_.code == 'E8':
        form.activity.choices.append(('P22', g.properties['P22'].name_inverse))
        form.activity.choices.append(('P23', g.properties['P23'].name_inverse))
    if form.validate_on_submit():
        g.cursor.execute('BEGIN')
        try:
            if view_name == 'event':
                for actor_id in ast.literal_eval(form.actor.data):
                    link_id = origin.link(form.activity.data, actor_id,
                                          form.description.data)
                    DateMapper.save_link_dates(link_id, form)
                    NodeMapper.save_link_nodes(link_id, form)
            else:
                for event_id in ast.literal_eval(form.event.data):
                    link_id = LinkMapper.insert(event_id, form.activity.data,
                                                origin.id,
                                                form.description.data)
                    DateMapper.save_link_dates(link_id, form)
                    NodeMapper.save_link_nodes(link_id, form)
            g.cursor.execute('COMMIT')
            flash(_('entity created'), 'info')
        except Exception as e:  # pragma: no cover
            g.cursor.execute('ROLLBACK')
            logger.log('error', 'database', 'transaction failed', e)
            flash(_('error transaction'), 'error')
        if form.continue_.data == 'yes':
            return redirect(url_for('involvement_insert', origin_id=origin_id))
        tab = 'actor' if view_name == 'event' else 'event'
        return redirect(
            url_for(view_name + '_view', id_=origin.id) + '#tab-' + tab)
    return render_template('involvement/insert.html', origin=origin, form=form)
Exemplo n.º 12
0
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')
        view_name = get_view_name(origin)
        tab = 'actor' if view_name == 'event' else 'event'
        return redirect(
            url_for(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)
Exemplo n.º 13
0
def save(form, file=None, origin=None):
    g.cursor.execute('BEGIN')
    try:
        log_action = 'update'
        if not file:
            log_action = 'insert'
            file_ = request.files['file']
            file = EntityMapper.insert('E31', form.name.data, 'file')
            filename = secure_filename(file_.filename)
            new_name = str(file.id) + '.' + filename.rsplit('.', 1)[1].lower()
            full_path = os.path.join(app.config['UPLOAD_FOLDER_PATH'],
                                     new_name)
            file_.save(full_path)
        file.name = form.name.data
        file.description = form.description.data
        file.update()
        file.save_nodes(form)
        url = url_for('file_view', id_=file.id)
        if origin:
            if origin.system_type in ['edition', 'bibliography']:
                link_id = origin.link('P67', file)
                url = url_for('reference_link_update',
                              link_id=link_id,
                              origin_id=origin.id)
            else:
                file.link('P67', origin)
                url = url_for(get_view_name(origin) + '_view',
                              id_=origin.id) + '#tab-file'
        g.cursor.execute('COMMIT')
        logger.log_user(file.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')
        openatlas.logger.log('error', 'database', 'transaction failed', e)
        flash(_('error transaction'), 'error')
        url = url_for('file_index', origin_id=origin.id if origin else None)
    return url
Exemplo n.º 14
0
def place_view(id_, unlink_id=None):
    object_ = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    object_.set_dates()
    location = object_.get_linked_entity('P53')
    tables = {
        'info': get_entity_data(object_, location),
        'file': {'id': 'files', 'data': [], 'header': app.config['TABLE_HEADERS']['file']},
        'source': {'id': 'source', 'data': [], 'header': app.config['TABLE_HEADERS']['source']},
        'event': {'id': 'event', 'data': [], 'header': app.config['TABLE_HEADERS']['event']},
        'reference': {
            'id': 'reference', 'data': [],
            'header': app.config['TABLE_HEADERS']['reference'] + ['pages']},
        'actor': {
            'id': 'actor', 'data': [],
            'header': [_('actor'), _('property'), _('class'), _('first'), _('last')]}}
    if object_.system_type == 'place':
        tables['feature'] = {'id': 'feature', 'data': [],
                             'header': app.config['TABLE_HEADERS']['place'] + [_('description')]}
    if object_.system_type == 'feature':
        tables['stratigraphic-unit'] = {
            'id': 'stratigraphic', 'data': [], 'header':
            app.config['TABLE_HEADERS']['place'] + [_('description')]}
    if object_.system_type == 'stratigraphic unit':
        tables['find'] = {'id': 'find', 'data': [],
                          'header': app.config['TABLE_HEADERS']['place'] + [_('description')]}
    for link_ in object_.get_links('P67', True):
        data = get_base_table_data(link_.domain)
        view_name = get_view_name(link_.domain)
        if view_name not in ['source', 'file']:
            data.append(truncate_string(link_.description))
            if is_authorized('editor'):
                url = url_for('reference_link_update', link_id=link_.id, origin_id=object_.id)
                data.append('<a href="' + url + '">' + uc_first(_('edit')) + '</a>')
        if is_authorized('editor'):
            url = url_for('place_view', id_=object_.id, unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(url, link_.domain.name))
        tables[view_name]['data'].append(data)
    for event in location.get_linked_entities(['P7', 'P24'], True):
        tables['event']['data'].append(get_base_table_data(event))
    has_subunits = False
    for entity in object_.get_linked_entities('P46'):
        has_subunits = True
        data = get_base_table_data(entity)
        data.append(truncate_string(entity.description))
        tables[entity.system_type.replace(' ', '-')]['data'].append(data)
    for link_ in location.get_links(['P74', 'OA8', 'OA9'], True):
        actor = EntityMapper.get_by_id(link_.domain.id)
        tables['actor']['data'].append([
            link(actor),
            g.properties[link_.property.code].name,
            actor.class_.name,
            actor.first,
            actor.last])
    gis_data = GisMapper.get_all(object_.id) if location else None
    if gis_data['gisPointSelected'] == '[]' and gis_data['gisPolygonSelected'] == '[]':
        gis_data = None
    place = None
    feature = None
    stratigraphic_unit = None
    if object_.system_type == 'find':
        stratigraphic_unit = object_.get_linked_entity('P46', True)
        feature = stratigraphic_unit.get_linked_entity('P46', True)
        place = feature.get_linked_entity('P46', True)
    elif object_.system_type == 'stratigraphic unit':
        feature = object_.get_linked_entity('P46', True)
        place = feature.get_linked_entity('P46', True)
    elif object_.system_type == 'feature':
        place = object_.get_linked_entity('P46', True)
    return render_template('place/view.html', object_=object_, tables=tables, gis_data=gis_data,
                           place=place, feature=feature, stratigraphic_unit=stratigraphic_unit,
                           has_subunits=has_subunits)
Exemplo n.º 15
0
def save(form, actor=None, code=None, origin=None):
    g.cursor.execute('BEGIN')
    try:
        log_action = 'update'
        if actor:
            LinkMapper.delete_by_codes(actor, ['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:
            view_name = get_view_name(origin)
            if view_name == 'reference':
                link_id = origin.link('P67', actor)
                url = url_for('reference_link_update',
                              link_id=link_id,
                              origin_id=origin.id)
            elif view_name == 'source':
                origin.link('P67', actor)
                url = url_for('source_view', id_=origin.id) + '#tab-actor'
            elif view_name == 'event':
                link_id = origin.link('P11', actor)
                url = url_for('involvement_update',
                              id_=link_id,
                              origin_id=origin.id)
            elif 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)
        g.cursor.execute('COMMIT')
        logger.log_user(actor.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')
        return redirect(url_for('actor_index'))
    return url
Exemplo n.º 16
0
def actor_view(id_, unlink_id=None):
    actor = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    actor.set_dates()
    object_ids = []
    info = get_entity_data(actor)
    residence = actor.get_linked_entity('P74')
    if residence:
        object_ = residence.get_linked_entity('P53', True)
        object_ids.append(object_.id)
        info.append((uc_first(_('residence')), link(object_)))
    first = actor.get_linked_entity('OA8')
    if first:
        object_ = first.get_linked_entity('P53', True)
        object_ids.append(object_.id)
        info.append((uc_first(_('appears first')), link(object_)))
    last = actor.get_linked_entity('OA9')
    if last:
        object_ = last.get_linked_entity('P53', True)
        object_ids.append(object_.id)
        info.append((uc_first(_('appears last')), link(object_)))
    tables = {
        'info': info,
        'file': {
            'id': 'files',
            'data': [],
            'header': app.config['TABLE_HEADERS']['file']
        },
        'source': {
            'id': 'source',
            'data': [],
            'header': app.config['TABLE_HEADERS']['source']
        },
        'reference': {
            'id': 'reference',
            'data': [],
            'header': app.config['TABLE_HEADERS']['reference'] + ['pages']
        },
        'event': {
            'id':
            'event',
            'data': [],
            'header':
            ['event', 'class', 'involvement', 'first', 'last', 'description']
        },
        'relation': {
            'id': 'relation',
            'data': [],
            'sort': 'sortList:[[0,0]]',
            'header': ['relation', 'actor', 'first', 'last', 'description']
        },
        'member_of': {
            'id': 'member_of',
            'data': [],
            'header':
            ['member of', 'function', 'first', 'last', 'description']
        }
    }
    for link_ in actor.get_links('P67', True):
        data = get_base_table_data(link_.domain)
        view_name = get_view_name(link_.domain)
        if view_name not in ['source', 'file']:
            data.append(truncate_string(link_.description))
            if is_authorized('editor'):
                update_url = url_for('reference_link_update',
                                     link_id=link_.id,
                                     origin_id=actor.id)
                data.append('<a href="' + update_url + '">' +
                            uc_first(_('edit')) + '</a>')
        if is_authorized('editor'):
            unlink = url_for('actor_view', id_=actor.id,
                             unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink, link_.domain.name))
        tables[view_name]['data'].append(data)
    for link_ in actor.get_links(['P11', 'P14', 'P22', 'P23'], True):
        event = link_.domain
        first = link_.first
        place = event.get_linked_entity('P7')
        if place:
            object_ids.append(place.get_linked_entity('P53', True).id)
        if not link_.first and event.first:
            first = '<span class="inactive" style="float:right">' + str(
                event.first) + '</span>'
        last = link_.last
        if not link_.last and event.last:
            last = '<span class="inactive" style="float:right">' + str(
                event.last) + '</span>'
        data = ([
            link(event), g.classes[event.class_.code].name,
            link_.type.name if link_.type else '', first, last,
            truncate_string(link_.description)
        ])
        if is_authorized('editor'):
            update_url = url_for('involvement_update',
                                 id_=link_.id,
                                 origin_id=actor.id)
            unlink_url = url_for(
                'actor_view', id_=actor.id, unlink_id=link_.id) + '#tab-event'
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            data.append(display_remove_link(unlink_url, link_.range.name))
        tables['event']['data'].append(data)
    for link_ in actor.get_links('OA7') + actor.get_links('OA7', True):
        if actor.id == link_.domain.id:
            type_ = link_.type.get_name_directed() if link_.type else ''
            related = link_.range
        else:
            type_ = link_.type.get_name_directed(True) if link_.type else ''
            related = link_.domain
        data = ([
            type_,
            link(related), link_.first, link_.last,
            truncate_string(link_.description)
        ])
        if is_authorized('editor'):
            update_url = url_for('relation_update',
                                 id_=link_.id,
                                 origin_id=actor.id)
            unlink_url = url_for('actor_view',
                                 id_=actor.id,
                                 unlink_id=link_.id) + '#tab-relation'
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            data.append(display_remove_link(unlink_url, related.name))
        tables['relation']['data'].append(data)
    for link_ in actor.get_links('P107', True):
        data = ([
            link(link_.domain), link_.type.name if link_.type else '',
            link_.first, link_.last,
            truncate_string(link_.description)
        ])
        if is_authorized('editor'):
            update_url = url_for('member_update',
                                 id_=link_.id,
                                 origin_id=actor.id)
            unlink_url = url_for('actor_view',
                                 id_=actor.id,
                                 unlink_id=link_.id) + '#tab-member-of'
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            data.append(display_remove_link(unlink_url, link_.domain.name))
        tables['member_of']['data'].append(data)
    if actor.class_.code in app.config['CLASS_CODES']['group']:
        tables['member'] = {
            'id': 'member',
            'header': ['member', 'function', 'first', 'last', 'description'],
            'data': []
        }
        for link_ in actor.get_links('P107'):
            data = ([
                link(link_.range), link_.type.name if link_.type else '',
                link_.first, link_.last,
                truncate_string(link_.description)
            ])
            if is_authorized('editor'):
                update_url = url_for('member_update',
                                     id_=link_.id,
                                     origin_id=actor.id)
                unlink_url = url_for('actor_view',
                                     id_=actor.id,
                                     unlink_id=link_.id) + '#tab-member'
                data.append('<a href="' + update_url + '">' +
                            uc_first(_('edit')) + '</a>')
                data.append(display_remove_link(unlink_url, link_.range.name))
            tables['member']['data'].append(data)
    gis_data = GisMapper.get_all(object_ids) if object_ids else None
    if gis_data and gis_data['gisPointSelected'] == '[]':
        gis_data = None
    return render_template('actor/view.html',
                           actor=actor,
                           tables=tables,
                           gis_data=gis_data)
Exemplo n.º 17
0
def event_view(id_, unlink_id=None):
    event = EntityMapper.get_by_id(id_)
    if unlink_id:
        LinkMapper.delete_by_id(unlink_id)
        flash(_('link removed'), 'info')
    event.set_dates()
    tables = {
        'info': get_entity_data(event),
        'file': {
            'id': 'files',
            'data': [],
            'header': app.config['TABLE_HEADERS']['file']
        },
        'subs': {
            'id': 'sub-event',
            'data': [],
            'header': app.config['TABLE_HEADERS']['event']
        },
        'actor': {
            'id':
            'actor',
            'data': [],
            'header':
            ['actor', 'class', 'involvement', 'first', 'last', 'description']
        },
        'source': {
            'id': 'source',
            'data': [],
            'header': app.config['TABLE_HEADERS']['source'] + ['description']
        },
        'reference': {
            'id': 'reference',
            'data': [],
            'header': app.config['TABLE_HEADERS']['reference'] + ['pages']
        }
    }
    for link_ in event.get_links(['P11', 'P14', 'P22', 'P23']):
        first = link_.first
        if not link_.first and event.first:
            first = '<span class="inactive" style="float:right">' + str(
                event.first) + '</span>'
        last = link_.last
        if not link_.last and event.last:
            last = '<span class="inactive" style="float:right">' + str(
                event.last) + '</span>'
        data = ([
            link(link_.range), g.classes[link_.range.class_.code].name,
            link_.type.name if link_.type else '', first, last,
            truncate_string(link_.description)
        ])
        if is_authorized('editor'):
            unlink_url = url_for(
                'event_view', id_=event.id, unlink_id=link_.id) + '#tab-actor'
            update_url = url_for('involvement_update',
                                 id_=link_.id,
                                 origin_id=event.id)
            data.append('<a href="' + update_url + '">' + uc_first(_('edit')) +
                        '</a>')
            data.append(display_remove_link(unlink_url, link_.range.name))
        tables['actor']['data'].append(data)
    for link_ in event.get_links('P67', True):
        data = get_base_table_data(link_.domain)
        view_name = get_view_name(link_.domain)
        if view_name not in ['source', 'file']:
            data.append(truncate_string(link_.description))
            if is_authorized('editor'):
                update_url = url_for('reference_link_update',
                                     link_id=link_.id,
                                     origin_id=event.id)
                data.append('<a href="' + update_url + '">' +
                            uc_first(_('edit')) + '</a>')
        if is_authorized('editor'):
            unlink = url_for('event_view', id_=event.id,
                             unlink_id=link_.id) + '#tab-' + view_name
            data.append(display_remove_link(unlink, link_.domain.name))
        tables[view_name]['data'].append(data)
    for sub_event in event.get_linked_entities('P117', True):
        tables['subs']['data'].append(get_base_table_data(sub_event))
    return render_template('event/view.html', event=event, tables=tables)