Пример #1
0
def post_save_urlqrcode(sender, instance, **kwargs):
    """
	根据模型创建QRCode
	"""
    #logger.info(u"%spost_save signal arrived..." % (instance))

    if instance._QRCODE:
        instance._QRCODE = False
        if instance.qr_image:
            instance.qr_image.delete()
        qr = qrcode.QRCode(4, qrcode.ERROR_CORRECT_L)
        qr.add_data(instance.url)
        #print 'data added..'
        qr.make()
        #print 'image made..'
        image = qr.make_image()

        #print 'image madelll'

        #Save image to string buffer
        image_buffer = StringIO()
        image.save(image_buffer)
        image_buffer.seek(0)

        #Here we use django file storage system to save the image.
        file_name = 'UrlQR_%s.jpg' % instance.id
        file_object = File(image_buffer, file_name)
        content_file = ContentFile(file_object.read())
        instance.qr_image.save(file_name, content_file, save=True)
Пример #2
0
 def test_fit(self):
     qr = qrcode.QRCode()
     qr.add_data('a')
     qr.make()
     self.assertEqual(qr.version, 1)
     qr.add_data('bcdefghijklmno')
     qr.make()
     self.assertEqual(qr.version, 2)
Пример #3
0
 def test_render_svg(self):
     qr = qrcode.QRCode()
     qr.add_data(UNICODE_TEXT)
     qr.make_image(image_factory=svg.SvgImage)
Пример #4
0
 def test_mode_8bit(self):
     qr = qrcode.QRCode()
     qr.add_data(u'abcABC' + UNICODE_TEXT)
     qr.make()
     self.assertEqual(qr.version, 1)
     self.assertEqual(qr.data_list[0].mode, MODE_8BIT_BYTE)
Пример #5
0
 def test_mode_alpha(self):
     qr = qrcode.QRCode()
     qr.add_data('ABCDEFGHIJ1234567890')
     qr.make()
     self.assertEqual(qr.version, 1)
     self.assertEqual(qr.data_list[0].mode, MODE_ALPHA_NUM)
Пример #6
0
 def test_mode_number(self):
     qr = qrcode.QRCode()
     qr.add_data('1234567890123456789012345678901234')
     qr.make()
     self.assertEqual(qr.version, 1)
     self.assertEqual(qr.data_list[0].mode, MODE_NUMBER)
Пример #7
0
 def test_overflow(self):
     qr = qrcode.QRCode(version=1)
     qr.add_data('abcdefghijklmno')
     self.assertRaises(DataOverflowError, qr.make, fit=False)
Пример #8
0
 def test_basic(self):
     qr = qrcode.QRCode(version=1)
     qr.add_data('a')
     qr.make(fit=False)