bip.utils package

Submodules

bip.utils.app module

class bip.utils.app.Application(import_name: str, static_url_path: Optional[str] = None, static_folder: Optional[Union[str, PathLike]] = 'static', static_host: Optional[str] = None, host_matching: bool = False, subdomain_matching: bool = False, template_folder: Optional[str] = 'templates', instance_path: Optional[str] = None, instance_relative_config: bool = False, root_path: Optional[str] = None)

Klasy bazowe: Flask

Overriden application class.

property jinja_options: dict

Overriden options for Jinja templates.

Zwraca:

template options

Typ zwracany:

dict

bip.utils.cli module

class bip.utils.cli.ColAlign

Klasy bazowe: object

Column alignment enum.

center = 'c'
left = 'l'
right = 'r'
class bip.utils.cli.ColDataType

Klasy bazowe: object

Column data type enum.

auto = 'a'
exp = 'e'
float = 'f'
int = 'i'
text = 't'
class bip.utils.cli.ColSpec(align, dtype, title)

Klasy bazowe: tuple

Create new instance of ColSpec(align, dtype, title)

property align

Alias for field number 0

property dtype

Alias for field number 1

property title

Alias for field number 2

bip.utils.cli.create_table(is_testing: bool, cols: List[ColSpec]) Texttable

Create table for terminal display.

The table has unlimited size if application is in testing state, otherwise term size.

Parametry:
  • is_testing (bool) – flag whether application is in testing state

  • cols (List[ColSpec]) – list of columns for the table

Zwraca:

table object

Typ zwracany:

Texttable

bip.utils.cli.login_user(username: str, admin: bool = True) User

Verify user login.

Parametry:
  • username (str) – user account name

  • admin (bool, optional) – require administrative privileges, defaults to True

Wyrzuca:

click.ClickException – if credentials are not valid

Zwraca:

logged in user object

Typ zwracany:

User

bip.utils.cli.print_table(table: Texttable)

Print table to terminal or to pager depending on table size.

Parametry:

table (Texttable) – table to be printed

bip.utils.files module

class bip.utils.files.FileData(filename, file_type, file_size)

Klasy bazowe: tuple

Create new instance of FileData(filename, file_type, file_size)

property file_size

Alias for field number 2

property file_type

Alias for field number 1

property filename

Alias for field number 0

bip.utils.files.calc_sha256(filename: str) str

Calculate SHA256 checksum without reading whole file into memory.

Parametry:

filename (str) – path to file

Zwraca:

SHA256 checksum of file content

Typ zwracany:

str

bip.utils.files.process_incoming_file(path: str, target_dir: str) FileData

Processing of incoming page attachment file.

Parametry:
  • path (str) – path to file in local filesystem

  • target_dir (str) – destination where the file will be stored

Zwraca:

file object related data for attachment

Typ zwracany:

FileData

bip.utils.forms module

class bip.utils.forms.BaseForm(*args, **kwargs)

Klasy bazowe: FlaskForm

Parametry:
  • formdata – Input data coming from the client, usually request.form or equivalent. Should provide a „multi dict” interface to get a list of values for a given key, such as what Werkzeug, Django, and WebOb provide.

  • obj – Take existing data from attributes on this object matching form field attributes. Only used if formdata is not passed.

  • prefix – If provided, all fields will have their name prefixed with the value. This is for distinguishing multiple forms on a single page. This only affects the HTML name for matching input data, not the Python name for matching existing data.

  • data – Take existing data from keys in this dict matching form field attributes. obj takes precedence if it also has a matching attribute. Only used if formdata is not passed.

  • meta – A dict of attributes to override on this form’s meta instance.

  • extra_filters – A dict mapping field attribute names to lists of extra filter functions to run. Extra filters run after filters passed when creating the field. If the form has filter_<fieldname>, it is the last extra filter.

  • kwargs – Merged with data to allow passing existing data as parameters. Overwrites any duplicate keys in data. Only used if formdata is not passed.

buttons = [Button(type_='submit', class_='primary', icon='check', icon_type='fas', text='zapisz'), Link(href='javascript:history.back()', text='powrót')]
class bip.utils.forms.Button(type_: str = 'submit', class_: str = 'primary', icon: str = 'check', icon_type: str = 'fas', text: str = 'ok')

Klasy bazowe: Renderable

