BaseWidget

../../_images/basewidget.png

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

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_nocolumns(formset)[source]

Generate the html for the no_columns organizer

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.

close()[source]

Close the application

message(msg, title=None, msg_type=None)[source]

Write a simple message.

Parameters
  • msg (str) – Message to show.

  • title (str) – Message title.

  • msg_type (str) – Message box css class.

success(msg, title=None)[source]

Write a success message

Parameters
  • msg (str) – Message to show.

  • title (str) – Message title.

info(msg, title=None)[source]

Write a info message

Parameters
  • msg (str) – Message to show.

  • title (str) – Message title.

warning(msg, title=None)[source]

Write a warning message

Parameters
  • msg (str) – Message to show.

  • title (str) – Message title.

alert(msg, title=None)[source]

Write a alert message

Parameters
  • msg (str) – Message to show.

  • title (str) – Message title.

message_popup(msg, title='', buttons=None, handler=None, msg_type='')[source]

Show a popup message window

Parameters
  • msg (str) – Message to show.

  • title (str) – Message title.

  • buttons (list(str)) – List of buttons labels to create in the popup window.

  • msg_type (str) – Message box css class.

  • handler (method) – Method that will handle the press of the buttons.

# Handler
def button_pressed_btn(popup=[Popup instance], button=[Label of the pressed button]):
     ...
success_popup(msg, title='', buttons=None, handler=None)[source]

Show a popup success message window

Parameters
  • msg (str) – Message to show.

  • title (str) – Message title.

  • buttons (list(str)) – List of buttons labels to create in the popup window.

  • handler (method) – Method that will handle the press of the buttons.

info_popup(msg, title='', buttons=None, handler=None)[source]

Show a popup info message window

Parameters
  • msg (str) – Message to show.

  • title (str) – Message title.

  • buttons (list(str)) – List of buttons labels to create in the popup window.

  • handler (method) – Method that will handle the press of the buttons.

warning_popup(msg, title='', buttons=None, handler=None)[source]

Show a popup warning message window

Parameters
  • msg (str) – Message to show.

  • title (str) – Message title.

  • buttons (list(str)) – List of buttons labels to create in the popup window.

  • handler (method) – Method that will handle the press of the buttons.

alert_popup(msg, title='', buttons=None, handler=None)[source]

Show a popup alert message window

Parameters
  • msg (str) – Message to show.

  • title (str) – Message title.

  • buttons (list(str)) – List of buttons labels to create in the popup window.

  • handler (method) – Method that will handle the press of the buttons.

commit()[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.

refresh_event()[source]

Event called every X time defined by REFRESH_TIMEOUT variable.

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