diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-02-26 20:14:22 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-24 19:38:57 +0200 |
commit | 5bd178db63db3ff05165fc131960f198b2fbbca3 (patch) | |
tree | c644209eb81804406bfc5f014713dc1f62bc5ad4 /archaeological_operations | |
parent | bb1bb0cf461766997a1496547edbbdf04ade4bd6 (diff) | |
download | Ishtar-5bd178db63db3ff05165fc131960f198b2fbbca3.tar.bz2 Ishtar-5bd178db63db3ff05165fc131960f198b2fbbca3.zip |
QR code: QR code export, display on ODT and PDF
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/models.py | 8 | ||||
-rw-r--r-- | archaeological_operations/tests.py | 36 |
2 files changed, 42 insertions, 2 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index a09798f1f..aa1e2dcb4 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -109,9 +109,11 @@ post_delete.connect(post_save_cache, sender=RecordQualityType) class ArchaeologicalSite(BaseHistorizedItem, QRCodeItem, GeoItem, OwnPerms, ValueGetter, ShortMenuItem): + SLUG = 'site' + APP = "archaeological-operations" + MODEL = "archaeological-site" SHOW_URL = 'show-site' TABLE_COLS = ['reference', 'name', 'towns_label', 'periods', 'remains'] - SLUG = 'site' LONG_SLUG = 'archaeologicalsite' BASE_SEARCH_VECTORS = [ @@ -511,10 +513,12 @@ class OperationManager(models.GeoManager): class Operation(ClosedItem, BaseHistorizedItem, QRCodeItem, GeoItem, OwnPerms,\ ValueGetter, ShortMenuItem, DashboardFormItem, RelationItem): + SLUG = 'operation' + APP = "archaeological-operations" + MODEL = "operation" SHOW_URL = 'show-operation' TABLE_COLS = ['year', 'towns_label', 'common_name', 'operation_type', 'start_date', 'excavation_end_date', 'remains'] - SLUG = 'operation' # search parameters BOOL_FIELDS = ['end_date__isnull', 'virtual_operation', diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 01418141d..14577e119 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -2547,3 +2547,39 @@ class SiteTest(TestCase, OperationInitTest): search = {'search_vector': 'reference="reference*"'} response = c.get(reverse('get-site'), search) self.assertEqual(json.loads(response.content)['recordsTotal'], 1) + + +class GenerateQRCode(OperationInitTest, TestCase): + fixtures = FILE_FIXTURES + + def setUp(self): + self.username, self.password, self.user = create_superuser() + self.operation = self.create_operation(self.user)[0] + + def test_display(self): + if self.operation.qrcode.name: + self.operation.qrcode = None + self.operation.save() + operation = models.Operation.objects.get(pk=self.operation.pk) + self.assertIn(operation.qrcode.name, ["", None]) + c = Client() + url = reverse('qrcode-item', args=[ + 'archaeological-operations', 'operation', operation.pk]) + response = c.get(url) + self.assertEqual(response.status_code, 302) + c.login(username=self.username, password=self.password) + response = c.get(url) + self.assertEqual(response.status_code, 200) + self.assertEqual(response['Content-Type'], "image/png") + operation = models.Operation.objects.get(pk=self.operation.pk) + self.assertIsNotNone(operation.qrcode.name) + + def test_generation(self): + self.assertIsNone(self.operation.qrcode.name) + self.operation.generate_qrcode() + self.assertIsNotNone(self.operation.qrcode.name) + self.assertTrue( + self.operation.qrcode.name.startswith( + "operation/2010/OP2010-1/qrcode" + ) + ) |