Esempio n. 1
0
def actor_update(id_):
    actor = EntityMapper.get_by_id(id_)
    actor.set_dates()
    code_class = {'E21': 'Person', 'E74': 'Group', 'E40': 'Legal Body'}
    form = build_form(ActorForm, code_class[actor.class_.code], actor, request)
    if form.validate_on_submit():
        if was_modified(form, actor):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(
                logger.get_log_for_advanced_view(actor.id)['modifier'])
            return render_template('actor/update.html',
                                   form=form,
                                   actor=actor,
                                   modifier=modifier)
        save(form, actor)
        return redirect(url_for('actor_view', id_=id_))
    residence = actor.get_linked_entity('P74')
    form.residence.data = residence.get_linked_entity(
        'P53', True).id if residence else ''
    first = actor.get_linked_entity('OA8')
    form.appears_first.data = first.get_linked_entity('P53',
                                                      True).id if first else ''
    last = actor.get_linked_entity('OA9')
    form.appears_last.data = last.get_linked_entity('P53',
                                                    True).id if last else ''
    for alias in [x.name for x in actor.get_linked_entities('P131')]:
        form.alias.append_entry(alias)
    form.alias.append_entry('')
    return render_template('actor/update.html', form=form, actor=actor)
Esempio n. 2
0
def update(id_: int) -> Union[str, Response]:
    entity = Entity.get_by_id(id_, types=True, aliases=True)
    check_update_access(entity)
    if entity.check_for_too_many_links_for_single_type():
        abort(422)
    place_info = get_place_info_for_update(entity)
    form = build_form(entity.class_.name,
                      entity,
                      location=place_info['location'])
    if form.validate_on_submit():
        if isinstance(entity, Type) and not check_type(entity, form):
            return redirect(url_for('view', id_=entity.id))
        if was_modified(form, entity):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            return render_template(
                'entity/update.html',
                form=form,
                entity=entity,
                modifier=link(logger.get_log_info(entity.id)['modifier']))
        return redirect(save(form, entity))
    populate_update_form(form, entity)
    if entity.class_.view in ['artifact', 'place']:
        entity.set_image_for_places()
    return render_template(
        'entity/update.html',
        form=form,
        entity=entity,
        gis_data=place_info['gis_data'],
        overlays=place_info['overlays'],
        geonames_module=check_geonames_module(entity.class_.name),
        title=entity.name,
        crumbs=add_crumbs(entity.class_.name, entity, place_info['structure']))
Esempio n. 3
0
def actor_update(id_: int) -> str:
    actor = EntityMapper.get_by_id(id_, nodes=True, aliases=True)
    code_class = {'E21': 'Person', 'E74': 'Group', 'E40': 'Legal Body'}
    form = build_form(ActorForm, code_class[actor.class_.code], actor, request)
    if form.validate_on_submit():
        if was_modified(form, actor):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(
                logger.get_log_for_advanced_view(actor.id)['modifier'])
            return render_template('actor/update.html',
                                   form=form,
                                   actor=actor,
                                   modifier=modifier)
        save(form, actor)
        return redirect(url_for('actor_view', id_=id_))
    residence = actor.get_linked_entity('P74')
    form.residence.data = residence.get_linked_entity(
        'P53', True).id if residence else ''
    first = actor.get_linked_entity('OA8')
    form.begins_in.data = first.get_linked_entity('P53',
                                                  True).id if first else ''
    last = actor.get_linked_entity('OA9')
    form.ends_in.data = last.get_linked_entity('P53', True).id if last else ''
    for alias in actor.aliases.values():
        form.alias.append_entry(alias)
    form.alias.append_entry('')
    if actor.class_.code == 'E21':
        form.begins_in.label.text = _('born in')
        form.ends_in.label.text = _('died in')
    return render_template('actor/update.html', form=form, actor=actor)
Esempio n. 4
0
def event_update(id_):
    event = EntityMapper.get_by_id(id_)
    event.set_dates()
    form = build_form(EventForm, 'Event', event, request)
    if event.class_.code != 'E8':
        del form.given_place
    form.event_id.data = event.id
    if form.validate_on_submit():
        if was_modified(form, event):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(
                logger.get_log_for_advanced_view(event.id)['modifier'])
            return render_template('event/update.html',
                                   form=form,
                                   event=event,
                                   modifier=modifier)
        save(form, event)
        return redirect(url_for('event_view', id_=id_))
    super_event = event.get_linked_entity('P117')
    form.event.data = super_event.id if super_event else ''
    place = event.get_linked_entity('P7')
    form.place.data = place.get_linked_entity('P53', True).id if place else ''
    if event.class_.code == 'E8':  # Form data for acquisition
        form.given_place.data = [
            entity.id for entity in event.get_linked_entities('P24')
        ]
    return render_template('event/update.html', form=form, event=event)