class_: str = 'primary'
icon: str = 'check'
icon_type: str = 'fas'
template: ClassVar[str] = '<button type="{{ obj.type_ }}" class="btn btn-{{ obj.class_ }}"><i class="{{ obj.icon_type }} fa-{{ obj.icon }}"></i>&nbsp;{{ obj.text }}</button>'
text: str = 'ok'
type_: str = 'submit'
class bip.utils.forms.EmailValidator(message=None)

Klasy bazowe: object

Klasy bazowe: Renderable

href: str
template: ClassVar[str] = '<a href="{{ obj.href }}">{{ obj.text }}</a>'
text: str = 'klik'
class bip.utils.forms.ObjectForm(*args, **kwargs)

Klasy bazowe: BaseForm

Parametry:
  • formdata – Input data coming from the client, usually request.form or equivalent. Should provide a „multi dict” interface to get a list of values for a given key, such as what Werkzeug, Django, and WebOb provide.

  • obj – Take existing data from attributes on this object matching form field attributes. Only used if formdata is not passed.

  • prefix – If provided, all fields will have their name prefixed with the value. This is for distinguishing multiple forms on a single page. This only affects the HTML name for matching input data, not the Python name for matching existing data.

  • data – Take existing data from keys in this dict matching form field attributes. obj takes precedence if it also has a matching attribute. Only used if formdata is not passed.

  • meta – A dict of attributes to override on this form’s meta instance.

  • extra_filters – A dict mapping field attribute names to lists of extra filter functions to run. Extra filters run after filters passed when creating the field. If the form has filter_<fieldname>, it is the last extra filter.

  • kwargs – Merged with data to allow passing existing data as parameters. Overwrites any duplicate keys in data. Only used if formdata is not passed.

save(obj: Model, save: bool = True) Model
class bip.utils.forms.Renderable

Klasy bazowe: object

An object that can be rendered.

render() Markup

Render template into Markup object.

Zwraca:

rendering result as Markup

Typ zwracany:

Markup

bip.utils.http module

bip.utils.http.or_404(obj: Optional[Any]) Any

Abort with 404 if passed object is None.

Parametry:

obj (Optional[Any]) – something to be checked for None

Zwraca:

passed object if it’s not None

Typ zwracany:

Any

bip.utils.menu module

class bip.utils.menu.MenuItem(title, url)

Klasy bazowe: tuple

Create new instance of MenuItem(title, url)

property title

Alias for field number 0

property url

Alias for field number 1

bip.utils.pagination module

class bip.utils.pagination.Pagination(page, per_page, total, items)

Klasy bazowe: object

Copied almost verbatim from Flask-SQLAlchemy.

Minor changes made to work with Peewee query object. Removed unused code.

Copyright 2010 Pallets

iter_pages(left_edge=2, left_current=2, right_current=5, right_edge=2)

Iterate over pages, yielding page nums.

property has_next

True if a next page exists.

property has_prev

True if a previous page exists.

property pages

The total number of pages.

bip.utils.pagination.get_page(arg_name: str = 'p') int

Get page number for current request.

Page number is searched in request args.

Parametry:

arg_name (str, optional) – name of URL argument, defaults to «p»

Zwraca:

page number or 1 if not found

Typ zwracany:

int

bip.utils.pagination.paginate(query: Query, page: Optional[int] = None, size: Optional[int] = None) Pagination

Create pagination object using sane defaults.

Parametry:
  • query (peewee.Query) – query to paginate results

  • page (Optional[int], optional) – page number, will be fetched from request if omitted, defaults to None

  • size (Optional[int], optional) – page size, defaults to None

Zwraca:

pagination object for query

Typ zwracany:

Pagination

bip.utils.pagination.url_for_other_page(page: Union[int, str]) str

Generate (internal) URL to another page of the same document.

This works only within the context of particular request.

Parametry:

page (Union[int, str]) – desired page

Zwraca:

URL to another page of current document

Typ zwracany:

str

bip.utils.site module

class bip.utils.site.Address(street: 'str', zip_code: 'str', town: 'str')

Klasy bazowe: object

property display_value: str

Formatted address line.

Zwraca:

address line

Typ zwracany:

str

street: str
town: str
zip_code: str
class bip.utils.site.Contact(phone: 'str', email: 'str', name: 'str' = '')

Klasy bazowe: object

property basic_information: List[Tuple]

Contact basic information.

Zwraca:

key/value pairs of basic information

Typ zwracany:

List[Tuple]

