예제 #1
0
파일: views.py 프로젝트: larryweya/formhub
def qrcode(request, username, id_string):
    try:
        formhub_url = "http://%s/" % request.META['HTTP_HOST']
    except:
        formhub_url = "http://formhub.org/"
    formhuburl = formhub_url + username
    url = enketo_url(formhuburl, id_string)
    if url:
        image = generate_qrcode(url)
        results = """<img class="qrcode" src="%s" alt="%s" />
                   </br><a href="%s" target="_blank">%s</a>""" % (image, url, url, url)
    else:
        error_msg = _(u"Error Generating QRCODE")
        results = """<div class="alert alert-error">%s</div>""" % error_msg

    return HttpResponse(results, mimetype='text/html')
예제 #2
0
파일: views.py 프로젝트: tremolo/formhub
    except:
        formhub_url = "http://formhub.org/"
    formhub_url = formhub_url + username
    if settings.TESTING_MODE:
        formhub_url = "https://testserver.com/bob"
    results = _(u"Unexpected Error occured: No QRCODE generated")
    status = 200
    try:
        url = enketo_url(formhub_url, id_string)
    except Exception, e:
        error_msg = _(u"Error Generating QRCODE: %s" % e)
        results = """<div class="alert alert-error">%s</div>""" % error_msg
        status = 400
    else:
        if url:
            image = generate_qrcode(url)
            results = """<img class="qrcode" src="%s" alt="%s" />
                    </br><a href="%s" target="_blank">%s</a>""" \
                % (image, url, url, url)
        else:
            status = 400
    return HttpResponse(results, mimetype='text/html', status=status)


def enketo_preview(request, username, id_string):
    xform = get_object_or_404(
        XForm, user__username=username, id_string=id_string)
    owner = xform.user
    if not has_permission(xform, owner, request, xform.shared):
        return HttpResponseForbidden(_(u'Not shared.'))
    enekto_preview_url = \