Ejemplo n.º 1
0
def statements_post(req_dict):
    stmt_responses = []

    log_dict = req_dict['initial_user_action'] 
    log_info_processing(log_dict, 'POST', __name__)

    define = True
    if 'oauth_define' in req_dict:
        define = req_dict['oauth_define']    

    # Handle batch POST
    if type(req_dict['body']) is list:
        try:
            for st in req_dict['body']:
                stmt = Statement.Statement(st, auth=req_dict['auth'], log_dict=log_dict,
                    define=define).model_object
                stmt_responses.append(str(stmt.statement_id))
        except Exception, e:
            for stmt_id in stmt_responses:
                try:
                    models.statement.objects.get(statement_id=stmt_id).delete()
                except models.statement.DoesNotExist:
                    pass # stmt already deleted 
            log_exception(log_dict, e.message, statements_post.__name__)
            update_parent_log_status(log_dict, 500)
            raise e
Ejemplo n.º 2
0
def statements_get(req_dict):
    log_dict = req_dict['initial_user_action']    
    log_info_processing(log_dict, 'GET', __name__)
    
    if 'statements_mine_only' in req_dict:
        mine_only = True
    else:
        mine_only = False

    stmt_result = {}
    # If statementId is in req_dict then it is a single get
    if 'statementId' in req_dict:
        statementId = req_dict['statementId']
        # Try to retrieve stmt, if DNE then return empty else return stmt info                
        try:
            st = models.statement.objects.get(statement_id=statementId)
        except models.statement.DoesNotExist:
            err_msg = 'There is no statement associated with the id: %s' % statementId
            log_exception(log_dict, err_msg, statements_get.__name__)
            update_parent_log_status(log_dict, 404)
            raise exceptions.IDNotFoundError(err_msg)
        
        # check if stmt authority is in oauth group
        if mine_only and not (st.authority.id == req_dict['auth'].id):
            raise exceptions.Forbidden("Incorrect permissions to view statements that do not have auth %s" % str(req_dict['auth']))

        stmt_result = st.object_return()
    else:
        stmt_list = retrieve_statement.complex_get(req_dict)
        stmt_result = retrieve_statement.build_statement_result(req_dict, stmt_list)
    
    update_parent_log_status(log_dict, 200)

    return HttpResponse(stream_response_generator(stmt_result), mimetype="application/json", status=200)
Ejemplo n.º 3
0
def activities_get(req_dict):
    log_dict = req_dict['initial_user_action']    
    log_info_processing(log_dict, 'GET', __name__)

    activityId = req_dict['activityId']
    # Try to retrieve activity, if DNE then return empty else return activity info
    act_list = models.activity.objects.filter(activity_id=activityId)
    if not act_list:
        err_msg = "No activities found with ID %s" % activityId
        log_exception(log_dict, err_msg, activities_get.__name__)
        update_parent_log_status(log_dict, 404)
        raise exceptions.IDNotFoundError(err_msg)
    
    full_act_list = []
    for act in act_list:
        full_act_list.append(act.object_return())

    update_parent_log_status(log_dict, 200)
    return HttpResponse(json.dumps([k for k in full_act_list]), mimetype="application/json", status=200)
Ejemplo n.º 4
0
def statements_get(req_dict):
    log_dict = req_dict['initial_user_action']    
    log_info_processing(log_dict, 'GET', __name__)

    stmt_result = {}
    # If statementId is in req_dict then it is a single get
    if 'statementId' in req_dict:
        statementId = req_dict['statementId']
        # Try to retrieve stmt, if DNE then return empty else return stmt info                
        try:
            st = models.statement.objects.get(statement_id=statementId)
        except models.statement.DoesNotExist:
            err_msg = 'There is no statement associated with the id: %s' % statementId
            log_exception(log_dict, err_msg, statements_get.__name__)
            update_parent_log_status(log_dict, 404)
            raise exceptions.IDNotFoundError(err_msg)
        stmt_result = st.object_return()
    else:
        stmt_list = retrieve_statement.complex_get(req_dict)
        stmt_result = retrieve_statement.build_statement_result(req_dict.copy(), stmt_list)
    
    update_parent_log_status(log_dict, 200)
    return HttpResponse(stream_response_generator(stmt_result), mimetype="application/json", status=200)