Exemple #1
0
def render_form(request, domain):
    # get session
    session_id = request.GET.get('session_id')

    session = get_object_or_404(EntrySession, session_id=session_id)

    response = requests.post("{base_url}/webforms/get-xml/{session_id}".format(
        base_url=get_url_base(),
        session_id=session_id)
    )

    if response.status_code is not 200:
        err = "Session XML could not be found"
        return HttpResponse(err, status=500, content_type="text/plain")

    response_json = json.loads(response.text)
    xmlns = response_json["xmlns"]
    form_data_xml = response_json["output"]

    _, form_data_json = xml2json(form_data_xml)
    pretty_questions = readable.get_questions(domain, session.app_id, xmlns)

    readable_form = readable.get_readable_form_data(form_data_json, pretty_questions)

    rendered_readable_form = render_to_string(
        'reports/form/partials/readable_form.html',
        {'questions': readable_form}
    )

    return json_response({
        'form_data': rendered_readable_form,
        'instance_xml': render_pretty_xml(form_data_xml)
    })
Exemple #2
0
def render_form(request, domain):
    # get session
    session_id = request.GET.get('session_id')

    session = get_object_or_404(EntrySession, session_id=session_id)

    try:
        raw_instance = get_raw_instance(session_id, domain)
    except Exception as e:
        return HttpResponse(e, status=500, content_type="text/plain")

    xmlns = raw_instance["xmlns"]
    form_data_xml = raw_instance["output"]

    _, form_data_json = xml2json(form_data_xml)
    pretty_questions = readable.get_questions(domain, session.app_id, xmlns)

    readable_form = readable.get_readable_form_data(form_data_json,
                                                    pretty_questions)

    rendered_readable_form = render_to_string(
        'reports/form/partials/readable_form.html',
        {'questions': readable_form})

    return json_response({
        'form_data': rendered_readable_form,
        'instance_xml': indent_xml(form_data_xml)
    })
Exemple #3
0
def render_form(request, domain):
    # get session
    session_id = request.GET.get('session_id')

    session = get_object_or_404(EntrySession, session_id=session_id)

    response = requests.post("{base_url}/webforms/get-xml/{session_id}".format(
        base_url=get_url_base(), session_id=session_id))

    if response.status_code is not 200:
        err = "Session XML could not be found"
        return HttpResponse(err, status=500, content_type="text/plain")

    response_json = json.loads(response.text)
    xmlns = response_json["xmlns"]
    form_data_xml = response_json["output"]

    _, form_data_json = xml2json(form_data_xml)
    pretty_questions = readable.get_questions(domain, session.app_id, xmlns)

    readable_form = readable.get_readable_form_data(form_data_json,
                                                    pretty_questions)

    rendered_readable_form = render_to_string(
        'reports/form/partials/readable_form.html',
        {'questions': readable_form})

    return json_response({
        'form_data': rendered_readable_form,
        'instance_xml': render_pretty_xml(form_data_xml)
    })
Exemple #4
0
    def post(self, request, domain):
        instance_xml = request.POST.get('instanceXml').encode('utf-8')
        app_id = request.POST.get('appId')
        xmlns = request.POST.get('xmlns')

        _, form_data_json = xml2json(instance_xml)
        pretty_questions = readable.get_questions(domain, app_id, xmlns)

        readable_form = readable.get_readable_form_data(
            form_data_json, pretty_questions)

        rendered_readable_form = render_to_string(
            'reports/form/partials/readable_form.html',
            {'questions': readable_form})

        return json_response({
            'form_data': rendered_readable_form,
        })
Exemple #5
0
    def post(self, request, domain):
        instance_xml = request.POST.get('instanceXml').encode('utf-8')
        app_id = request.POST.get('appId')
        xmlns = request.POST.get('xmlns')

        _, form_data_json = xml2json(instance_xml)
        pretty_questions = readable.get_questions(domain, app_id, xmlns)

        readable_form = readable.get_readable_form_data(form_data_json, pretty_questions)

        rendered_readable_form = render_to_string(
            'reports/form/partials/readable_form.html',
            {'questions': readable_form}
        )

        return json_response({
            'form_data': rendered_readable_form,
            'form_questions': pretty_questions
        })
Exemple #6
0
@cloudcare_api
def render_form(request, domain):
    # get session
    session_id = request.GET.get('session_id')

    session = get_object_or_404(EntrySession, session_id=session_id)

    try:
        raw_instance = get_raw_instance(session_id, domain)
    except Exception, e:
        return HttpResponse(e, status=500, content_type="text/plain")

    xmlns = raw_instance["xmlns"]
    form_data_xml = raw_instance["output"]

    _, form_data_json = xml2json(form_data_xml)
    pretty_questions = readable.get_questions(domain, session.app_id, xmlns)

    readable_form = readable.get_readable_form_data(form_data_json,
                                                    pretty_questions)

    rendered_readable_form = render_to_string(
        'reports/form/partials/readable_form.html',
        {'questions': readable_form})

    return json_response({
        'form_data': rendered_readable_form,
        'instance_xml': indent_xml(form_data_xml)
    })

Exemple #7
0
@cloudcare_api
def render_form(request, domain):
    # get session
    session_id = request.GET.get('session_id')

    session = get_object_or_404(EntrySession, session_id=session_id)

    try:
        raw_instance = get_raw_instance(session_id, domain)
    except Exception, e:
        return HttpResponse(e, status=500, content_type="text/plain")

    xmlns = raw_instance["xmlns"]
    form_data_xml = raw_instance["output"]

    _, form_data_json = xml2json(form_data_xml)
    pretty_questions = readable.get_questions(domain, session.app_id, xmlns)

    readable_form = readable.get_readable_form_data(form_data_json, pretty_questions)

    rendered_readable_form = render_to_string(
        'reports/form/partials/readable_form.html',
        {'questions': readable_form}
    )

    return json_response({
        'form_data': rendered_readable_form,
        'instance_xml': indent_xml(form_data_xml)
    })