35 lines
939 B
Python
35 lines
939 B
Python
from django.conf import settings
|
|
|
|
import requests
|
|
|
|
|
|
def labelmaker_print(name, qr_text, meta_text=''):
|
|
"""
|
|
Generic labelmaker printing, throws on request failure
|
|
"""
|
|
json_dict = {'name': name,
|
|
'qr_text': qr_text,
|
|
'meta_text': meta_text
|
|
}
|
|
print(f'JSON dict: {json_dict}')
|
|
resp = requests.post(
|
|
f'{settings.LABEL_API}/api/1/print',
|
|
json=json_dict)
|
|
resp.raise_for_status()
|
|
|
|
|
|
def labelmaker_render(name, qr_text, meta_text='', fmt='pdf'):
|
|
"""
|
|
Generic labelmaker rendering, throws on request failure. `fmt`
|
|
must be one of 'pdf', 'png'.
|
|
"""
|
|
json_dict = {'name': name,
|
|
'qr_text': qr_text,
|
|
'meta_text': meta_text
|
|
}
|
|
print(f'JSON dict: {json_dict}')
|
|
resp = requests.get(
|
|
f'{settings.LABEL_API}/api/1/render/{fmt}',
|
|
json=json_dict)
|
|
resp.raise_for_status()
|