コード例 #1
0
ファイル: xform_tags.py プロジェクト: saketkanth/commcare-hq
def render_form_xml(form):
    xml = form.get_xml()
    if isinstance(xml, unicode):
        xml.encode('utf-8', errors='replace')
    formatted_xml = indent_xml(xml) if xml else ''
    return '<pre class="fancy-code prettyprint linenums"><code class="no-border language-xml">%s</code></pre>' \
           % escape(formatted_xml)
コード例 #2
0
    def get(self, request, domain):
        record_id = request.GET.get('record_id')
        record = self.get_record_or_404(request, domain, record_id)
        content_type = record.repeater.generator.content_type
        try:
            payload = record.get_payload()
        except XFormNotFound:
            return json_response(
                {
                    'error':
                    u'Odd, could not find payload for: {}'.format(
                        record.payload_id)
                },
                status_code=404)

        if content_type == 'text/xml':
            payload = indent_xml(payload)
        elif content_type == 'application/json':
            payload = json.dumps(json.loads(payload), indent=4)
        elif content_type == 'application/soap+xml':
            # we return a payload that is a dict, which is then converted to
            # XML by the zeep library before being sent along as a SOAP request.
            payload = json.dumps(payload, indent=4)

        return json_response({
            'payload': payload,
            'content_type': content_type,
        })
コード例 #3
0
ファイル: xform_tags.py プロジェクト: dimagi/commcare-hq
def render_form_xml(form):
    xml = form.get_xml()
    if isinstance(xml, six.text_type):
        xml = xml.encode('utf-8', errors='replace')
    formatted_xml = indent_xml(xml) if xml else ''
    return format_html('<pre class="prettyprint linenums"><code class="no-border language-xml">{}</code></pre>',
                       formatted_xml)
コード例 #4
0
def render_form_xml(form):
    xml = form.get_xml()
    if isinstance(xml, unicode):
        xml.encode('utf-8', errors='replace')
    formatted_xml = indent_xml(xml) if xml else ''
    return '<pre class="fancy-code prettyprint linenums"><code class="no-border language-xml">%s</code></pre>' \
           % escape(formatted_xml)
コード例 #5
0
ファイル: views.py プロジェクト: alemat/commcare-hq
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)
    })
コード例 #6
0
ファイル: xform_tags.py プロジェクト: bderenzi/commcare-hq
def render_form_xml(form):
    xml = form.get_xml()
    if isinstance(xml, six.text_type):
        xml = xml.encode('utf-8', errors='replace')
    formatted_xml = indent_xml(xml) if xml else ''
    return format_html('<pre class="prettyprint linenums"><code class="no-border language-xml">{}</code></pre>',
                       formatted_xml)
コード例 #7
0
ファイル: views.py プロジェクト: ansarbek/commcare-hq
    def get(self, request, domain):
        record = RepeatRecord.get(request.GET.get('record_id'))
        content_type = record.repeater.get_payload_generator(
            record.repeater.format_or_default_format()
        ).content_type
        try:
            payload = record.get_payload()
        except XFormNotFound:
            return json_response({
                'error': u'Odd, could not find payload for: {}'.format(record.payload_id)
            }, status_code=404)

        if content_type == 'text/xml':
            payload = indent_xml(payload)

        return json_response({
            'payload': payload,
            'content_type': content_type,
        })
コード例 #8
0
    def get(self, request, domain):
        record_id = request.GET.get('record_id')
        record = self.get_record_or_404(domain, record_id)
        content_type = record.repeater.generator.content_type
        try:
            payload = record.get_payload()
        except XFormNotFound:
            return JsonResponse({
                'error': 'Odd, could not find payload for: {}'.format(record.payload_id)
            }, status=404)

        if content_type == 'text/xml':
            payload = indent_xml(payload)
        elif content_type == 'application/json':
            payload = pformat_json(payload)

        return JsonResponse({
            'payload': payload,
            'content_type': content_type,
        })
コード例 #9
0
ファイル: repeat_records.py プロジェクト: kkrampa/commcare-hq
    def get(self, request, domain):
        record_id = request.GET.get('record_id')
        record = self.get_record_or_404(request, domain, record_id)
        content_type = record.repeater.generator.content_type
        try:
            payload = record.get_payload()
        except XFormNotFound:
            return json_response({
                'error': 'Odd, could not find payload for: {}'.format(record.payload_id)
            }, status_code=404)

        if content_type == 'text/xml':
            payload = indent_xml(payload)
        elif content_type == 'application/json':
            payload = pformat_json(payload)

        return json_response({
            'payload': payload,
            'content_type': content_type,
        })
コード例 #10
0
    def get(self, request, domain):
        record = RepeatRecord.get(request.GET.get('record_id'))
        content_type = record.repeater.get_payload_generator(
            record.repeater.format_or_default_format()
        ).content_type
        try:
            payload = record.get_payload()
        except XFormNotFound:
            return json_response({
                'error': u'Odd, could not find payload for: {}'.format(record.payload_id)
            }, status_code=404)

        if content_type == 'text/xml':
            payload = indent_xml(payload)
        elif content_type == 'application/json':
            payload = json.dumps(json.loads(payload), indent=4)

        return json_response({
            'payload': payload,
            'content_type': content_type,
        })
コード例 #11
0
    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)
    })


class HttpResponseConflict(HttpResponse):
    status_code = 409


class EditCloudcareUserPermissionsView(BaseUserSettingsView):
    template_name = 'cloudcare/config.html'
    urlname = 'cloudcare_app_settings'

    @property
    def page_title(self):
        if toggles.USE_FORMPLAYER_FRONTEND.enabled(self.domain):
            return _("Web Apps Permissions")
コード例 #12
0
    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)
    })


class HttpResponseConflict(HttpResponse):
    status_code = 409


class EditCloudcareUserPermissionsView(BaseUserSettingsView):
    template_name = 'cloudcare/config.html'
    urlname = 'cloudcare_app_settings'

    @property
    def page_title(self):
        if toggles.USE_FORMPLAYER_FRONTEND.enabled(self.domain):
            return _("Web Apps Permissions")