Skip to content

Commit

Permalink
fixes for nb3;
Browse files Browse the repository at this point in the history
  • Loading branch information
k01ek committed Oct 13, 2021
1 parent d4195d4 commit a78512e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
PYTHON_VER?=3.7
NETBOX_VER?=v2.11.6

NETBOX_VER?=v3.0.7

NAME=netbox-qrcode

Expand Down
14 changes: 11 additions & 3 deletions netbox_qrcode/template_content.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from packaging import version

from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist

from extras.plugins import PluginTemplateExtension

from .utilities import get_img_b64, get_qr, get_qr_text, get_concat
Expand Down Expand Up @@ -54,9 +57,14 @@ def x_page(self):
else:
img = get_img_b64(qr_img)
try:
return self.render(
'netbox_qrcode/qrcode.html', extra_context={'image': img}
)
if version.parse(settings.VERSION).major >= 3:
return self.render(
'netbox_qrcode/qrcode3.html', extra_context={'image': img}
)
else:
return self.render(
'netbox_qrcode/qrcode.html', extra_context={'image': img}
)
except ObjectDoesNotExist:
return ''

Expand Down
20 changes: 20 additions & 0 deletions netbox_qrcode/templates/netbox_qrcode/qrcode3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script type="text/javascript">
function printImg(source) {
var win = window.open('');
win.document.write('<img src="' + source + '" onload="window.print();window.close()" />');
win.focus();
}
</script>
<div class="card">
<h5 class="card-header">
<strong>QR Code</strong>
</h5>
<div class="card-body text-right noprint">
<img src="data:image/png;base64,{{image}}" />
</div>
<div class="card-footer text-end noprint">
<button onclick="printImg('data:image/png;base64,{{image}}')" ; class="btn btn-xs btn-primary">
<span class="mdi mdi-printer" aria-hidden="true"></span> Print
</button>
</div>
</div>

0 comments on commit a78512e

Please sign in to comment.