Esempio n. 1
0
def refresh_florlp():
    user = current_user
    form = RefreshFlorlpForm(request.form)
    if form.validate_on_submit():
        layers = [(current_app.config.get('USER_READONLY_LAYER'), current_app.config.get('USER_READONLY_LAYER_TITLE'))]
        try:
            florlp_session = create_florlp_session(user.florlp_name, form.data['password'])
        except FLOrlpUnauthenticated:
            flash(_('Invalid florlp password'), 'error')
            return render_template("user/refresh_florlp.html", form=form)
        try:
            schema, feature_collection = latest_flursteuck_features(florlp_session)
        finally:
            remove_florlp_session(florlp_session)

        feature_collection = transform_geojson(from_srs=current_app.config.get('FLORLP_SHP_SRS'), to_srs=3857, geojson=feature_collection)

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

        if (not couch.layer_schema(current_app.config.get('USER_WORKON_LAYER')) or not couch.layer_extent(current_app.config.get('USER_WORKON_LAYER'))) and not user.type:
            layers.append((current_app.config.get('USER_WORKON_LAYER'), current_app.config.get('USER_WORKON_LAYER_TITLE')))

        for layer, title in layers:
            couch.clear_layer(layer)
            couch.store_layer_schema(layer, schema, title=title)
            couch.store_features(layer, feature_collection['features'])

            signals.features_updated.send(user, layer=layer)


        flash(_('Refreshed florlp data'), 'success')
        return redirect(url_for(".index"))
    return render_template("user/refresh_florlp.html", form=form)
Esempio n. 2
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'))
Esempio n. 3
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'))
Esempio n. 4
0
def init_couchdb(config):
    user = model.User.by_email('*****@*****.**')
    init_user_boxes(user, config.get('COUCH_DB_URL'))
    couch = CouchDBBox(config.get('COUCH_DB_URL'), '%s_%s' % (SystemConfig.AREA_BOX_NAME, user.id))
    layers = [(config.get('USER_READONLY_LAYER'), config.get('USER_READONLY_LAYER_TITLE')), (config.get('USER_WORKON_LAYER'), config.get('USER_WORKON_LAYER_TITLE'))]
    print layers
    florlp_session = create_florlp_session("demo", "demo")
    try:
        schema, feature_collection = latest_flursteuck_features(florlp_session)
    finally:
        remove_florlp_session(florlp_session)

    feature_collection = transform_geojson(from_srs=config.get('FLORLP_SHP_SRS'), to_srs=3857, geojson=feature_collection)
    for layer, title in layers:
        couch.clear_layer(layer)
        couch.store_layer_schema(layer, schema, title=title)
        couch.store_features(layer, feature_collection['features'])

    user = model.User.by_email('*****@*****.**')
    init_user_boxes(user, config.get('COUCH_DB_URL'))