Example #1
0
def wfs_session(layer=None):
    user = current_user
    wfs_session = WFSSession.by_active_user_layer(layer, user)

    if not wfs_session:
        try:
            wfs_layers, wfs_layer_token = create_wfs(user, [layer])
        except MissingSchemaError:
            flash(_('layer unknown or without schema'))
            abort(404)
        wfs_session = WFSSession(user=user, layer=layer, url=url_for('.tinyows_wfs', token=wfs_layer_token, _external=True))
        db.session.add(wfs_session)
        db.session.commit()
    return render_template('maps/wfs_session.html', wfs_session=wfs_session)
Example #2
0
def cancel_changes(layer=None):
    user = current_user
    wfs_session = WFSSession.by_active_user_layer(layer, user)
    wfs_session.active=False
    wfs_session.update()
    db.session.commit()
    flash(_('wfs changes discarded'))
    return redirect(url_for('.wfs_edit'))
Example #3
0
def cancel_changes(layer=None):
    user = current_user

    wfs_session = WFSSession.by_active_user_layer(layer, user)
    wfs_session.active=False
    wfs_session.update()

    db.session.commit()

    flash(_('wfs changes discarded'))

    return redirect(url_for('.wfs_edit'))
Example #4
0
def wfs_session(layer=None):
    user = current_user
    wfs_session = WFSSession.by_active_user_layer(layer, user)

    if not wfs_session:
        try:
            wfs_layers, wfs_layer_token = create_wfs(user, [layer])
        except MissingSchemaError:
            flash(_('layer unknown or without schema'))
            abort(404)
        wfs_session = WFSSession(user=user, layer=layer, url=url_for('.tinyows_wfs', token=wfs_layer_token, _external=True))
        db.session.add(wfs_session)
        db.session.commit()
    return render_template('maps/wfs_session.html', wfs_session=wfs_session)
Example #5
0
def wfs_edit_layer(layer=None):
    form = WFSSearchForm()
    user = current_user
    wfs_session = WFSSession.by_active_user_layer(layer, user)

    if wfs_session:
        flash(_('external edit in progress'))
        return redirect(url_for('.wfs_session', layer=layer))

    couch = CouchDBBox(current_app.config.get('COUCH_DB_URL'), '%s_%s' % (SystemConfig.AREA_BOX_NAME, user.id))

    try:
        wfs_layers, wfs_layer_token = create_wfs(user, editable_layers=[layer])
    except MissingSchemaError:
        flash(_('layer unknown or without schema'))
        abort(404)

    features = [feature for feature in couch.iter_layer_features(current_app.config.get('USER_READONLY_LAYER')) if isinstance(feature['geometry'], dict)]


    data_extent = couch.layer_extent(layer)

    if not data_extent:
        data_extent = couch.layer_extent(current_app.config.get('USER_READONLY_LAYER'))
    if not data_extent:

        result = db.session.query(WMTS, ST_Transform(WMTS.view_coverage, 3857)).order_by(desc(WMTS.is_background_layer)).first()

        if result:
            data_extent = to_shape(result[1])

    titles = dict(couch.get_layer_names())
    return render_template(
        'maps/wfs.html',
        form=form,
        wfs=wfs_layers,
        layers=WMTS.query.all(),
        read_only_features=features,
        read_only_schema=couch.layer_schema(layer)['properties'],
        read_only_layer_name=current_app.config.get('AREA_BOX_TITLE'),
        editable_layer=layer,
        editable_layer_title=titles[layer],
        data_extent=data_extent.bounds if data_extent else None,
        user=current_user
    )
Example #6
0
def wfs_edit_layer(layer=None):
    user = current_user
    wfs_session = WFSSession.by_active_user_layer(layer, user)

    if wfs_session:
        flash(_('external edit in progress'))
        return redirect(url_for('.wfs_session', layer=layer))

    couch = CouchDBBox(current_app.config.get('COUCH_DB_URL'), '%s_%s' % (SystemConfig.AREA_BOX_NAME, user.id))

    try:
        wfs_layers, wfs_layer_token = create_wfs(user, [current_app.config.get('EXTERNAL_WFS_LAYER'), layer])
    except MissingSchemaError:
        flash(_('layer unknown or without schema'))
        abort(404)

    features = [feature for feature in couch.iter_layer_features(current_app.config.get('USER_READONLY_LAYER')) if isinstance(feature['geometry'], dict)]


    data_extent = couch.layer_extent(layer)

    if not data_extent:
        data_extent = couch.layer_extent(current_app.config.get('USER_READONLY_LAYER'))
    if not data_extent:
        result = db.session.query(WMTS, WMTS.view_coverage.transform(3857).wkt()).order_by(desc(WMTS.is_background_layer)).first()
        if result:
            data_extent = loads(result[1])

    return render_template(
        'maps/wfs.html',
        wfs=wfs_layers,
        layers=WMTS.query.all(),
        read_only_features=features,
        read_only_schema=couch.layer_schema(layer)['properties'],
        read_only_layer_name=current_app.config.get('USER_READONLY_LAYER_TITLE'),
        editable_layer=layer,
        editable_layer_name=wfs_layers[1]['name'],
        search_layer_name=current_app.config.get('EXTERNAL_WFS_NAME'),
        search_property=current_app.config.get('EXTERNAL_WFS_SEARCH_PROPERTY'),
        search_min_length=current_app.config.get('EXTERNAL_WFS_SEARCH_MIN_LENGTH'),
        search_prefix=current_app.config.get('EXTERNAL_WFS_SEARCH_PREFIX'),
        data_extent=data_extent.bounds if data_extent else None,
        user=current_user
    )
Example #7
0
def wfs_remove_layer(layer=None):
    user = current_user
    if layer in [current_app.config.get('USER_READONLY_LAYER'), current_app.config.get('USER_WORKON_LAYER')]:
        flash(_('not allowed to remove this layer'))
        return redirect(url_for('.wfs_edit'))

    wfs_session = WFSSession.by_active_user_layer(layer, user)
    if wfs_session:
        flash(_('external edit in progress'))
        return redirect(url_for('.wfs_session', layer=layer))

    couch = CouchDBBox(current_app.config.get('COUCH_DB_URL'), '%s_%s' % (SystemConfig.AREA_BOX_NAME, user.id))
    try:
        couch.clear_layer(layer)
        flash(_('Layer %(layer)s removed', layer=layer))
    except CouchDBError:
        flash(_('Could not remove layer %(layer)s', layer=layer), 'error')

    return redirect(url_for('.wfs_edit'))
Example #8
0
def wfs_remove_layer(layer=None):
    user = current_user
    if layer in [current_app.config.get('USER_READONLY_LAYER'), current_app.config.get('USER_WORKON_LAYER')]:
        flash(_('not allowed to remove this layer'))
        return redirect(url_for('.wfs_edit'))

    wfs_session = WFSSession.by_active_user_layer(layer, user)
    if wfs_session:
        flash(_('external edit in progress'))
        return redirect(url_for('.wfs_session', layer=layer))

    couch = CouchDBBox(current_app.config.get('COUCH_DB_URL'), '%s_%s' % (SystemConfig.AREA_BOX_NAME, user.id))
    try:
        couch.clear_layer(layer)
        flash(_('Layer %(layer)s removed', layer=layer))
    except CouchDBError:
        flash(_('Could not remove layer %(layer)s', layer=layer), 'error')

    return redirect(url_for('.wfs_edit'))