lino.utils.addressable

Used by lino_xl.lib.appypod.mixins.PrintLabelsAction and lino_xl.lib.contacts.

$ python setup.py test -s tests.UtilsTests.test_addressable

(This module's source code is available here.)

Classes

Addressable

General mixin (not only for Django models) to encapsulate the generating of "traditional" ("snail") mail addresses.

TestAddress(*lines)

Used only for testing.

class lino.utils.addressable.Addressable

Bases: object

General mixin (not only for Django models) to encapsulate the generating of "traditional" ("snail") mail addresses.

It differentiates between the "person" and the "location" part of an address. For example:

Mr. Luc Saffre     | person
Rumma & Ko       | person
Uus 1              | location
Vana-Vigala küla   | location
Vigala vald        | location
Estonia            | location

Usable subclasses must implement at least address_person_lines() and address_location_lines().

address

A property which calls get_address().

address_html

A property which calls get_address_html().

address_person_lines()

Expected to yield one or more unicode strings, one for each line of the person part.

address_location_lines()

Expected to yield one or more unicode strings, one for each line of the location part.

get_address_lines()

Yields a series of strings, one for each line of the address.

get_address(linesep='\n')

The plain text full postal address (person and location). Lines are separated by linesep which defaults to a newline.

property address

The plain text full postal address (person and location). Lines are separated by linesep which defaults to a newline.

get_address_html(*args, **kwargs)

Returns the full postal address a a string containing html markup of style:

<p>line1<br/>line2...</p>

This returns always exactly one paragraph, even if the address is empty (in which case the paragraph is empty):

>>> print(TestAddress().get_address_html())
<p/>

Optional attributes for the enclosing <p> tag can be specified as keyword arguments. Example:

>>> addr = TestAddress('line1', 'line2')
>>> print(addr.get_address_html(**{'class':"Recipient"}))
<p class="Recipient">line1<br/>line2</p>

If min_height is specified, makes sure that the string contains at least that many lines. Adds as many empty lines (<br/>) as needed. This is useful in a template which wants to get a given height for every address.

>>> print(addr.get_address_html(min_height=5))
<p>line1<br/>line2<br/><br/><br/></p>

Any arguments are forwarded to lines2p which is used to pack the address lines into a paragraph (see there for more examples).

property address_html

Returns the full postal address a a string containing html markup of style:

<p>line1<br/>line2...</p>

This returns always exactly one paragraph, even if the address is empty (in which case the paragraph is empty):

>>> print(TestAddress().get_address_html())
<p/>

Optional attributes for the enclosing <p> tag can be specified as keyword arguments. Example:

>>> addr = TestAddress('line1', 'line2')
>>> print(addr.get_address_html(**{'class':"Recipient"}))
<p class="Recipient">line1<br/>line2</p>

If min_height is specified, makes sure that the string contains at least that many lines. Adds as many empty lines (<br/>) as needed. This is useful in a template which wants to get a given height for every address.

>>> print(addr.get_address_html(min_height=5))
<p>line1<br/>line2<br/><br/><br/></p>

Any arguments are forwarded to lines2p which is used to pack the address lines into a paragraph (see there for more examples).

has_address()
>>> TestAddress('line1', 'line2').has_address()
True
>>> TestAddress().has_address()
False
class lino.utils.addressable.TestAddress(*lines)

Bases: lino.utils.addressable.Addressable

Used only for testing.