예제 #1
0
def involvement_insert(origin_id: int) -> Union[str, Response]:
    origin = Entity.get_by_id(origin_id)
    form = build_form('involvement', origin=origin)
    form.activity.choices = [('P11', g.properties['P11'].name_inverse)]
    if origin.class_.name in ['acquisition', 'activity', 'production']:
        form.activity.choices.append(('P14', g.properties['P14'].name_inverse))
        if origin.class_.name == 'acquisition':
            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():
        Transaction.begin()
        try:
            if origin.class_.view == 'event':
                for actor in Entity.get_by_ids(
                        ast.literal_eval(form.actor.data)):
                    link_ = Link.get_by_id(
                        origin.link(form.activity.data, actor,
                                    form.description.data)[0])
                    link_.set_dates(process_form_dates(form))
                    link_.type = get_link_type(form)
                    link_.update()
            else:
                for event in Entity.get_by_ids(
                        ast.literal_eval(form.event.data)):
                    link_ = Link.get_by_id(
                        event.link(form.activity.data, origin,
                                   form.description.data)[0])
                    link_.set_dates(process_form_dates(form))
                    link_.type = get_link_type(form)
                    link_.update()
            Transaction.commit()
        except Exception as e:  # pragma: no cover
            Transaction.rollback()
            logger.log('error', 'database', 'transaction failed', e)
            flash(_('error transaction'), 'error')
        if hasattr(form, 'continue_') and form.continue_.data == 'yes':
            return redirect(url_for('involvement_insert', origin_id=origin_id))
        return redirect(
            f"{url_for('view', id_=origin.id)}"
            f"#tab-{'actor' if origin.class_.view == 'event' else 'event'}")
    return render_template('display_form.html',
                           form=form,
                           crumbs=[[
                               _(origin.class_.view),
                               url_for('index', view=origin.class_.view)
                           ], origin,
                                   _('involvement')])
예제 #2
0
def relation_update(link_: Link, domain: Entity, range_: Entity,
                    origin: Entity) -> Union[str, Response]:
    origin = range_ if origin.id == range_.id else domain
    related = range_ if origin.id == domain.id else domain
    form = build_form('actor_actor_relation', link_)
    if form.validate_on_submit():
        Transaction.begin()
        try:
            link_.delete()
            if form.inverse.data:
                link_ = Link.get_by_id(
                    related.link('OA7', origin, form.description.data)[0])
            else:
                link_ = Link.get_by_id(
                    origin.link('OA7', related, form.description.data)[0])
            link_.set_dates(process_form_dates(form))
            link_.type = get_link_type(form)
            link_.update()
            Transaction.commit()
            flash(_('info update'), 'info')
        except Exception as e:  # pragma: no cover
            Transaction.rollback()
            logger.log('error', 'database', 'transaction failed', e)
            flash(_('error transaction'), 'error')
        return redirect(f"{url_for('view', id_=origin.id)}#tab-relation")
    if origin.id == range_.id:
        form.inverse.data = True
    return render_template(
        'display_form.html',
        form=form,
        title=_('relation'),
        crumbs=[[_('actor'), url_for('index', view='actor')], origin, related,
                _('edit')])
예제 #3
0
def member_update(id_: int, origin_id: int) -> Union[str, Response]:
    link_ = Link.get_by_id(id_)
    domain = Entity.get_by_id(link_.domain.id)
    range_ = Entity.get_by_id(link_.range.id)
    origin = range_ if origin_id == range_.id else domain
    form = build_form('actor_function', link_)
    if form.validate_on_submit():
        Transaction.begin()
        try:
            link_.delete()
            link_ = Link.get_by_id(
                domain.link('P107', range_, form.description.data)[0])
            link_.set_dates(process_form_dates(form))
            link_.type = get_link_type(form)
            link_.update()
            Transaction.commit()
        except Exception as e:  # pragma: no cover
            Transaction.rollback()
            logger.log('error', 'database', 'transaction failed', e)
            flash(_('error transaction'), 'error')
        return redirect(
            f"{url_for('view', id_=origin.id)}"
            f"#tab-member{'-of' if origin.id == range_.id else ''}")
    form.save.label.text = _('save')
    related = range_ if origin_id == domain.id else domain
    return render_template(
        'display_form.html',
        form=form,
        crumbs=[[_('actor'), url_for('index', view='actor')], origin, related,
                _('edit')])
