BaseWidget
Overview
The BaseWidget class is the base class of all pyforms applications.
API
- class pyforms_web.basewidget.BaseWidget(*args, **kwargs)[source]
Bases:
object
The class implements a application form
- Parameters
title (str) – Title of the app. By default will assume the value in the class variable TITLE.
parent_win (BaseWidget) – Parent BaseWidget
Example:
class FeedViewerApp(BaseWidget): TITLE = 'Feed viewer' def __init__(self, *args, **kwargs): self._likebtn = ControlButton(label_visible=False, labeled=True) self._htmlviewer = ControlTemplate('Html', template=self.VIEWER_TEMPLATE) self.formset = ['_likebtn', '_htmlviewer']
- URLS = None
list(str): Django urls to be added to the urls.py file
- TITLE = None
str: Title of the application.
- LAYOUT_POSITION = None
int or str: Id of the layout handler function registered in the javascript by the function [pyforms.register_layout_place] or Element DOM id in the HTML where the application should be shown.
- REFRESH_TIMEOUT = None
str: Time in milliseconds to refresh the application.
- AUTHORIZED_GROUPS = None
list(str): List of django groups authorized to run the application
- CSS = ''
str: Css classes to add to the form.
- STATIC_FILES = []
str: Static files to include in the page
- TRIGGER_ON_KEYDOWN_CODES = []
list(int): List of keys codes to detect
- init_form(parent=None)[source]
Generate the application Form. Return the dict:
{ 'code': ..., # HTML code that will initialize the application. 'title': ..., # Title of the application. 'css': ..., # Application CSS. 'app_id': ..., # Application id. 'refresh_timeout': ... # Application refresh time. }
- generate_panel(formset)[source]
Generate a panel for the application form with all the controls:
- Parameters
formset (list) – formset configuration, used to generate the panel.
Example:
[ no_columns('_toggle_btn','_copy_btn', '_css_btn'), ' ', ('empty:twelve','_input'), '_text', { 'a:Free text': [ 'h1:Header 1', 'h2:Header 2', 'h3:Header 3', 'h4:Header 4', 'h5:Header 5', 'h1-right:Header 1', 'h2-right:Header 2', 'h3-right:Header 3', 'h4-right:Header 4', 'h5-right:Header 5', '-', 'Free text here', 'msg:Message text', 'info:Info message', 'warning:Warning message', 'alert:Alert message' ], 'b:Segments': [ 'The next example has a segment', segment( '_combo', '_check', css='secondary' ), '_list', '_label' ] } ]
tuple: displays the controls horizontally.
list: displays the controls vertically.
dict: displays the controls in Tabs.
Use [a:,b:,c:] prefix to sort the tabs.
‘-’: Draw a vertical line.
‘ ‘: Empty column.
Empty column: Use ‘ ‘, or the prefix ‘empty:’ + size of the column (ex: one, two, …, sixteen) to add a empty column.
segment: Wraps the formset around a segment (Semantic UI segment).
Call the parameter css, to add extra classes to the segment.
no_columns: Do not apply the fields columns alignments.
Free text: Do not apply the fields columns alignments.
Message: By using the prefixes [msg:,info:,warning:,alert:] you will wrap a free message on message box.
Headers: Use the prefixes [h1:,h2:,h3:,h4:,h5:,h1-right:,h2-right:,h3-right:,h4-right:,h5-right:] on free text.
- message_popup(msg, title='', buttons=None, handler=None, msg_type='', buttons_css=[])[source]
Show a popup message window
- Parameters
# Handler def button_pressed_btn(popup=[Popup instance], button=[Label of the pressed button]): ...
- success_popup(msg, title='', buttons=None, handler=None, buttons_css=[])[source]
Show a popup success message window
- info_popup(msg, title='', buttons=None, handler=None, buttons_css=[])[source]
Show a popup info message window
- warning_popup(msg, title='', buttons=None, handler=None, buttons_css=[])[source]
Show a popup warning message window
- alert_popup(msg, title='', buttons=None, handler=None, buttons_css=[])[source]
Show a popup alert message window
- commit(user=None)[source]
Save all the application updates to a file, so it can be used in the next session.
- execute_js(code)[source]
This function executes a javascript remotely on the client side.
- Parameters
code (str) – Javascript code to execute.
- mark_to_update_client()[source]
Used to flag pyforms that the application was updated and the updates should be sent to the client side
- deserialize_form(params)[source]
Load the json parameters sent by the client side
- Parameters
params (dict) – Data to load.
- serialize_form()[source]
Serialize the Form to a control.
- Returns:
dict: Data representings the current state of the application.
- classmethod has_permissions(user)[source]
This class method, verifies if a user has permissions to execute the application
- Parameters
params (User) – User to availuate the permissions.
- has_session_permissions(user)[source]
It verifies if a user has permissions to execute the application during the runtime.
- Parameters
params (User) – User to availuate the permissions.
- property controls
Returns all the form controls from the the module
- property form
Return the basewidget html. The html is based on the ‘basewidget-template.html’ template
- property title
Return and set the title of the application
- property formset
Return and set the controls organization in the form
- property uid
Return and set the application unique identifier
- property refresh_timeout
Return a boolean indicating if the form is visible or not
- property parent
- property form_loaded
Return True if the Widget already executed the init_form() function or not.