email: str
name: str = ''
phone: str
class bip.utils.site.Department(name: 'str', staff: 'List[StaffMember]', phone: 'str' = '', email: 'str' = '', domain: 'str' = '', location: 'str' = '')

Klasy bazowe: object

classmethod from_dict(d: dict) Department

Initialise Department instance from dictionary data.

Parametry:

d (dict) – input data

Zwraca:

Department instance

Typ zwracany:

Department

property basic_information: List[Tuple]

Department basic information.

Zwraca:

key/value pairs of basic information

Typ zwracany:

List[Tuple]

domain: str = ''
email: str = ''
location: str = ''
name: str
phone: str = ''
staff: List[StaffMember]
class bip.utils.site.Site(name: 'str', address: 'Address', contacts: 'List[Contact]', departments: 'List[Department]', bip_url: 'str', nip: 'str', regon: 'str', short_name: 'str' = '', krs: 'str' = '')

Klasy bazowe: object

classmethod from_dict(d: dict) Site

Load site data from dictionary.

Parametry:

d (dict) – dictionary of site data

Zwraca:

Site instance

Typ zwracany:

Site

classmethod from_json(s: str) Site

Load site data from JSON string.

Parametry:

s (str) – input string

Zwraca:

Site instance

Typ zwracany:

Site

address: Address
property basic_information: List[Tuple]

Site basic information.

Zwraca:

key/value pairs of basic information

Typ zwracany:

List[Tuple]

bip_url: str
contacts: List[Contact]
departments: List[Department]
krs: str = ''
name: str
nip: str
regon: str
short_name: str = ''
class bip.utils.site.StaffMember(role_name: 'str', role_type: 'str', person_name: 'str', photo_url: 'str' = '', phone: 'str' = '', email: 'str' = '')

Klasy bazowe: object

property basic_information: List[Tuple]

Person basic information.

Zwraca:

key/value pairs of basic information

Typ zwracany:

List[Tuple]

email: str = ''
person_name: str
phone: str = ''
photo_url: str = ''
role_name: str
role_type: str
bip.utils.site.test_site() Site

Generate site data object for tests.

Zwraca:

site data object

Typ zwracany:

Site

bip.utils.templates module

bip.utils.templates.extra_context(**kwargs) dict

Things to be added to Jinja context.

Zwraca:

extra context

Typ zwracany:

dict

bip.utils.templates.extra_filters(**kwargs) dict

Additional filters to be registered in Jinja environment.

Zwraca:

extra filters

Typ zwracany:

dict

bip.utils.text module

bip.utils.text.pluralize(value: int, plural_forms: Sequence[str]) str

Polish pluralization.

Parametry:
  • value (int) – item count

  • plural_forms (Sequence[str]) – sequence of 3 pluralization forms (singular and 2 plurals)

Zwraca:

pluralized item literal

Typ zwracany:

str

bip.utils.text.slugify(text: str, delim: str = '-') str

Create slug (url-safe ASCII representation) of given string.

Parametry:
  • text (str) – text to slugify

  • delim (str, optional) – delimiter, defaults to «-»

Zwraca:

slugified text

Typ zwracany:

str

bip.utils.text.truncate_string(s: str, length: int) str

Truncate string at word boundary.

Parametry:
  • s (str) – string to be truncated

  • length (int) – max length of result string

Zwraca:

truncated text

Typ zwracany:

str

bip.utils.text.yesno(value: bool, capitalize: bool = True) str

Return „yes” or „no” in Polish.

Returned string is capitalized by default.

Parametry:
  • value (bool) – value to be represented

  • capitalize (bool, optional) – whether to capitalize output string, defaults to True

Zwraca:

textual representation of Boolean value

Typ zwracany:

str

bip.utils.views module

bip.utils.views.is_redirect_safe(target: Optional[str]) bool

Check if redirect is safe.

This is determined by checking if it’s is using HTTP protocol and is pointing to the same site.

Parametry:

target (str) – redirect target url

Zwraca:

flag signalling whether redirect is safe

Typ zwracany:

bool

bip.utils.views.next_redirect(fallback_endpoint: str, *args, **kwargs) str

Find redirect url.

The order of search is request params, session and finally url for fallback endpoint is returned if none found. Args and kwargs are passed intact to endpoint.

Parametry:

fallback_endpoint (str) – full endpoint specification

Zwraca:

HTTP path to redirect to

Typ zwracany:

str