Welcome to FeretUI’s documentation!

Feretui.

Small web client to build an admin user interface without any link with a framework.

This project is not a nodejs project. The client is generated with static templates. The javascrip library Htmx to improve the capability to manipulate the DOM and to add HTTP verb (DELETE, PUT, PATCH).

The client is not a Framework, and don’t use any web-server, orm, connector Frameworks. The goal is to separate the concept between both.

In a classical project the database, the ORM model’s and the user interface is declared on the same place. They are both the same configuration. But It is a mistake, because that limit the possibility and force to have only entry point by the user interface. The rules as required, readonly, … should be depending only on the user-interface. It is possible to define an interface based on more than one Model, or with another constraints.

To isolate it about the web-server projects, This project add objects to do abstract with web server:

FeretUI include to mecanism of templating:

  • feretui.template.Template : Import template by addons, the template can be modified by another template file. They are compiled by id and language. The compiled template are stored.

  • jinja.

The both are used in the same time, the internal allow the modularity, and jinja allow the loop and setter the variable inside the template

[my/template.tmpl]

<template id="my-template">
  <ul>
    {% for tag in tags %}
    <li>{{ tag }}</li>
    {% endfor %}
  </ul>
</template>

import of the template file

myferet.register_template_file('my/template.tmpl')

render the template

template_str = myferet.render_template(
    session, 'my-template', tags=['foo', 'bar'])

If the template need a static file (js, css, image), it is possible to add this static in existing client

myferet.register_js('my-lib.js', 'path in the filesystem')
myferet.register_css('my-lib.css', 'path in the filesystem')
myferet.register_image('my-picture.png', 'path in the filesystem')

Note

Python os lib give helper to find the path where the module is installed.

Note

An existing entrypoint is called at during the initialisation of the instance. In this entrypoint you may declare any static you need feretui.feretui.FeretUI.register_addons_from_entrypoint().

FeretUI include theme mecanism base on Bulma watch. It is easier to add your new theme file with feretui.feretui.FeretUI.register_theme().

myferet.register_theme('my-theme', 'path in the filesystem')

FeretUI add Action mechanism. The actions are callbacks and take as arguments the request and the argument of the action.

FeretUI allow to add page mecanisme. The page are function and take as arguments the session and the querystring or the body.

@myferet.register_page(
    name='my-page',
    template='''
        <template id="my-page">
            <div>My page</div>
        </template>
    '''
)
def my_page(feretui, session, option):
    return feretui.render_template(session, 'my-page')

In the case of the fully static page.

myferet.register_static_page(
    'my-static-page',
    '''
        <div>...</div>
    '''
)

or

from feretui.pages import static_page

