intranet.apps.printing package

Submodules

intranet.apps.printing.admin module

class intranet.apps.printing.admin.PrintJobAdmin(model, admin_site)[source]

Bases: django.contrib.admin.options.ModelAdmin

static formatted_page_range(obj)[source]
list_display = ('time', 'printer', 'user', 'file', 'num_pages', 'formatted_page_range', 'printed')
list_filter = ('time', 'printer', 'num_pages')
ordering = ('-time',)
raw_id_fields = ('user',)

intranet.apps.printing.forms module

class intranet.apps.printing.forms.PrintJobForm(*args, **kwargs)[source]

Bases: django.forms.models.ModelForm

class Meta[source]

Bases: object

fields = ['file', 'printer', 'page_range', 'duplex', 'fit']
model

alias of intranet.apps.printing.models.PrintJob

declared_fields = {'file': <django.forms.fields.FileField object>, 'page_range': <django.forms.fields.RegexField object>, 'printer': <django.forms.fields.ChoiceField object>}
validate_size()[source]

intranet.apps.printing.models module

class intranet.apps.printing.models.PrintJob(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Represents a submitted print job to Ion printing.

user

The user submitting the job.

Type

User

printer

The printer to run the job on.

Type

str

file

The file that the user submitted.

Type

File

page_range

The page range to print.

Type

str

time

The time the job was submitted.

Type

datetime.datetime

printed

Whether the job was printed.

Type

bool

num_pages

The number of pages in this job. This is calculated after converting the job.

Type

int

duplex

Whether to print duplex.

Type

bool

fit

Whether to fit to page.

Type

bool

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

duplex

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

file

The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:

>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size

Assign a file object on assignment so you can do:

>>> with open('/path/to/hello.world', 'r') as f:
...     instance.file = File(f)
fit

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_time(*, field=<django.db.models.fields.DateTimeField: time>, is_next=True, **kwargs)
get_previous_by_time(*, field=<django.db.models.fields.DateTimeField: time>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

num_pages

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
page_range

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

printed

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

printer

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

time

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

user_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

intranet.apps.printing.tests module

class intranet.apps.printing.tests.PrintingTest(methodName='runTest')[source]

Bases: intranet.test.ion_test.IonTestCase

test_printing_view()[source]

intranet.apps.printing.urls module

intranet.apps.printing.views module

exception intranet.apps.printing.views.InvalidInputPrintingError[source]

Bases: Exception

An error occurred while printing, but it was due to invalid input from the user and is not worthy of a CRITICAL log message.

intranet.apps.printing.views.check_page_range(page_range: str, max_pages: int) → Optional[int][source]

Returns the number of pages included in the range, or None if it is an invalid range.

Parameters
  • page_range – The page range as a string, such as “1-5” or “1,2,3”.

  • max_pages – The number of pages in the submitted document. If the number of pages in the given range exceeds this, it will be considered invalid.

Returns

The number of pages in the range, or None if it is an invalid range.

intranet.apps.printing.views.convert_file(tmpfile_name: str, orig_fname: str) → Optional[str][source]
intranet.apps.printing.views.convert_pdf(tmpfile_name: str, cmdname: str = 'ps2pdf') → Optional[str][source]
intranet.apps.printing.views.convert_soffice(tmpfile_name: str) → Optional[str][source]

Converts a doc or docx to a PDF with soffice.

Parameters

tmpfile_name – The path to the file to print.

Returns

The path to the converted file. If it fails, false.

intranet.apps.printing.views.get_mimetype(tmpfile_name: str) → str[source]
intranet.apps.printing.views.get_numpages(tmpfile_name: str) → int[source]
intranet.apps.printing.views.get_printers() → Dict[str, str][source]

Returns a dictionary mapping name:description for available printers.

This requires that a CUPS client be configured on the server. Otherwise, this returns an empty dictionary.

Returns

description for available printers.

Return type

A dictionary mapping name

intranet.apps.printing.views.print_job(obj: intranet.apps.printing.models.PrintJob, do_print: bool = True)[source]

Module contents