Esempio n. 5
0
def source_update(id_):
    source = EntityMapper.get_by_id(id_)
    form = build_form(SourceForm, 'Source', source, request)
    if form.validate_on_submit():
        if was_modified(form, source):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(logger.get_log_for_advanced_view(source.id)['modifier'])
            return render_template(
                'source/update.html', form=form, source=source, modifier=modifier)
        save(form, source)
        return redirect(url_for('source_view', id_=id_))
    return render_template('source/update.html', form=form, source=source)
def source_update(id_):
    source = EntityMapper.get_by_id(id_)
    form = build_form(SourceForm, 'Source', source, request)
    if form.validate_on_submit():
        if was_modified(form, source):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(logger.get_log_for_advanced_view(source.id)['modifier'])
            return render_template('source/update.html', form=form, source=source,
                                   modifier=modifier)
        save(form, source)
        return redirect(url_for('source_view', id_=id_))
    return render_template('source/update.html', form=form, source=source)
Esempio n. 7
0
def object_update(id_: int) -> str:
    object_ = EntityMapper.get_by_id(id_, nodes=True)
    form = build_form(InformationCarrierForm, object_.system_type.title(),
                      object_, request)
    if form.validate_on_submit():
        if was_modified(form, object_):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(
                logger.get_log_for_advanced_view(object_.id)['modifier'])
            return render_template('object/update.html',
                                   form=form,
                                   object_=object_,
                                   modifier=modifier)
        save(form, object_)
        return redirect(url_for('object_view', id_=id_))
    return render_template('object/update.html', form=form, object_=object_)
Esempio n. 8
0
def file_update(id_: int) -> str:
    file = EntityMapper.get_by_id(id_, nodes=True)
    form = build_form(FileForm, 'File', file, request)
    del form.file
    if form.validate_on_submit():
        if was_modified(form, file):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(
                logger.get_log_for_advanced_view(file.id)['modifier'])
            return render_template('file/update.html',
                                   form=form,
                                   file=file,
                                   modifier=modifier)
        save(form, file)
        return redirect(url_for('file_view', id_=id_))
    return render_template('file/update.html', form=form, file=file)
Esempio n. 9
0
def event_update(id_: int) -> str:
    event = EntityMapper.get_by_id(id_, nodes=True)
    form = prepare_form(build_form(EventForm, 'Event', event, request),
                        event.class_.code)
    form.event_id.data = event.id
    if form.validate_on_submit():
        if was_modified(form, event):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(
                logger.get_log_for_advanced_view(event.id)['modifier'])
            return render_template('event/update.html',
                                   form=form,
                                   event=event,
                                   modifier=modifier)
        save(form, event)
        return redirect(url_for('event_view', id_=id_))
    super_event = event.get_linked_entity('P117')
    form.event.data = super_event.id if super_event else ''
    if event.class_.code == 'E9':  # Form data for move
        place_from = event.get_linked_entity('P27')
        form.place_from.data = place_from.get_linked_entity(
            'P53', True).id if place_from else ''
        place_to = event.get_linked_entity('P26')
        form.place_to.data = place_to.get_linked_entity(
            'P53', True).id if place_to else ''
        person_data = []
        object_data = []
        for entity in event.get_linked_entities('P25'):
            if entity.class_.code == 'E21':
                person_data.append(entity.id)
            elif entity.class_.code == 'E84':
                object_data.append(entity.id)
        form.person.data = person_data
        form.object.data = object_data
    else:
        place = event.get_linked_entity('P7')
        form.place.data = place.get_linked_entity('P53',
                                                  True).id if place else ''
    if event.class_.code == 'E8':  # Form data for acquisition
        form.given_place.data = [
            entity.id for entity in event.get_linked_entities('P24')
        ]
    return render_template('event/update.html', form=form, event=event)
Esempio n. 10
0
def source_update(id_: int) -> str:
    source = EntityMapper.get_by_id(id_, nodes=True)
    form = build_form(SourceForm, 'Source', source, request)
    if form.validate_on_submit():
        if was_modified(form, source):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(
                logger.get_log_for_advanced_view(source.id)['modifier'])
            return render_template('source/update.html',
                                   form=form,
                                   source=source,
                                   modifier=modifier)
        save(form, source)
        return redirect(url_for('source_view', id_=id_))
    form.information_carrier.data = [
        entity.id
        for entity in source.get_linked_entities('P128', inverse=True)
    ]
    return render_template('source/update.html', form=form, source=source)
