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.
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.
- 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.
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 ifformdata
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 indata
. Only used ifformdata
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 bip.utils.forms.Link(href: str, text: str = 'klik')¶
Klasy bazowe:
Renderable
- 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 ifformdata
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 indata
. Only used ifformdata
is not passed.
bip.utils.http module¶
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.
- bip.utils.pagination.paginate(query: Query, page: Optional[int] = None, size: Optional[int] = None) Pagination ¶
Create pagination object using sane defaults.
- Parametry:
- Zwraca:
pagination object for query
- Typ zwracany:
bip.utils.site module¶
- class bip.utils.site.Contact(phone: 'str', email: 'str', name: 'str' = '')¶
Klasy bazowe:
object
- 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:
- property basic_information: List[Tuple]¶
Department basic information.
- Zwraca:
key/value pairs of basic information
- Typ zwracany:
List[Tuple]
- 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
- property basic_information: List[Tuple]¶
Site basic information.
- Zwraca:
key/value pairs of basic information
- Typ zwracany:
List[Tuple]
- departments: List[Department]¶
- class bip.utils.site.StaffMember(role_name: 'str', role_type: 'str', person_name: 'str', photo_url: 'str' = '', phone: 'str' = '', email: 'str' = '')¶
Klasy bazowe:
object
bip.utils.templates module¶
bip.utils.text module¶
- bip.utils.text.slugify(text: str, delim: str = '-') str ¶
Create slug (url-safe ASCII representation) of given string.
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.