bip.utils package

Submodules

bip.utils.app module

class bip.utils.app.Application(import_name, static_url_path=None, static_folder='static', static_host=None, host_matching=False, subdomain_matching=False, template_folder='templates', instance_path=None, instance_relative_config=False, root_path=None)

Klasy bazowe: flask.app.Flask

Overriden application class.

property jinja_options

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[bip.utils.cli.ColSpec]) → texttable.Texttable

Create table for term 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)bip.models.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.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)bip.utils.files.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: flask_wtf.form.FlaskForm

Parametry
  • formdata – Used to pass data coming from the enduser, usually request.POST or equivalent. formdata should be some sort of request-data wrapper which can get multiple parameters from the form input, and values are unicode strings, e.g. a Werkzeug/Django/WebOb MultiDict

  • obj – If formdata is empty or not provided, this object is checked for attributes matching form field names, which will be used for field values.

  • prefix – If provided, all fields will have their name prefixed with the value.

  • data – Accept a dictionary of data. This is only used if formdata and obj are not present.

  • meta – If provided, this is a dictionary of values to override attributes on this form’s meta instance.

  • **kwargs – If formdata is empty or not provided and obj does not contain an attribute named the same as a field, form will assign the value of a matching keyword argument to the field, if one exists.

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: bip.utils.forms.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: bip.utils.forms.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: bip.utils.forms.BaseForm

Parametry
  • formdata – Used to pass data coming from the enduser, usually request.POST or equivalent. formdata should be some sort of request-data wrapper which can get multiple parameters from the form input, and values are unicode strings, e.g. a Werkzeug/Django/WebOb MultiDict

  • obj – If formdata is empty or not provided, this object is checked for attributes matching form field names, which will be used for field values.

  • prefix – If provided, all fields will have their name prefixed with the value.

  • data – Accept a dictionary of data. This is only used if formdata and obj are not present.

  • meta – If provided, this is a dictionary of values to override attributes on this form’s meta instance.

  • **kwargs – If formdata is empty or not provided and obj does not contain an attribute named the same as a field, form will assign the value of a matching keyword argument to the field, if one exists.

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

Klasy bazowe: object

An object that can be rendered

render()markupsafe.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(query, 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)
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: peewee.Query, page: Optional[int] = None, size: Optional[int] = None)bip.utils.pagination.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
street: str
town: str
zip_code: str
class bip.utils.site.Contact(phone: «str», email: «str», name: «str» = '')

Klasy bazowe: object

property basic_information
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)bip.utils.site.Department
property basic_information
domain: str = ''
email: str = ''
location: str = ''
name: str
phone: str = ''
staff: List[bip.utils.site.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)bip.utils.site.Site
classmethod from_json(s: str)bip.utils.site.Site
address: bip.utils.site.Address
property basic_information
bip_url: str
contacts: List[bip.utils.site.Contact]
departments: List[bip.utils.site.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
email: str = ''
person_name: str
phone: str = ''
photo_url: str = ''
role_name: str
role_type: str
bip.utils.site.test_site()bip.utils.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” as textual representation of Boolean value 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, that 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