Beispiel #1
0
def api_map(map_name):
    eal = EAlGIS()
    defn = MapDefinition.get_by_name(map_name)
    if request.method == 'POST':
        if (defn is not None) and (not is_administrator(defn)):
            abort(403)
        try:
            if 'json' not in request.form:
                abort(400)
            if defn is None:
                defn = MapDefinition(name=map_name)
                eal.db.session.add(defn)
                eal.db.session.commit()
            try:
                rev = defn.set(json.loads(request.form['json']))
                eal.db.session.commit()
            except ValueError:
                abort(400)
            return jsonify(status="OK", updated=defn.get(), rev=rev)
        except CompilationError as e:
            return jsonify(status="ERROR",
                           title="Expression compilation failed",
                           mesg=e.message)
        except NoMatches as e:
            return jsonify(status="ERROR",
                           title="Attribute could not be resolved",
                           mesg=e.message)
        except TooManyMatches as e:
            return jsonify(status="ERROR",
                           title="Attribube reference is ambiguous",
                           mesg=e.message)
    elif request.method == 'DELETE':
        if defn is None:
            abort(404)
        if not is_administrator(defn):
            abort(403)
        eal.db.session.delete(defn)
        eal.db.session.commit()
        return jsonify(status="OK")
    else:
        if defn is None:
            abort(404)
        return jsonify(defn=defn.get(), administrator=is_administrator(defn))
Beispiel #2
0
def api_map(map_name):
    eal = EAlGIS()
    defn = MapDefinition.get_by_name(map_name)
    if request.method == 'POST':
        if (defn is not None) and (not is_administrator(defn)):
            abort(403)
        try:
            if 'json' not in request.form:
                abort(400)
            if defn is None:
                defn = MapDefinition(name=map_name)
                eal.db.session.add(defn)
                eal.db.session.commit()
            try:
                rev = defn.set(json.loads(request.form['json']))
                eal.db.session.commit()
            except ValueError:
                abort(400)
            return jsonify(status="OK", updated=defn.get(), rev=rev)
        except CompilationError as e:
            return jsonify(status="ERROR", title="Expression compilation failed", mesg=e.message)
        except NoMatches as e:
            return jsonify(status="ERROR", title="Attribute could not be resolved", mesg=e.message)
        except TooManyMatches as e:
            return jsonify(status="ERROR", title="Attribube reference is ambiguous", mesg=e.message)
    elif request.method == 'DELETE':
        if defn is None:
            abort(404)
        if not is_administrator(defn):
            abort(403)
        eal.db.session.delete(defn)
        eal.db.session.commit()
        return jsonify(status="OK")
    else:
        if defn is None:
            abort(404)
        return jsonify(defn=defn.get(), administrator=is_administrator(defn))