fpiweb.fpiweb_views package

Submodules

fpiweb.fpiweb_views.PrintLabelView module

PrintLabelView.py - manage the view to print QR codes on labels or paper.

class fpiweb.fpiweb_views.PrintLabelView.LabelPosition(page_offset: dataclasses.InitVar[Point], lower_left_offset: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0), lower_right_offset: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0), upper_left_offset: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0), upper_right_offset: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0), offset_on_page: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0), image_start: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0), title_start: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0))[source]

Bases: object

Container for measurements for one label.

All measurements are in points. x denotes horizontal measurement y denotes vertical origin is in lower left corner label is assumed to be 2 in x 2 in ( 144 pt x 144 pt)

image_start: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0)
lower_left_offset: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0)
lower_right_offset: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0)
offset_on_page: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0)
page_offset: dataclasses.InitVar[Point]
title_start: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0)
upper_left_offset: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0)
upper_right_offset: fpiweb.fpiweb_views.PrintLabelView.Point = Point(x=0, y=0)
class fpiweb.fpiweb_views.PrintLabelView.Point(x: int, y: int)[source]

Bases: object

Horizontal (x) and vertical (y) coordinate.

x: int
y: int
class fpiweb.fpiweb_views.PrintLabelView.PrintLabelForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)[source]

Bases: django.forms.forms.Form

Form to request number of labels and starting number.

base_fields = {'number_to_print': <django.forms.fields.IntegerField object>, 'starting_number': <django.forms.fields.IntegerField object>}
declared_fields = {'number_to_print': <django.forms.fields.IntegerField object>, 'starting_number': <django.forms.fields.IntegerField object>}
property media

Return all media required to render the widgets on this form.

number_to_print: int
starting_number: int
class fpiweb.fpiweb_views.PrintLabelView.PrintLabelView(**kwargs)[source]

Bases: django.contrib.auth.mixins.PermissionRequiredMixin, django.views.generic.base.View

Manage the request for starting number and count of QR code to print.

form_class

alias of fpiweb.fpiweb_views.PrintLabelView.PrintLabelForm

get(request, *args, **kwargs)[source]

Prepare to display request for starting box number and count.

Parameters
  • request

  • args

  • kwargs

Returns

static get_base_url(meta) → str[source]

Determine the URL prefix to add to each QR code for a box.

Modify this code as needed.

Parameters

meta

Returns

permission_required = ('fpiweb.print_labels_box',)
post(request, *args, **kwargs)[source]

Validate the info returned from the user and generate the QR codes.

Parameters
  • request

  • args

  • kwargs

Returns

success_url = '/fpiweb/index/'
template_name = 'fpiweb/print_labels.html'
class fpiweb.fpiweb_views.PrintLabelView.QRCodePrinter(url_prefix: str)[source]

Bases: object

Write the pdf of QR codes into the file or byte buffer provided.

compute_box_dimensions()[source]

Compute the dimensions and bounding boxes for each label on the page.

Called from __init__

Returns

draw_bounding_box(label_pos: int)[source]

Draw a bounding box around the specified label.

Parameters

label_pos – position in the labels locations list.

Returns

fill_pdf_pages(starting_number: int, count: int)[source]

Fill one or more pages with labels.

draw lines around the boxes that will be filled with labels # self.draw_boxes_on_page() # self.pdf.setFillColorRGB(1, 0, 1) # self.pdf.rect(2*inch, 2*inch, 2*inch, 2*inch, fill=1)

Returns

finalize_pdf_file()[source]

All pages have been generated so flush all buffers and close.

Returns

finish_page()[source]

Finish off the previous page before starting a new one.

generate_label_pdf()[source]

Generate the pdf file with the requested labels in it.

Returns

static get_next_box_number(start, count) -> (<class 'str'>, <class 'int'>)[source]

Search for the next box number to go on a label.

Returns

get_next_box_url(start_number: int, count: int) -> (<class 'str'>, <class 'str'>)[source]

Build the URL for the next box.

Returns

get_next_qr_img(start_number: int, count: int) -> (<class 'str'>, <class 'str'>)[source]

Build the QR image for the next box label.

Returns

a QR code image file name and the prefixed box number

initialize_pdf_file(buffer: _io.BytesIO)[source]

Prepare to scribble on a new pdf file.

Parameters

buffer – May be a string with a filename or a BytesIO or other File-like object

place_label(file_name: str, label_name: str, pos: int)[source]

Place the label in the appropriate location on the page.

Parameters
  • file_name

  • label_name

  • pos

Returns

print(starting_number: int, count: int, buffer)[source]

Starting point once view retrieved the requested info.

Parameters
  • starting_number – starting box number without the BOX prefix

  • count – number of labels desired

  • buffer – byte buffer to write pdf bytes into

Returns

fpiweb.fpiweb_views.PrintLabelView.logger = <Logger fpiweb (INFO)>

Assuming: - letter size paper

  • portrait orientation

  • 1/2 inch outer margin on all sides

  • all measurements in points (1 pt = 1/72 in)

  • 3 labels across

  • 4 labels down

  • each label has 1/4 in margin on all sides

  • 0, 0 of axis is in lower left corner