Ejemplo n.º 1
0
def stat(record_id, stat_id):
    # delete the identified statistic
    # check that we are authorised
    apikey = request.values.get("api_key")
    acc = models.Account.pull_by_auth_token(apikey)
    if acc is None:
        abort(401)
    
    # check that the record exists
    reg = models.Register.pull(record_id)
    if reg is None:
        abort(404)
        
    # check that the stat being removed exists
    stat = models.Statistics.pull(stat_id)
    if stat is None:
        abort(404)
    
    # if we get here, delete can go ahead
    try:
        RegistryAPI.delete_statistic(acc, stat)
    except AuthorisationException:
        abort(401)
    
    # return a json response
    resp = make_response(json.dumps({"success" : "true"}))
    resp.mimetype = "application/json"
    return resp