Example #1
0
 def retrieve(self, request, pk=None):  # TODO add tests for this
     '''
     Extending the default rest_framework endpoint for fetch one group to support the custom path/pseudo id of /groups/current
     That's the one pointed to by the settings record
     Note that the 'current' id does NOT work for updates/deletes, etc.
     '''
     if pk == 'current':
         group = get_current_group()
     else:  # TODO just defer to super() from here on
         group = get_object_or_404(self.queryset, pk=pk)
     serializer = GroupSerializer(group)
     return Response(serializer.data)
Example #2
0
 def retrieve(self, request, pk=None):  # TODO add tests for this
     '''
     Extending the default rest_framework endpoint for fetch one group to support the custom path/pseudo id of /groups/current
     That's the one pointed to by the settings record
     Note that the 'current' id does NOT work for updates/deletes, etc.
     '''
     if pk == 'current':
         group = get_current_group()
     else:  # TODO just defer to super() from here on
         group = get_object_or_404(self.queryset, pk=pk)
     serializer = GroupSerializer(group)
     return Response(serializer.data)
Example #3
0
def capture_sample(request):
    '''
    Calls the chain of tasks associated with getting a physical sample from the spectrometer according to the parameters
        specified in the current active group from (the settings record)
    Tasks are run asynchronously, relevant ids for created objects are returned
    '''
    group = get_current_group()

    try:
        response_dict = capture_sample_task(group)
        return Response(response_dict)
    except Exception as e:
        return Response(get_error_string_for_api(e), status=e.status_code)
Example #4
0
def capture_sample(request):
    '''
    Calls the chain of tasks associated with getting a physical sample from the spectrometer according to the parameters
        specified in the current active group from (the settings record)
    Tasks are run asynchronously, relevant ids for created objects are returned
    '''
    group = get_current_group()

    try:
        response_dict = capture_sample_task(group)
        return Response(response_dict)
    except Exception as e:
        return Response(get_error_string_for_api(e), status=e.status_code)
Example #5
0
def calibrate(request):
    '''
    Take a sample according to the current group config.
    Compare its data to the reference_sample_id passed in as a get parm
    On success return a SampleDelta object with the differences between the two samples
    '''
    # TODO add logic and tests for null reference_sample_id
    group = get_current_group()

    if 'reference_sample_id' in request.query_params and request.query_params['reference_sample_id']:
        try:
            return_data = calibrate_task(group, request.query_params['reference_sample_id'])
            return Response(return_data)
        except Exception as e:
            return Response(get_error_string_for_api(e), status=e.status_code)
    else:  # TODO add a test for this condition
        err_message = 'An id must be specified for a reference sample'
        return Response(data=err_message, status=409)
Example #6
0
def calibrate(request):
    '''
    Take a sample according to the current group config.
    Compare its data to the reference_sample_id passed in as a get parm
    On success return a SampleDelta object with the differences between the two samples
    '''
    # TODO add logic and tests for null reference_sample_id
    group = get_current_group()

    if 'reference_sample_id' in request.query_params and request.query_params[
            'reference_sample_id']:
        try:
            return_data = calibrate_task(
                group, request.query_params['reference_sample_id'])
            return Response(return_data)
        except Exception as e:
            return Response(get_error_string_for_api(e), status=e.status_code)
    else:  # TODO add a test for this condition
        err_message = 'An id must be specified for a reference sample'
        return Response(data=err_message, status=409)