def qrcode(request, username, id_string): try: formhub_url = "http://%s/" % request.META['HTTP_HOST'] except: formhub_url = "http://formhub.org/" formhub_url = formhub_url + username if settings.TESTING_MODE: formhub_url = "https://{}/{}".format(settings.TEST_HTTP_HOST, settings.TEST_USERNAME) results = _(u"Unexpected Error occured: No QRCODE generated") status = 200 try: url = enketo_url(formhub_url, id_string) except Exception as 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 test_generate_qrcode(self): self.assertEqual(generate_qrcode(url), qrcode.strip())
def test_generate_qrcode(self): url = "https://hmh2a.enketo.formhub.org" self.assertTrue( generate_qrcode(url).find("data:image/png;base64,") > -1 )
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
def test_generate_qrcode(self): path = os.path.join(os.path.dirname(__file__), "fixtures", "qrcode.txt") with open(path) as f: qrcode = f.read() self.assertEqual(generate_qrcode(url), qrcode.strip())