Esempio n. 11
0
def place_update(id_):
    object_ = EntityMapper.get_by_id(id_)
    object_.set_dates()
    location = object_.get_linked_entity('P53')
    if object_.system_type == 'feature':
        form = build_form(FeatureForm, 'Feature', object_, request, location)
    elif object_.system_type == 'stratigraphic unit':
        form = build_form(FeatureForm, 'Stratigraphic Unit', object_, request, location)
    elif object_.system_type == 'find':
        form = build_form(FeatureForm, 'Find', object_, request, location)
    else:
        form = build_form(PlaceForm, 'Place', object_, request, location)
    if form.validate_on_submit():
        if was_modified(form, object_):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(logger.get_log_for_advanced_view(object_.id)['modifier'])
            return render_template(
                'place/update.html', form=form, object_=object_, modifier=modifier)
        save(form, object_, location)
        return redirect(url_for('place_view', id_=id_))
    for alias in [x.name for x in object_.get_linked_entities('P1')]:
        form.alias.append_entry(alias)
    if object_.system_type == 'place':
        form.alias.append_entry('')
    gis_data = GisMapper.get_all(object_.id)
    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)
    if 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/update.html', form=form, object_=object_, gis_data=gis_data,
                           place=place, feature=feature, stratigraphic_unit=stratigraphic_unit)
Esempio n. 12
0
def reference_update(id_: int) -> str:
    reference = EntityMapper.get_by_id(id_, nodes=True)
    form = build_form(ReferenceForm, reference.system_type.title(), reference,
                      request)
    if reference.system_type == 'external reference':
        form.name.validators = [InputRequired(), URL()]
        form.name.label.text = 'URL'
    if form.validate_on_submit():
        if was_modified(form, reference):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(
                logger.get_log_for_advanced_view(reference.id)['modifier'])
            return render_template('reference/update.html',
                                   form=form,
                                   reference=reference,
                                   modifier=modifier)
        save(form, reference)
        return redirect(url_for('reference_view', id_=id_))
    return render_template('reference/update.html',
                           form=form,
                           reference=reference)
Esempio n. 13
0
def event_update(id_):
    event = EntityMapper.get_by_id(id_)
    event.set_dates()
    form = build_form(EventForm, 'Event', event, request)
    if event.class_.code != 'E8':
        del form.given_place
    form.event_id.data = event.id
    if form.validate_on_submit():
        if was_modified(form, event):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(logger.get_log_for_advanced_view(event.id)['modifier'])
            return render_template('event/update.html', form=form, event=event, modifier=modifier)
        save(form, event)
        return redirect(url_for('event_view', id_=id_))
    super_event = event.get_linked_entity('P117')
    form.event.data = super_event.id if super_event else ''
    place = event.get_linked_entity('P7')
    form.place.data = place.get_linked_entity('P53', True).id if place else ''
    if event.class_.code == 'E8':  # Form data for acquisition
        form.given_place.data = [entity.id for entity in event.get_linked_entities('P24')]
    return render_template('event/update.html', form=form, event=event)
Esempio n. 14
0
def actor_update(id_):
    actor = EntityMapper.get_by_id(id_)
    actor.set_dates()
    code_class = {'E21': 'Person', 'E74': 'Group', 'E40': 'Legal Body'}
    form = build_form(ActorForm, code_class[actor.class_.code], actor, request)
    if form.validate_on_submit():
        if was_modified(form, actor):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(logger.get_log_for_advanced_view(actor.id)['modifier'])
            return render_template('actor/update.html', form=form, actor=actor, modifier=modifier)
        save(form, actor)
        return redirect(url_for('actor_view', id_=id_))
    residence = actor.get_linked_entity('P74')
    form.residence.data = residence.get_linked_entity('P53', True).id if residence else ''
    first = actor.get_linked_entity('OA8')
    form.appears_first.data = first.get_linked_entity('P53', True).id if first else ''
    last = actor.get_linked_entity('OA9')
    form.appears_last.data = last.get_linked_entity('P53', True).id if last else ''
    for alias in [x.name for x in actor.get_linked_entities('P131')]:
        form.alias.append_entry(alias)
    form.alias.append_entry('')
    return render_template('actor/update.html', form=form, actor=actor)
