コード例 #1
0
def _paginate_submissions_or_by_ids(project_uuid, request):

    if request.GET.getlist('ids'):
        return _get_submissions_by_ids(project_uuid, request)
    else:
        is_slim_submission_requested = not (request.GET.get('view')
                                            and request.GET['view'] == 'full')
        survey_request = SurveyWebXformQuestionnaireRequest(
            request, project_uuid, XFormSubmissionProcessor())
        slim_submission_response = _get_slim_submission_paginated(
            request, project_uuid)

        if is_slim_submission_requested:
            return response_json_cors(slim_submission_response)

        ID_INDEX = 0
        submission_ids = [
            slim_submission[ID_INDEX]
            for slim_submission in slim_submission_response['data']
        ]
        submissions_response = survey_request.get_many_submissions(
            submission_ids)
        submissions_response_paginated = slim_submission_response
        submissions_response_paginated.update({'data': submissions_response})
        return response_json_cors(submissions_response_paginated)
コード例 #2
0
def get_delta_submission(request, project_uuid):
    survey_request = SurveyWebXformQuestionnaireRequest(
        request, project_uuid, XFormSubmissionProcessor())
    to_time = convert_date_time_to_epoch(datetime.utcnow())
    from_time = int(request.GET.get('last_fetch'))
    submissions = survey_request.get_submission_from(from_time, to_time)

    return response_json_cors({
        'submissions':
        submissions,
        'last_fetch':
        convert_date_time_to_epoch(datetime.utcnow())
    })
コード例 #3
0
def update_submission_or_get_by_id(request, project_uuid, submission_uuid):
    if request.method == 'GET':
        survey_request = SurveyWebXformQuestionnaireRequest(
            request, project_uuid, XFormSubmissionProcessor())
        content = survey_request.get_submission(submission_uuid)
        return response_json_cors(content)
    elif request.method == 'POST':
        try:
            form_code = _get_form_code_from_xform(request.POST['form_data'])
            response = XFormWebSubmissionHandler(request=request, form_code=form_code).\
                update_submission_response(submission_uuid)
            return enable_cors(response)
        except LookupError:
            return enable_cors(HttpResponseNotFound())
        except Exception as e:
            logger.exception("Exception in submission : \n%s" % e)
            return HttpResponseBadRequest()
コード例 #4
0
def edit_xform_submission_get(request, project_id, survey_response_id):
    survey_request = SurveyWebXformQuestionnaireRequest(
        request, project_id, XFormSubmissionProcessor())
    if request.method == 'GET':
        return survey_request.response_for_xform_edit_get_request(
            survey_response_id)
コード例 #5
0
def _get_submissions_by_ids(project_uuid, request):
    survey_request = SurveyWebXformQuestionnaireRequest(
        request, project_uuid, XFormSubmissionProcessor())
    submissions = survey_request.get_many_submissions(request.GET['ids'])
    return response_json_cors(submissions)