myferet.register_page(name='my-page')(static_page('my-page-id))

To display the page a menu mecanism exist to call the render method of the page.

myferet.register_toolbar_right_menus([
    ToolBarMenu(
        'My static page',
        page='my-static-page',
        description="Go to my static page"
    ),
])

They are two main type of menu:

The helpers to register or get them are:

The client FeretUI add WTForm mecanism. The goal is to display easily formulaire in the pages and validate the entry in the actions.

To link the form with the translation and the bulma renderer you must inherit feretui.form.FeretUIForm.

If you need to register a password you must use the validator feretui.form.Password

The resource is a set of page and form to represent a data and tools to manipulate this data.

The client FeretUI add translation mechanism. This mecanism can be declared with addon’s name attribute. This attribute is used to extract the translation of FeretUI or an additionnal project. The translated object are:

To export the translation, the console script export-feretui-catalog extract all the translation messages in pot file.

from feretui import FeretUI, Session


myferet = FeretUI()
session = Session()

@route('an/url')
def do_something(request):
    frequest = Request(
        session=session,
        method=Request.POST,
        body=request.body.read(),
        headers=dict(request.headers),
    )
    response = myferet.execute_action(frequest, 'action-arg1-arg2')
    return response.body
class feretui.Action(label: str, method: str, icon: str | None = None, description: str | None = None, visible_callback: Callable | None = None)[source]

Action class.

Define an action in actionset in the view meta.

get_url(feretui: FeretUI, session: Session, options: dict) str[source]

Return the hx-post url.

Parameters:
Returns:

The url

Return type:

str

is_visible(session: Session) bool[source]

Return True is the action should be displayed.

Parameters:

session (feretui.session.Session) – The session of the user

Return type:

bool

render(feretui: FeretUI, session: Session, options: dict, resource_code: str, view_code: str) Markup[source]

Return the html of the action.

Parameters:
Returns:

The html

Return type:

Markup

class feretui.Actionset(label: str, actions: list[Action], icon: str | None = None, description: str | None = None)[source]

Actionset class.

The Actionset is a set of action with a label.

This need to group the action in the same place

export_catalog(translation: Translation, po: POFile) None[source]

Export the translations in the catalog.

Parameters:
  • translation (Translation) – The translation instance to add also inside it.

  • po (PoFile) – The catalog instance

is_visible(session: Session) bool[source]

Return True is the action should be displayed.

Parameters:

session (feretui.session.Session) – The session of the user

Return type:

bool

render(feretui: FeretUI, session: Session, options: dict, resource_code: str, view_code: str) Markup[source]

Return the html of the action.

Parameters:
  • feretui (feretui.feretui.FeretUI) – The feretui client instance.

  • session (feretui.session.Session) – The session of the user

  • options (dict) – The querystring

  • resource_code (str) – the code of the resource

  • view_code (str) – the code of the view

Returns:

The html

Return type:

Markup

class feretui.AsideHeaderMenu(label: str, children: list[ToolBarMenu] | None = None, **kwargs: dict[str, str])[source]

Hieracal menu for aside.

menu = AsideHeaderMenu(
    'Label',
    children=[AsideMenu('My label')])
if menu.is_visible(session):
    menu.render(myferet, session)
template_id: str = 'aside-header-menu'

The template id to display in the Menu.render()

class feretui.AsideMenu(label: str, **kwargs: dict[str, str])[source]

Menu class for the aside menu page.

menu = AsideMenu('My label')
if menu.is_visible(session):
    menu.render(myferet, session)
get_href(feretui: FeretUI, querystring: dict[str, str]) str[source]

Return the url to put in href attribute of the a tag.

Parameters:
  • feretui (feretui.feretui.FeretUI) – The feretui client instance.

  • querystring – The querysting to pass at the api

Returns:

The url

Return type:

str

get_url(feretui: FeretUI, querystring: dict[str, str]) str[source]

Return the url to put in hx-get attribute of the a tag.

Parameters:
  • feretui (feretui.feretui.FeretUI) – The feretui client instance.

  • querystring – The querysting to pass at the api

Returns:

The url

Return type:

str

template_id: str = 'aside-menu'

The template id to display in the Menu.render()

class feretui.AsideUrlMenu(label: str, url: str, **kw: dict[str, str])[source]

Menu class to add a link to another web api.

menu = AsideUrlMenu('My label', url="https://bulma.io")
if menu.is_visible(session):
    menu.render(myferet, session)
template_id: str = 'aside-url-menu'

The template id to display in the Menu.render()

class feretui.CResource[source]

CResource class.

MetaViewCreate

alias of DefaultViewCreate

build_view(view_cls_name: str) Resource[source]

Return the view instance in fonction of the MetaView attributes.

Parameters:

view_cls_name (str) – name of the meta attribute

Returns:

An instance of the view

Return type:

feretui.resources.view.View

create(form: FeretUIForm) str[source]

Create an object from the form and return the primary key.

Warning

must be overwriting

Parameters:

form (feretui.form.FeretUIForm) – The instance of Form

Returns:

The primary key

Return type:

str

class feretui.DResource[source]

DResource class.

MetaViewDelete

alias of DefaultViewDelete

build_view(view_cls_name: str) Resource[source]

Return the view instance in fonction of the MetaView attributes.

Parameters:

view_cls_name (str) – name of the meta attribute

Returns:

An instance of the view

Return type:

feretui.resources.view.View

delete(pks: list[str]) None[source]

Delete an object from the pks.

Warning

must be overwriting

Parameters:

pks (list[str]) – The primary keys

class feretui.FeretUI(base_url: str = '/feretui', title: str = 'FeretUI')[source]

Feretui class.

Attributes

  • base_url[str] : The url for this client

  • title[str] : The title of the html head

  • jinja_env[Environment] : The environnement of jinja

  • template[:class: feretui.template.Template]: Templates load

  • statics[dict[str, str]]: The static filepath on server stored by name

  • css_import[list[str]] : List of the urls of the css to load

  • js_import[list[str]] : List of the urls of the script javascript to load

  • images[dict[str, str]] : List of the image and their url

  • themes[dict[str, str]] : List of the theme and their url

  • fonts[dict[str, str]] : List of the font and their url

  • actions[dict[str, Callable]] : List of the action callables

  • pages[dict[str, Callable]] : List of the pages

  • menus[dict[str, feretui.menus.ToolBarMenu]] : the key are left or right the value are instances of the menu.

  • asides[dict[str, feretui.menus.AsideMenu]] : The key is the code for the aside-menu page, the values are the instance of the menu.

  • resources[dict[str, :class:`feretui.resource.Resource]] : The key is the code of the resource and value the class.

The instance provide methodes to use

property css_import: list[tuple[bool, str]]

Return the css imports.

Returns:

The list of css files to import

Return type:

list[tuple[bool, str]]

execute_action(request: Request, action_name: str) Response[source]

Execute a stored action.

Get and execute the action stored in the client. The parameters need for the good working of the action must be passed by the body or the querystring from the request.

request = Request(...)
myferet.execute_action(request, 'my_action')
Parameters:
Returns:

The result of the action

Return type:

feretui.response.Response

export_catalog(output_path: str, version: str, addons: str | None = None) None[source]

Export the catalog at the POT format.

FeretUI.export_catalog(
    'feretui/locale/feretui.pot', addons='feretui')
Parameters:
  • output_path (str) – The path where write the catalog

  • version (str) – The version of the catalog

  • addons (str) – The addons where the message come from

property fonts: dict[str, str]

Return the fonts registry.

Returns:

The dictionary of registered fonts

Return type:

dict[str, str]

get_aside_menus(code: str) list[AsideMenu][source]

Return the aside menus link with the code.

Parameters:

code (str) – The code of the aside

Returns:

The menus to render

Return type:

list[feretui.menus.AsideMenu

get_image_url(name: str) str[source]

Get the url for a picture.

Parameters:

name (str) – The name of the picture

Returns:

The url to get it

Return type:

str

get_page(pagename: str) Callable[[FeretUI, Session, dict], str][source]

Return the page callable.

myferet.get_page('my-page')
Parameters:

pagename (str) – The name of the page

Returns:

the callable

Return type:

Callable[ [FeretUI, feretui.session.Session, dict], str]

get_resource(code: str) Resource[source]

Return the resource instance.

Parameters:

code (feretui.resource.Resource) – The code of the instance

Returns:

The instance of the resource

Return type:

feretui.resource.Resource

Exception:

feretui.exceptions.UnexistingResourceError

get_site_map_menus() None[source]

Return the sitemap menus.

Returns:

The menus to render

Return type:

feretui.menus.SitemapMenu

get_static_file_path(filename: str) str[source]

Get the path in the filesystem for static file name.

Parameters:

name (str) – The name of the static

Returns:

The filesystem path

Return type:

str

get_theme_url(session: Session) str[source]

Return the theme url in function of the session.

Parameters:
Returns:

the url to import stylesheep

Return type:

str

property images: dict[str, str]

Return the images registry.

Returns:

The dictionary of registered images

Return type:

dict[str, str]

property js_import: list[str]

Return the js imports.

Returns:

The list of js files to import

Return type:

list[str]

load_catalog(catalog_path: str, lang: str) None[source]

Load a specific catalog for a language.

::

FeretUI.load_catalog(‘feretui/locale/fr.po’, ‘fr’)

Parameters:
  • catalog_path (str) – Path of the catalog

  • lang (str) – Language code

load_internal_catalog(lang: str) None[source]

Load a specific catalog for a language defined by feretui.

::

FeretUI.load_internal_catalog(‘fr’)

Parameters:

lang (str) – Language code

register_action(function: Callable[[FeretUI, Request], Response]) Callable[[FeretUI, Request], Response][source]

Register an action.

It is a Decorator to register an action need by the client or the final project.

The action is a callable with two params:

@myferet.register_action
def my_action(feretui, request):
    return Response(...)
Parameters:

function (Callable[[FeretUI, feretui.request.Request], feretui.response.Response]) – The action callable to store

Returns:

The stored action callable

Return type:

Callable[[FeretUI, feretui.request.Request], feretui.response.Response]

register_addons_from_entrypoint() None[source]

Get the static from the entrypoints.

The declaration of the entryt point is done in the pyproject.toml of your project

[project.entry-points."feretui.addons"]
feretui = "feretui.feretui:import_feretui_addons"

Here the method call is import_feretui_addons().

register_aside_menus(code: str, menus: list[AsideMenu], addons: str | None = None) None[source]

Register a menu in an aside page.

myferet.register_aside_menus(
    'my-aside', [
        AsideMenu(...),
    ],
)
Parameters:
  • code (str) – The code of the aside

  • menus (list[feretui.menus.AsideMenu]) – The menus to register

  • addons (str) – The addons where the message come from

Exception:

feretui.exceptions.MenuError

register_auth_menus(menus: list[ToolBarButtonMenu], addons: str | None = None) None[source]

Register the auth menus.

myferet.register_auth_menus([
    ToolBarButtonMenu(...),
])
Parameters:
Exception:

feretui.exceptions.MenuError

register_css(name: str, filepath: str, compress: bool = True) None[source]

Register a stylesheet file to import in the client.

Parameters:
  • name (str) – name of the file see in the html url

  • filepath (str) – Path in server file system

  • compress (bool) – if True compress the csv

register_font(name: str, filepath: str) None[source]

Register a theme file to use it in the client.

Parameters:
  • name (str) – name of the font see in the html url

  • filepath (str) – Path in server file system

register_form(addons: str | None = None) Callable[source]

Register a WTForm.

This a decorator.

@myferet.register_form()
class MyForm(FeretUIForm):
    foo = StringField()
Parameters:

addons (str) – The addons where the message come from

register_image(name: str, filepath: str) None[source]

Register an image file to use it in the client.

Parameters:
  • name (str) – name of the image see in the html url

  • filepath (str) – Path in server file system

register_js(name: str, filepath: str) None[source]

Register a javascript file to import in the client.

Parameters:
  • name (str) – name of the file see in the html url

  • filepath (str) – Path in server file system

register_page(name: str | None = None, templates: Iterable[str] | None = None, forms: Iterable[FeretUIForm] | None = None, addons: str | None = None) Callable[source]

Register a page.

This is a decorator to register a page.

A page is a function :

  • Params

    • FeretUI

    • Session

    • dict

  • return the strof the html page

@myferet.register_page()
def my_page(feretui, session, options):
    return ...

By default the name is the name of the decorated callable. but this nae can be overritting

@myferet.register_page(name='my_page')
def _my_page(feretui, session, options):
    return ...

If need, the templates can be passed in the decorator and are added in the templates librairy

@myferet.register_page(template=[
    '''
        <template id="...">
            ...
        </template>
    '''
])
def my_page(feretui, session, options):
    return ...

You can register a WTForm

class MyForm(FeretUIForm):
    ...

@myferet.register_page(forms=[MyForm])
def my_page(feretui, session, options):
    return ...
Parameters:
  • name (str) – The name of the pages stored in FeretUI.pages

  • templates (list[str]) – The str of the template to load

  • forms – The WTForm to register at the same time

  • addons (str) – The addons where the message come from

Returns:

Return a decorator

Return type:

Callable

register_resource(addons: str | None = None) None[source]

Register and build the resource instance.

myferet.register_resource(
    'code of the resource',
    'label',
)
class MyResource(Resource):
    pass
Parameters:

addons (str) – The addons where the message come from

register_static_page(name: str, template: str, templates: Iterable[str] | None = None, addons: str | None = None) None[source]

Register a page.

This method register the page template and the callable to serve it without additionnal callable.

myferet.register_static_page('my-page', '<div>My Page</div>')

If need, the templates can be passed in the decorator and are added in the templates librairy

myferet.register_static_page(
    'my-page',
    '<div>My Page</div>',
    template=[
        '''
            <template id="...">
                ...
            </template>
        '''
    ]
)
Parameters:
  • name (str) – The name of the pages stored in FeretUI.pages

  • templates (Iterable[str]) – The str of the additionnal templates to load

  • addons (str) – The addons where the message come from

register_template_file(template_path: str, addons: str | None = None) None[source]

Import a template file in FeretUI.

The template file is imported in feretui.template.Template, and it is declared in the feretui.translation.Translation.

It is possible to load more than one template file.

myferet.register_template_file('path/of/template.tmpl')
Parameters:
  • template_path (str) – The template file path to import the instance of FeretUI

  • addons (str) – The addons where the message come from

register_template_from_str(template: str, addons: str | None = None) None[source]

Import a template string in FeretUI.

The template string is imported in feretui.template.Template, and it is declared in the feretui.translation.Translation.

It is possible to load more than one template string.

myferet.register_template_from_str('''
    <template id="my-template">
        ...
    </template>
''')
Parameters:
  • template (str) – The template to import the instance of FeretUI

  • addons (str) – The addons where the message come from

register_theme(name: str, filepath: str) None[source]

Register a theme file to use it in the client.

Parameters:
  • name (str) – name of the theme see in the html url

  • filepath (str) – Path in server file system

register_toolbar_left_menus(menus: list[ToolBarMenu], addons: str | None = None) None[source]

Register a menu in the left part of the toolbar.

myferet.register_toolbar_left_menus([
    ToolBarMenu(...),
])
Parameters:
Exception:

feretui.exceptions.MenuError

register_toolbar_right_menus(menus: list[ToolBarMenu], addons: str | None = None) None[source]

Register a menu in the right part of the toolbar.

myferet.register_toolbar_right_menus([
    ToolBarMenu(...),
])
Parameters:
Exception:

feretui.exceptions.MenuError

register_user_menus(menus: list[ToolBarMenu], addons: str | None = None) None[source]

Register a menu in the dropdown in the user menu.

myferet.register_user_menus([
    ToolBarMenu(...),
])
Parameters:
Exception:

feretui.exceptions.MenuError

render(request: Request) Response[source]

Return the render of the main page.

Parameters:

request – The feretui request

Returns:

Return the html page athrough a feretui Response

Return type:

class:

feretui.response.Response

render_template(session: Session, template_id: str, **kwargs) str[source]

Get a compiled template.

The compiled template from feretui.template.Template, This template is translated in function of the lang attribute of the session. All the named arguments is used by jinja librairy to improve the render.

myferet.render_template(session, 'my-template')

The jinja render is done after the compilation of the template. Because the template is stored in function of the declared templates and the language. The jinja depend of the execution in function of the parameter and can be saved but recomputed at each call.

Parameters:
  • session (feretui.session.Session) – The user feretui’s session

  • template_id (str) – The identify of the template

Returns:

The compiled templated through feretui.template.Template and jinja

Return type:

str

property statics: dict[str, str | Path]

Return the statics registry.

Returns:

The dictionary of static files

Return type:

dict[str, str | Path]

property themes: dict[str, str]

Return the themes registry.

Returns:

The dictionary of registered themes

Return type:

dict[str, str]

class feretui.FeretUIForm(*args, **kwargs)[source]

Form base class.

The goal is to give at the Form used by FeretUI the behaviour like:

  • translation

  • bulma renderer

It is not required to used it. If the translation or the renderer is not automaticly done by FeretUI.

class MyForm(FeretUIForm):
    name = StringField()
DEFAULT_WRAPPER(session: Session, field: Field, **kwargs: dict) Markup

Render input field.

Parameters:
Returns:

The renderer of the widget as html.

Return type:

Markup

class Meta[source]

Meta class.

Added * Translation * Bulma render

bind_field(form: Form, unbound_field: UnboundField, options: dict) Field[source]

Bind the field to the form.

Added translation for the field

get_translations(form: FeretUIForm) FormTranslations[source]

Return Translation class.

Parameters:

form (FeretUIForm) – The form instance

Returns:

The translation class to link feretui translation.

Return type:

FormTranslations

render_field(field: Field, render_kw: dict) Markup[source]

Render the field.

Parameters:

field (Field) – The field to render

Returns:

The renderer of the widget as html.

Return type:

Markup

classmethod export_catalog(translation: Translation, po: POFile) None[source]

Export the Form translation in the catalog.

Parameters:
  • translation (Translation) – The translation instance to add also inside it.

  • po (PoFile) – The catalog instance

classmethod get_context() str[source]

Return the context for the translation.

classmethod register_translation(message: str) str[source]

Register a translation come from validator.

Some text is defined in the validator or WTForms addons. They can not be export easily. This register give the possibility for the devloper to define their.

class feretui.GotoViewAction(label: str, view: str, icon: str | None = None, description: str | None = None, visible_callback: Callable | None = None)[source]

Action class.

Define an action in actionset in the view meta.

get_url(feretui: FeretUI, session: Session, options: dict) str[source]

Return the hx-post url.

Parameters:
Returns:

The url

Return type:

str

class feretui.LCRUDResource[source]

LCRUDResource class.

This class is a mixin, it inherit the mixins:

class MetaViewCreate[source]

Meta view class for create.

class MetaViewDelete[source]

Meta view class for delete.

class MetaViewList[source]

Meta view class for list.

class MetaViewRead[source]

Meta view class for read.

class MetaViewUpdate[source]

Meta view class for update.

class feretui.LResource[source]

LResource class.

MetaViewList

alias of DefaultViewList

build_view(view_cls_name: str) Resource[source]

Return the view instance in fonction of the MetaView attributes.

Parameters:

view_cls_name (str) – name of the meta attribute

Returns:

An instance of the view

Return type:

feretui.resources.view.View

filtered_reads(form_cls: FeretUIForm, filters: list[tuple[str, list[str]]], offset: int, limit: int) dict[source]

Return the dataset of the list.

should return a dict with 2 key * forms: list of instance of form_cls * total: number of the exisinting entries without offset and limit

Warning

must be overwriting

Parameters:
  • form_cls (feretui.form.FeretUIForm) – Form of the list view

  • filters (list[tuple[str, list[str]]]) – The filters choosen in the list

  • offset (int) – The start of the plage of the dataset

  • limit (int) – The size of the plage of the dataset

Returns:

the dataset

Return type:

dict

class feretui.Password(min_size: int = 12, max_size: int | None = None, has_lowercase: bool = True, has_uppercase: bool = True, has_letters: bool = True, has_digits: bool = True, has_symbols: bool = True, has_spaces: bool = False)[source]

Password validator.

It is a generic validator for WTForms. It is based on the library password-validator.

class MyForm(Form):
    password = PasswordField(validators=[Password()])
Parameters:
  • min_size (int) – The minimal size of the password. If None then no minimal size.

  • max_size (int) – The maximal size. If None then no maximal size.

  • has_lowercase (bool) – If True the password must have one or more lowercase. If False the password must not have any lowercase If None no rule on the lowercase

  • has_uppercase (bool) – If True the password must have one or more uppercase. If False the password must not have any uppercase If None no rule on the uppercase

  • has_letters (bool) – If True the password must have one or more letters. If False the password must not have any letters If None no rule on the letters

  • has_digits (bool) – If True the password must have one or more digits. If False the password must not have any digits If None no rule on the digits

  • has_symbols (bool) – If True the password must have one or more symbols. If False the password must not have any symbols If None no rule on the symbols

  • has_spaces (bool) – If True the password must have one or more spaces. If False the password must not have any spaces If None no rule on the spaces

class feretui.RResource[source]

RResource class.

MetaViewRead

alias of DefaultViewRead

build_view(view_cls_name: str) Resource[source]

Return the view instance in fonction of the MetaView attributes.

Parameters:

view_cls_name (str) – name of the meta attribute

Returns:

An instance of the view

Return type:

feretui.resources.view.View

read(form_cls: FeretUIForm, pk: str) FeretUIForm[source]

Return an intance of the form.

Warning

must be overwriting

Parameters:
Returns:

the form instance

class feretui.Request(session: Session | None = None, method: RequestMethod = POST, form: MultiDict | None = None, params: MultiDict | None = None, querystring: str | None = None, headers: dict[str, str] | None = None)[source]

Description of the request.

This object is just a description of the web-server request.

Parameters:
  • session (Session) – User session

  • method (RequestMethod) – [Request.POST], the request method

  • form (MultiDict) – [None]

  • querystring (str) – [None]

  • params (dict) – [None]

  • headers (dict[str, str]) – [None]

Exception:

feretui.exceptions.RequestFormError

Exception:

feretui.exceptions.RequestNoSessionError

Exception:

feretui.exceptions.RequestWrongSessionError

DELETE = DELETE

DELETE request method

GET = GET

GET request method

PATCH = PATCH

PATCH request method

POST = POST

Post request method

PUT = PUT

PUT request method

get_base_url_from_current_url() dict[str, list[str]][source]

Get the querystring from the current client URL.

Returns:

The converted querystring.

Return type:

dict[str, list[str]]

get_query_string_from_current_url() dict[str, list[str]][source]

Get the querystring from the current client URL.

Returns:

The converted querystring.

Return type:

dict[str, list[str]]

get_url_from_dict(base_url: str = '/', querystring: dict[str, Any] | None = None) str[source]

Return an url.

The url is built in function the ain_url and the querystring.

Parameters:
  • base_url (str) – [/], the base url before the querystring.

  • querystring (dict[str, Any]) – [None], the querystring.

Returns:

Return the URL.

Return type:

str

class feretui.Resource[source]

Resource class.

class Form[source]

The Form class.

static action_security(func: Callable) Callable

Raise an exception if the user is not authenticated.

It is a decorator

@myferet.register_action
@action_for_authenticated_user
def my_action(feretui, request):
    return Response(...)
Returns:

a wrapper function:

Return type:

Callable

Exception:

ActionUserIsNotAuthenticatedError

classmethod build() None[source]

Build the additional part of the resource.

build_view(view_cls_name: str) View[source]

Return the view instance in fonction of the MetaView attributes.

Parameters:

view_cls_name (str) – name of the meta attribute

Returns:

An instance of the view

Return type:

feretui.resources.view.View

export_catalog(translation: Translation, po: POFile) None[source]

Export the translations in the catalog.

Parameters:
  • translation (Translation) – The translation instance to add also inside it.

  • po (PoFile) – The catalog instance

get_label(feretui: FeretUI, session: Session) str[source]

Return the translated label.

Parameters:
Return type:

str.

get_meta_view_class(view_cls_name: str) list[source]

Return all the meta view class.

Parameters:

view_cls_name (Class) – The name of the meta class

Returns:

list of the class

Return type:

list

static menu_visibility(session: Session) bool

Return True if the user is authenticated.

See the feretui.menus.Menu

Parameters:

session (feretui.session.Session) – The user session

Returns:

True if the user is authenticated

Return type:

bool

render(feretui: FeretUI, session: Session, options: dict) str[source]

Render the resource.

Parameters:
Returns:

The html page in

Return type:

str.

router(feretui: FeretUI, request: Request) Response[source]

Resource entry point actions.

Parameters:
Returns:

The page to display

Return type:

feretui.response.Response

class feretui.Response(body: str | None = '', status_code: int = 200, headers: dict[str, str] | None = None)[source]

Description of the response.

This object is just a description to inform the web-server library the return of FeretUI

from feretui import Response


response = Response('<div>This is a template</div>')
Parameters:
  • body (Any) – [‘’], response return to the web-serving.

  • status_code (int) – [200], the status code of the response.

  • headers (dict[str, str]) – Optionnal, additionnal headers.

class feretui.SelectedRowsAction(label: str, method: str, icon: str | None = None, description: str | None = None, visible_callback: Callable | None = None)[source]

SelectedRowsAction class.

This action is not disabled when an entry is selected.

class feretui.Session(user: str | None = None, lang: str = 'en', theme: str = 'default', **kwargs: dict)[source]

Description of the session.

The session can be overwritting by the developper:

from feretui import Session


class MySession(Session):
    pass

You should overwrite the methods to link the session with your user model.

Attributes

  • [user: str = None] : User name of the session

  • [lang: str = ‘en’] : The language use by the user session

  • [theme: str = ‘default’] : The ui theme use by the user session

class LoginForm(*args, **kwargs)

WTform for the login.

class SignUpForm(*args, **kwargs)

WTform for sign up.

login(form: FeretUIForm) None[source]

Login.

Parameters:

form – the WTForm object

logout() None[source]

Logout.

signup(form: FeretUIForm) bool[source]

Signup.

Parameters:

form – the WTForm object

to_dict() dict[source]

Return the value of the session as a dict.

class feretui.ToolBarButtonMenu(label: str, css_class: str | None = None, **kwargs: dict[str, str])[source]

Menu class for the toolbar.

menu = ToolBarButtonMenu('My label')
if menu.is_visible(session):
    menu.render(myferet, session)
render(feretui: FeretUI, session: Session) str[source]

Return the html of the menu.

Parameters:
Returns:

The html

Return type:

str

template_id: str = 'toolbar-button-menu'

The template id to display in the Menu.render()

class feretui.ToolBarButtonUrlMenu(label: str, url: str, visible_callback: ~collections.abc.Callable = <function menu_for_authenticated_user>, **kw: dict[str, str])[source]

Menu class for the toolbar.

menu = ToolBarButtonUrlMenu('My label')
if menu.is_visible(session):
    menu.render(myferet, session)
template_id: str = 'toolbar-button-url-menu'

The template id to display in the Menu.render()

class feretui.ToolBarButtonsMenu(children: ToolBarMenu, visible_callback: Callable | None = None)[source]

Menu class for the toolbar.

menu = ToolBarButtonMenu([
    ToolBarButtonMenu('My label'),
])
if menu.is_visible(session):
    menu.render(myferet, session)
template_id: str = 'toolbar-buttons-menu'

The template id to display in the Menu.render()

class feretui.ToolBarDividerMenu(visible_callback: ~collections.abc.Callable = <function menu_for_authenticated_user>)[source]

Simple Divider.

render(feretui: FeretUI, session: Session) str[source]

Return the html of the menu.

Parameters:
Returns:

The html

Return type:

str

template_id: str = 'toolbar-divider-menu'

The template id to display in the Menu.render()

class feretui.ToolBarDropDownMenu(label: str, children: list[ToolBarMenu] | None = None, **kwargs: dict[str, str])[source]

DropDown for toolbar.

menu = ToolBarDropDownMenu(
    'Label',
    children=[ToolBarMenu('My label')])
if menu.is_visible(session):
    menu.render(myferet, session)
template_id: str = 'toolbar-dropdown-menu'

The template id to display in the Menu.render()

class feretui.ToolBarMenu(label: str, **kwargs: dict[str, str])[source]

Menu class for the toolbar.

menu = ToolBarMenu('My label')
if menu.is_visible(session):
    menu.render(myferet, session)
template_id: str = 'toolbar-menu'

The template id to display in the Menu.render()

class feretui.ToolBarUrlMenu(label: str, url: str, **kw: dict[str, str])[source]

Menu class to add a link to another web api.

menu = ToolBarUrlMenu('My label', url="https://bulma.io")
if menu.is_visible(session):
    menu.render(myferet, session)
template_id: str = 'toolbar-url-menu'

The template id to display in the Menu.render()

class feretui.UResource[source]

UResource class.

MetaViewUpdate

alias of DefaultViewUpdate

build_view(view_cls_name: str) Resource[source]

Return the view instance in fonction of the MetaView attributes.

Parameters:

view_cls_name (str) – name of the meta attribute

Returns:

An instance of the view

Return type:

feretui.resources.view.View

read(form_cls: FeretUIForm, pk: str) FeretUIForm[source]

Return an intance of the form.

Warning

must be overwriting

Parameters:
Returns:

the form instance

update(forms: list[FeretUIForm]) None[source]

Update an object from the form.

Warning

must be overwriting

Parameters:

form (feretui.form.FeretUIForm) – The instance of Form

feretui.action_for_authenticated_user(func: Callable) Callable[source]

Raise an exception if the user is not authenticated.

It is a decorator

@myferet.register_action
@action_for_authenticated_user
def my_action(feretui, request):
    return Response(...)
Returns:

a wrapper function:

Return type:

Callable

Exception:

ActionUserIsNotAuthenticatedError

feretui.action_for_unauthenticated_user(func: Callable) Callable[source]

Raise an exception if the user is authenticated.

It is a decorator

@myferet.register_action
@action_for_unauthenticated_user
def my_action(feretui, request):
    return Response(...)
Returns:

a wrapper function:

Return type:

Callable

Exception:

ActionUserIsAuthenticatedError

feretui.action_validator(methods: list[RequestMethod] | None = None) Callable[source]

Validate the action callback.

@myferet.register_action
@action_validator(methods=[RequestMethod.POST])
def my_action(feretui, request):
    return Response(...)

Note

The response of the callback must be a feretui.response.Response

Parameters:

methods (list[feretui.request.RequestMethod]) – The request methods of the action, if None the action can be called with any request method, else allow only the defined request methods.

Returns:

a wrapper function:

Return type:

Callable

feretui.menu_for_authenticated_user(session: Session) bool[source]

Return True if the user is authenticated.

See the feretui.menus.Menu

Parameters:

session (feretui.session.Session) – The user session

Returns:

True if the user is authenticated

Return type:

bool

feretui.menu_for_unauthenticated_user(session: Session) bool[source]

Return True if the user is not authenticated.

See the feretui.menus.Menu

Parameters:

session (feretui.session.Session) – The user session

Returns:

True if the user is not authenticated

Return type:

bool

feretui.page_for_authenticated_user_or_goto(fallback_page: str | Callable) Callable[source]

Display the decorated page if the user is authenticated.

In the case or the user is not autenticated. The returned page is the fallback page.

@page_for_authenticated_user_or_goto('404')
def my_page(myferet, session, options):
    ...
Parameters:

fallback_page (str or the callable page) – The page if the user is not authenticated

Returns:

a decorator

Return type:

Callable

feretui.page_for_unauthenticated_user_or_goto(fallback_page: str | Callable) Callable[source]

Display the decorated page if the user is not authenticated.

In the case or the user is autenticated. The returned page is the fallback page.

@page_for_unauthenticated_user_or_goto('forbidden')
def my_page(myferet, session, options):
    ...
Parameters:

fallback_page (str or the callable page) – The page if the user is authenticated

Returns:

a decorator

Return type:

Callable

Indices and tables