Esempio n. 15
0
def update(id_: int) -> Union[str, Response]:
    entity = Entity.get_by_id(id_, nodes=True, aliases=True)
    if not entity.class_.view:
        abort(422)  # pragma: no cover
    elif not is_authorized(entity.class_.write_access):
        abort(403)  # pragma: no cover
    elif isinstance(entity, Node):
        root = g.nodes[entity.root[-1]] if entity.root else None
        if not root and (entity.standard or entity.locked):
            abort(403)  # pragma: no cover

    # Archaeological sub units
    geonames_module = False
    if entity.class_.name == 'place' and ReferenceSystem.get_by_name(
            'GeoNames').forms:
        geonames_module = True
    structure = None
    gis_data = None
    overlays = None
    location = None

    if entity.class_.view in ['artifact', 'place']:
        structure = get_structure(entity)
        location = entity.get_linked_entity_safe('P53', nodes=True)
        gis_data = Gis.get_all([entity], structure)
        overlays = Overlay.get_by_object(entity)

    form = build_form(entity.class_.name, entity, location=location)

    if entity.class_.view == 'event':
        form.event_id.data = entity.id
    elif isinstance(entity, ReferenceSystem) and entity.system:
        form.name.render_kw['readonly'] = 'readonly'
    if form.validate_on_submit():
        if isinstance(entity, Node):
            valid = True
            root = g.nodes[entity.root[-1]]
            new_super_id = getattr(form, str(root.id)).data
            new_super = g.nodes[int(new_super_id)] if new_super_id else None
            if new_super:
                if new_super.id == entity.id:
                    flash(_('error node self as super'), 'error')
                    valid = False
                if new_super.root and entity.id in new_super.root:
                    flash(_('error node sub as super'), 'error')
                    valid = False
            if not valid:
                return redirect(url_for('entity_view', id_=entity.id))
        if was_modified(form, entity):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            return render_template('entity/update.html',
                                   form=form,
                                   entity=entity,
                                   structure=structure,
                                   modifier=link(
                                       logger.get_log_for_advanced_view(
                                           entity.id)['modifier']))
        return redirect(save(form, entity))
    populate_update_form(form, entity)
    return render_template('entity/update.html',
                           form=form,
                           entity=entity,
                           structure=structure,
                           gis_data=gis_data,
                           overlays=overlays,
                           geonames_module=geonames_module,
                           title=entity.name,
                           crumbs=add_crumbs(view_name=entity.class_.view,
                                             class_=entity.class_.name,
                                             origin=entity,
                                             structure=structure))
Esempio n. 16
0
def place_update(id_: int) -> str:
    object_ = EntityMapper.get_by_id(id_, nodes=True, aliases=True)
    location = object_.get_linked_entity('P53', nodes=True)
    geonames_buttons = False
    if object_.system_type == 'feature':
        form = build_form(FeatureForm, 'Feature', object_, request, location)
    elif object_.system_type == 'stratigraphic unit':
        form = build_form(FeatureForm, 'Stratigraphic Unit', object_, request,
                          location)
    elif object_.system_type == 'find':
        form = build_form(FeatureForm, 'Find', object_, request, location)
    else:
        geonames_buttons = True if current_user.settings[
            'module_geonames'] else False
        form = build_form(PlaceForm, 'Place', object_, request, location)
    if hasattr(form,
               'geonames_id') and not current_user.settings['module_geonames']:
        del form.geonames_id, form.geonames_precision  # pragma: no cover
    if form.validate_on_submit():
        if was_modified(form, object_):  # pragma: no cover
            del form.save
            flash(_('error modified'), 'error')
            modifier = link(
                logger.get_log_for_advanced_view(object_.id)['modifier'])
            return render_template('place/update.html',
                                   form=form,
                                   object_=object_,
                                   modifier=modifier)
        save(form, object_, location)
        return redirect(url_for('place_view', id_=id_))
    if object_.system_type == 'place':
        for alias in object_.aliases.values():
            form.alias.append_entry(alias)
        form.alias.append_entry('')
    gis_data = GisMapper.get_all(object_)
    if hasattr(form,
               'geonames_id') and current_user.settings['module_geonames']:
        geonames_link = GeonamesMapper.get_geonames_link(object_)
        if geonames_link:
            geonames_entity = geonames_link.domain
            form.geonames_id.data = geonames_entity.name if geonames_entity else ''
            exact_match = True if g.nodes[
                geonames_link.type.id].name == 'exact match' else False
            form.geonames_precision.data = exact_match
    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)
    if 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)

    overlays = OverlayMapper.get_by_object(object_) if current_user.settings['module_map_overlay'] \
        else None

    return render_template('place/update.html',
                           form=form,
                           object_=object_,
                           gis_data=gis_data,
                           place=place,
                           feature=feature,
                           stratigraphic_unit=stratigraphic_unit,
                           overlays=overlays,
                           geonames_buttons=geonames_buttons)