예제 #4
0
파일: relation.py 프로젝트: craws/OpenAtlas
def relation_insert(origin_id: int) -> Union[str, Response]:
    origin = Entity.get_by_id(origin_id)
    form = build_form('actor_actor_relation')
    form.relation_origin_id.data = origin.id
    if form.validate_on_submit():
        Transaction.begin()
        try:
            for actor in Entity.get_by_ids(ast.literal_eval(form.actor.data)):
                if form.inverse.data:
                    link_ = Link.get_by_id(
                        actor.link('OA7', origin, form.description.data)[0])
                else:
                    link_ = Link.get_by_id(
                        origin.link('OA7', actor, form.description.data)[0])
                link_.set_dates(process_form_dates(form))
                link_.type = get_link_type(form)
                link_.update()
            Transaction.commit()
            flash(_('entity created'), 'info')
        except Exception as e:  # pragma: no cover
            Transaction.rollback()
            logger.log('error', 'database', 'transaction failed', e)
            flash(_('error transaction'), 'error')
        if hasattr(form, 'continue_') and form.continue_.data == 'yes':
            return redirect(url_for('relation_insert', origin_id=origin_id))
        return redirect(f"{url_for('view', id_=origin.id)}#tab-relation")
    return render_template(
        'display_form.html',
        form=form,
        title=_('relation'),
        crumbs=[
            [_('actor'), url_for('index', view='actor')],
            origin,
            f"+ {uc_first(_('relation'))}"])
예제 #5
0
def involvement_update(link_: Link, origin: Entity) -> Union[str, Response]:
    form = build_form('involvement', link_)
    form.activity.choices = [('P11', g.properties['P11'].name)]
    event = Entity.get_by_id(link_.domain.id)
    actor = Entity.get_by_id(link_.range.id)
    origin = event if origin.id == event.id else actor
    if event.class_.name in ['acquisition', 'activity']:
        form.activity.choices.append(('P14', g.properties['P14'].name))
        if event.class_.name == 'acquisition':
            form.activity.choices.append(('P22', g.properties['P22'].name))
            form.activity.choices.append(('P23', g.properties['P23'].name))
    if form.validate_on_submit():
        Transaction.begin()
        try:
            link_.delete()
            link_ = Link.get_by_id(
                event.link(
                    form.activity.data,
                    actor,
                    form.description.data)[0])
            link_.set_dates(process_form_dates(form))
            link_.type = get_link_type(form)
            link_.update()
            Transaction.commit()
        except Exception as e:  # pragma: no cover
            Transaction.rollback()
            logger.log('error', 'database', 'transaction failed', e)
            flash(_('error transaction'), 'error')
        return redirect(
            f"{url_for('view', id_=origin.id)}"
            f"#tab-{'actor' if origin.class_.view == 'event' else 'event'}")
    form.save.label.text = _('save')
    form.activity.data = link_.property.code
    form.description.data = link_.description
    return render_template(
        'display_form.html',
        origin=origin,
        form=form,
        crumbs=[
            [_(origin.class_.view), url_for('index', view=origin.class_.view)],
            origin,
            event if origin.id != event.id else actor,
            _('edit')])
예제 #6
0
def member_insert(origin_id: int,
                  code: str = 'member') -> Union[str, Response]:
    origin = Entity.get_by_id(origin_id)
    form = build_form('actor_function', code=code)
    form.member_origin_id.data = origin.id
    if form.validate_on_submit():
        Transaction.begin()
        try:
            member_field = getattr(form, 'actor') \
                if code == 'member' else getattr(form, 'group')
            for actor in Entity.get_by_ids(ast.literal_eval(
                    member_field.data)):
                if code == 'membership':
                    link_ = Link.get_by_id(
                        actor.link('P107', origin, form.description.data)[0])
                else:
                    link_ = Link.get_by_id(
                        origin.link('P107', actor, form.description.data)[0])
                link_.set_dates(process_form_dates(form))
                link_.type = get_link_type(form)
                link_.update()
            Transaction.commit()
            flash(_('entity created'), 'info')
        except Exception as e:  # pragma: no cover
            Transaction.rollback()
            logger.log('error', 'database', 'transaction failed', e)
            flash(_('error transaction'), 'error')
        if hasattr(form, 'continue_') and form.continue_.data == 'yes':
            return redirect(
                url_for('member_insert', origin_id=origin_id, code=code))
        return redirect(f"{url_for('view', id_=origin.id)}"
                        f"#tab-member{'' if code == 'member' else '-of'}")
    return render_template(
        'display_form.html',
        form=form,
        crumbs=[[_('actor'), url_for('index', view='actor')], origin,
                _('member')])