예제 #1
0
def agent_profile_get(req_dict):
    # add ETag for concurrency
    agent = req_dict['params']['agent']
    a = Agent.objects.retrieve(**agent)
    if not a:
        response = HttpResponseNotFound("No agent found for agent profile get")
    else:
        ap = AgentProfileManager(a)

        profile_id = req_dict['params'].get('profileId', None) if 'params' in req_dict else None
        if profile_id:
            resource = ap.get_profile(profile_id)
            if resource.profile:
                response = HttpResponse(resource.profile.read(), content_type=resource.content_type)
            else:
                response = HttpResponse(resource.json_profile, content_type=resource.content_type)
            response['ETag'] = '"%s"' % resource.etag
            return response

        since = req_dict['params'].get('since', None) if 'params' in req_dict else None
        resource = ap.get_profile_ids(since)
        response = JsonResponse([k for k in resource], safe=False)
    
    # If it's a HEAD request
    if req_dict['method'].lower() != 'get':
        response.body = ''
    return response
예제 #2
0
def agent_profile_get(req_dict):
    # add ETag for concurrency
    agent = req_dict['params']['agent']
    a = Agent.objects.retrieve(**agent)
    if not a:
        response = HttpResponseNotFound("No agent found for agent profile get")
    else:
        ap = AgentProfileManager(a)

        profile_id = req_dict['params'].get('profileId', None) if 'params' in req_dict else None
        if profile_id:
            resource = ap.get_profile(profile_id)
            if resource.profile:
                response = HttpResponse(resource.profile.read(), content_type=resource.content_type)
            else:
                response = HttpResponse(resource.json_profile, content_type=resource.content_type)
            response['ETag'] = '"%s"' % resource.etag
            return response

        since = req_dict['params'].get('since', None) if 'params' in req_dict else None
        resource = ap.get_profile_ids(since)
        response = JsonResponse([k for k in resource], safe=False)
    
    # If it's a HEAD request
    if req_dict['method'].lower() != 'get':
        response.body = ''
    return response
예제 #3
0
def activity_state_get(req_dict):
    # add ETag for concurrency
    state_id = req_dict['params'].get('stateId', None)
    activity_id = req_dict['params']['activityId']
    agent = req_dict['params']['agent']
    a = Agent.objects.retrieve(**agent)
    if not a:
        response = HttpResponseNotFound("No agent found for activity state")
    else:    
        registration = req_dict['params'].get('registration', None)
        actstate = ActivityStateManager(a)
        # state id means we want only 1 item
        if state_id:
            resource = actstate.get_state(activity_id, registration, state_id)
            if resource.state:
                response = HttpResponse(resource.state.read(), content_type=resource.content_type)
            else:
                response = HttpResponse(resource.json_state, content_type=resource.content_type)
            response['ETag'] = '"%s"' % resource.etag
        # no state id means we want an array of state ids
        else:
            since = req_dict['params'].get('since', None)
            resource = actstate.get_state_ids(activity_id, registration, since)
            response = JsonResponse([k for k in resource], safe=False)
    
    # If it's a HEAD request
    if req_dict['method'].lower() != 'get':
        response.body = ''
    return response
예제 #4
0
def activity_state_get(req_dict):
    # add ETag for concurrency
    state_id = req_dict['params'].get('stateId', None)
    activity_id = req_dict['params']['activityId']
    agent = req_dict['params']['agent']
    a = Agent.objects.retrieve(**agent)
    if not a:
        response = HttpResponseNotFound("No agent found for activity state")
    else:    
        registration = req_dict['params'].get('registration', None)
        actstate = ActivityStateManager(a)
        # state id means we want only 1 item
        if state_id:
            resource = actstate.get_state(activity_id, registration, state_id)
            if resource.state:
                response = HttpResponse(resource.state.read(), content_type=resource.content_type)
            else:
                response = HttpResponse(resource.json_state, content_type=resource.content_type)
            response['ETag'] = '"%s"' % resource.etag
        # no state id means we want an array of state ids
        else:
            since = req_dict['params'].get('since', None)
            resource = actstate.get_state_ids(activity_id, registration, since)
            response = JsonResponse([k for k in resource], safe=False)
    
    # If it's a HEAD request
    if req_dict['method'].lower() != 'get':
        response.body = ''
    return response