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.request.Request: It is the class object used by FeretUI to represent web-server request.feretui.response.Response: It is the class object used by FeretUI to respond at the client query.feretui.session.Session: It is the class object used by FeretUI to define to represent an user session, it is not the Session of the 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.
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.FeretUI.register_action: Decorator to register the callback as an action.feretui.FeretUI.execute_action: Method to execute an action.
FeretUI allow to add page mecanisme. The page are function and take as arguments the session and the querystring or the body.
feretui.FeretUI.register_page: Decorator to register the pageferetui.FeretUI.register_static_page: Declare a static pageferetui.FeretUI.get_page: Method to return the page function.
@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:
Toolbar: Renderer in the toolbar
feretui.menus.ToolBarMenu: Simple menuferetui.menus.ToolBarDropDownMenu: Dropdown menuferetui.menus.ToolBarDividerMenu: Séparator in dropdown menuferetui.menus.ToolBarUrlMenu: Link to another url.feretui.menus.ToolBarButtonMenu: Simple button menuferetui.menus.ToolBarButtonsMenu: Define a group of buttonsferetui.menus.ToolBarButtonUrlMenu: Link to another url. in a button
Aside: rendere in the aside-menu page
feretui.menus.AsideMenu: Simple menuferetui.menus.AsideHeaderMenu: Display a title and take sub menu.feretui.menus.AsideUrlMenu: Link to another url.
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.
feretui.resources.list.RResource
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:
feretui (
feretui.feretui.FeretUI) – The feretui client instance.session (
feretui.session.Session) – The session of the useroptions (dict) – The querystring
- 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:
feretui (
feretui.feretui.FeretUI) – The feretui client instance.session (
feretui.session.Session) – The session of the useroptions (dict) – The querystring
- 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 useroptions (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:
- 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
- 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
- TemplatingImport and get the template, need for display the client.
- Static filesDeclare static file to import in the client.
- ActionDeclare action called by the web server api.
- PageDeclare page called to render inside html body main
- MenuDeclare the menus registered in the feretui instance
Form : Declare the WTForm class in the feretui instance, need for the translation
- Resource: Declare the resource to CRUD
- TranslationsImport and export the catalog
- 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:
request (
feretui.request.Request) – The feretui request from api.action_name (str) – The name of the action
- Returns:
The result of the action
- Return type:
- 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]
Return the aside menus link with the code.
- Parameters:
code (str) – The code of the aside
- Returns:
The menus to render
- Return type:
- 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:
Return the sitemap menus.
- Returns:
The menus to render
- Return type:
- 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:
feretui (
FeretUI) – The instance of the clientsession (
feretui.session.Session) – The session of the user.
- 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:
feretui [
FeretUI] : The client instance.request [
feretui.request.Request] : The request
@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 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 registeraddons (str) – The addons where the message come from
- Exception:
Register the auth menus.
myferet.register_auth_menus([ ToolBarButtonMenu(...), ])
- Parameters:
menus (list[
feretui.menus.ToolBarButtonMenu]) – The menus to registeraddons (str) – The addons where the message come from
- Exception:
- 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 theferetui.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 theferetui.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 a menu in the left part of the toolbar.
myferet.register_toolbar_left_menus([ ToolBarMenu(...), ])
- Parameters:
menus (list[
feretui.menus.ToolBarMenu]) – The menus to registeraddons (str) – The addons where the message come from
- Exception:
Register a menu in the right part of the toolbar.
myferet.register_toolbar_right_menus([ ToolBarMenu(...), ])
- Parameters:
menus (list[
feretui.menus.ToolBarMenu]) – The menus to registeraddons (str) – The addons where the message come from
- Exception:
Register a menu in the dropdown in the user menu.
myferet.register_user_menus([ ToolBarMenu(...), ])
- Parameters:
menus (list[
feretui.menus.ToolBarMenu]) – The menus to registeraddons (str) – The addons where the message come from
- Exception:
- 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 sessiontemplate_id (str) – The identify of the template
- Returns:
The compiled templated through
feretui.template.Templateand 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:
feretui (
feretui.feretui.FeretUI) – The feretui clientsession (
feretui.session.Session) – The Sessionfield (Field) – The field to validate
- Returns:
The renderer of the widget as html.
- Return type:
- 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:
- 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
- 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:
feretui (
feretui.feretui.FeretUI) – The feretui client instance.session (
feretui.session.Session) – The session of the useroptions (dict) – The querystring
- Returns:
The url
- Return type:
str
- class feretui.LCRUDResource[source]¶
LCRUDResource class.
This class is a mixin, it inherit the mixins:
- 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:
- 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 viewfilters (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:
- read(form_cls: FeretUIForm, pk: str) FeretUIForm[source]¶
Return an intance of the form.
Warning
must be overwriting
- Parameters:
form_cls (
feretui.form.FeretUIForm) – Form of the list viewpk (str) – The primary key
- 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:
- Exception:
- Exception:
- 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.
- 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
- 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:
- 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:
feretui (
feretui.feretui.FeretUI) – The feretui clientsession (
feretui.session.Session) – The Session
- 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
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:
feretui (
feretui.feretui.FeretUI) – The feretui clientsession (
feretui.session.Session) – The Sessionoptions (dict) – The options come from the body or the query string
- Returns:
The html page in
- Return type:
str.
- router(feretui: FeretUI, request: Request) Response[source]¶
Resource entry point actions.
- Parameters:
feretui (
feretui.feretui.FeretUI) – The feretui clientrequest (
feretui.request.Request) – The request
- Returns:
The page to display
- Return type:
- 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
- signup(form: FeretUIForm) bool[source]¶
Signup.
- Parameters:
form – the WTForm object
- 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:
feretui (
feretui.feretui.FeretUI) – The feretui client instance.session (
feretui.session.Session) – The session of the user
- 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:
feretui (
feretui.feretui.FeretUI) – The feretui client instance.session (
feretui.session.Session) – The session of the user
- 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:
- read(form_cls: FeretUIForm, pk: str) FeretUIForm[source]¶
Return an intance of the form.
Warning
must be overwriting
- Parameters:
form_cls (
feretui.form.FeretUIForm) – Form of the list viewpk (str) – The primary key
- 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
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
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
Contents:
- Getting Started
- FeretUI client internals
- feretui module
- feretui.feretui module
- feretui.request module
- feretui.response module
- feretui.session module
- feretui.template module
- feretui.actions module
- feretui.pages module
- feretui.menus module
- feretui.form module
- feretui.resources modules
- feretui.helper module
- feretui.context module
- feretui.translation module
- feretui.exceptions module
- feretui.ext module
- How to contribute (hackers needed!)
- Troubleshooting
- CHANGELOG