Merge pull request #474 from SchrodingersGat/qr-png

Fixes
This commit is contained in:
Oliver 2019-09-06 13:19:19 +10:00 committed by GitHub
commit b3be5ca5a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 9 deletions

View File

@ -189,7 +189,7 @@ class InvenTreeTree(models.Model):
def __str__(self): def __str__(self):
""" String representation of a category is the full path to that category """ """ String representation of a category is the full path to that category """
return self.pathstring return "{path} - {desc}".format(path=self.pathstring, desc=self.description)
@receiver(pre_delete, sender=InvenTreeTree, dispatch_uid='tree_pre_delete_log') @receiver(pre_delete, sender=InvenTreeTree, dispatch_uid='tree_pre_delete_log')

View File

@ -1,3 +1,14 @@
.qr-code {
max-width: 400px;
max-height: 400px;
align-content: center;
}
.qr-container {
width: 100%;
align-content: center;
}
.navbar-brand { .navbar-brand {
float: left; float: left;
} }

View File

@ -78,7 +78,7 @@ class TestQuoteWrap(TestCase):
self.assertEqual(helpers.WrapWithQuotes('hello"'), '"hello"') self.assertEqual(helpers.WrapWithQuotes('hello"'), '"hello"')
class TestMakeBarcoede(TestCase): class TestMakeBarcode(TestCase):
""" Tests for barcode string creation """ """ Tests for barcode string creation """
def test_barcode(self): def test_barcode(self):

View File

@ -67,8 +67,8 @@ class CategoryTest(TestCase):
def test_path_string(self): def test_path_string(self):
""" Test that the category path string works correctly """ """ Test that the category path string works correctly """
self.assertEqual(str(self.resistors), 'Electronics/Resistors') self.assertEqual(str(self.resistors), 'Electronics/Resistors - Resistors')
self.assertEqual(str(self.transceivers), 'Electronics/IC/Transceivers') self.assertEqual(str(self.transceivers.pathstring), 'Electronics/IC/Transceivers')
def test_url(self): def test_url(self):
""" Test that the PartCategory URL works """ """ Test that the PartCategory URL works """
@ -111,11 +111,11 @@ class CategoryTest(TestCase):
def test_default_locations(self): def test_default_locations(self):
""" Test traversal for default locations """ """ Test traversal for default locations """
self.assertEqual(str(self.fasteners.default_location), 'Office/Drawer_1') self.assertEqual(str(self.fasteners.default_location), 'Office/Drawer_1 - In my desk')
# Test that parts in this location return the same default location, too # Test that parts in this location return the same default location, too
for p in self.fasteners.children.all(): for p in self.fasteners.children.all():
self.assert_equal(p.get_default_location(), 'Office/Drawer_1') self.assert_equal(p.get_default_location().pathstring, 'Office/Drawer_1')
# Any part under electronics should default to 'Home' # Any part under electronics should default to 'Home'
R1 = Part.objects.get(name='R_2K2_0805') R1 = Part.objects.get(name='R_2K2_0805')

View File

@ -44,7 +44,7 @@ class PartTest(TestCase):
self.assertEqual(self.R1.get_absolute_url(), '/part/3/') self.assertEqual(self.R1.get_absolute_url(), '/part/3/')
def test_category(self): def test_category(self):
self.assertEqual(str(self.C1.category), 'Electronics/Capacitors') self.assertEqual(str(self.C1.category), 'Electronics/Capacitors - Capacitors')
orphan = Part.objects.get(name='Orphan') orphan = Part.objects.get(name='Orphan')
self.assertIsNone(orphan.category) self.assertIsNone(orphan.category)

View File

@ -167,7 +167,7 @@ class PartQRTest(PartViewTestCase):
data = str(response.content) data = str(response.content)
self.assertIn('Part QR Code', data) self.assertIn('Part QR Code', data)
self.assertIn('<img src=', data) self.assertIn('<img class=', data)
def test_invalid_part(self): def test_invalid_part(self):
response = self.client.get(reverse('part-qr', args=(9999,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest') response = self.client.get(reverse('part-qr', args=(9999,)), HTTP_X_REQUESTED_WITH='XMLHttpRequest')

View File

@ -2,7 +2,9 @@
<div class='container' style='width: 80%;'> <div class='container' style='width: 80%;'>
{% if qr_data %} {% if qr_data %}
<img src="{% qr_url_from_text qr_data size='m' error_correction='q' %}" alt="QR Code"> <div class='qr-container'>
<img class='qr-code' src="{% qr_url_from_text qr_data size='m' image_format='png' error_correction='q' %}" alt="QR Code">
</div>
{% else %} {% else %}
<b>Error:</b><br> <b>Error:</b><br>
{{ error_msg }} {{ error_msg }}