def render_label(request, c, metrics, da, badge_img, debug):
    """Render a single label"""
    badge = da.badge

    badge_image_width = (1.0 + (1.0 / 64.0)) * inch
    badge_image_height = (1.0 + (1.0 / 64.0)) * inch

    qr_left = badge_image_width - metrics['qr_overlap']
    qr_bottom = badge_image_height - metrics['qr_overlap']
    qr_width = metrics['width'] - qr_left
    qr_height = metrics['height'] - qr_bottom

    if False and debug:
        # Draw some layout lines on debug.
        c.setLineWidth(0.3)
        c.rect(0, 0, metrics['width'], metrics['height'])
        c.rect(qr_left, qr_bottom, qr_width, qr_height)
        c.rect(0, 0, badge_image_width, badge_image_height)

    fit_text(c, da.badge.title,
             0.0, badge_image_height,
             badge_image_width, qr_height)

    c.saveState()
    c.rotate(-90)

    code_height = qr_height * (0.45)
    claim_height = qr_height - code_height

    c.setFont("Courier", code_height)
    c.drawCentredString(0 - (badge_image_width / 2.0),
                        metrics['height'] - code_height,
                        da.claim_code)

    text = """
        <font name="Helvetica">Claim at</font> <font name="Courier">%s</font>
    """ % (settings.SITE_TITLE)
    fit_text(c, text,
             0 - badge_image_height, badge_image_width,
             badge_image_width, claim_height)

    c.restoreState()

    # Attempt to build a QR code image for the claim URL
    claim_url = request.build_absolute_uri(da.get_claim_url())
    qr_img = None
    try:
        # Try using PyQRNative: http://code.google.com/p/pyqrnative/
        # badg.us should have this in vendor-local
        from PyQRNative import QRCode, QRErrorCorrectLevel
        # TODO: Good-enough settings?
        if len(claim_url) < 20:
            qr = QRCode(3, QRErrorCorrectLevel.L)
        elif len(claim_url) < 50:
            qr = QRCode(4, QRErrorCorrectLevel.L)
        else:
            qr = QRCode(10, QRErrorCorrectLevel.L)
        qr.addData(claim_url)
        qr.make()
        qr_img = ImageReader(qr.makeImage())

    except ImportError:
        try:
            # Hmm, if we don't have PyQRNative, then try abusing this web
            # service. Should be fine for low volumes.
            qr_url = ("http://api.qrserver.com/v1/create-qr-code/?%s" %
                urllib.urlencode({'size': '%sx%s' % (500, 500),
                                  'data': claim_url}))

            qr_img = ImageReader(StringIO(urllib2.urlopen(qr_url).read()))

        except Exception:
            # Ignore issues in drawing the QR code - maybe show an error?
            pass

    if qr_img:
        c.drawImage(qr_img, qr_left, qr_bottom, qr_width, qr_height)

    c.drawImage(badge_img,
                0.0 * inch, 0.0 * inch,
                badge_image_width, badge_image_height)
dataset/ETHPy150Open mozilla/django-badger/badger/printing.py/render_label/original