Django admin
ModelAdminWidget
- class pyforms_web.widgets.django.modeladmin.ModelAdminWidget(*args, **kwargs)[source]
Bases:
pyforms_web.basewidget.BaseWidget
The class is used to generate an admin interface for ModelAdmin.MODEL.
from suppliers.models import Suplier class SupplierAdminApp(ModelAdminWidget): MODEL = Supplier TITLE = 'Suppliers'
- Parameters
title (str) – Title of the app. By default will assume the value in the class variable TITLE.
model (django.db.models.Model) – Model the App will manages. By default will assume the value in the class variable MODEL.
editform_class (class) – Class used to generate the edition form. By default will assume the value in the class variable EDITFORM_CLASS.
parent_pk (int) – (optional) Used to generate the inline interface. Primary key of the parent model
parent_model (Model) – (optional) Used to generate the inline interface. Parent model
- MODEL = None
class: Model to manage
- TITLE = None
str: Title of the application
- EDITFORM_CLASS
class: Edit form class
alias of
pyforms_web.widgets.django.modelform.ModelFormWidget
- ADDFORM_CLASS = None
class: Create form class
- USE_DETAILS_TO_ADD = True
boolean: Use the flag to create the ControlEmptyWidget self._details. This control is used to load the ADDFORM_CLASS.
- USE_DETAILS_TO_EDIT = True
boolean: Use the flag to create the ControlEmptyWidget self._details. This control is used to load the EDITFORM_CLASS.
- INLINES = []
list(class): Sub models to show in the interface
- LIST_FILTER = None
list(str): List of filters fields
- LIST_DISPLAY = None
list(str): List of fields to display in the table
- LIST_HEADERS = None
list(str): Table columns headers. It will override the LIST_DISPLAY
- LIST_COLS_SIZES = None
list(str): Table columns sizes. Should use style units.
- LIST_COLS_ALIGN = None
list(str): Table columns alignments. Should use style units.
- SEARCH_FIELDS = None
list(str): Fields to be used in the search
- EXPORT_CSV = False
boolean: Flag to activate the export of data to csv. The value of this flag is overwritten by the function has_export_csv_permissions
- EXPORT_CSV_COLUMNS = None
list(str): List of fields to export to the csv file. By default it will assume the fields in the LIST_DISPLAY variable
- EXPORT_CSV_HEADERS = {}
dict(str: str): Provide custom header labels to fields listed in EXPORT_CSV_COLUMNS, e.g. {‘date’: ‘Procedure Date’}
- CONTROL_LIST
class: Control to be used in to list the values
alias of
pyforms_web.controls.control_querylist.ControlQueryList
- FIELDSETS = None
Formset of the edit form
- READ_ONLY = []
list(str): List of readonly fields
- LIST_ROWS_PER_PAGE = 10
int: number of rows to show per page
- LIST_N_PAGES = 5
int: number of pages to show in the list bottom
- ADD_BTN_LABEL = '<i class="plus icon"></i> Add'
str: Label of the add button
- property selected_row_object
django.db.models.Model: Return the current selected row object. If no row is selected return None.
- get_toolbar_buttons(has_add_permission=False)[source]
This function generate the formset configuration for the top buttons,
- Returns:
list(str): Returns the formset configuration that will be append to the end of the fieldsets.
- get_queryset(request, queryset)[source]
The function retrives the queryset used to polulate the list.
- Parameters
queryset (django.db.models.query.QuerySet) – Default queryset used to populate the list. This queryset may have already applied the next filters: - If this class is being used as a inline app, the filters to select only the rows related with the parent app are applied. - If the model being managed by this class has a function called get_queryset(request, queryset), the filters applied by this function are applied. (this helps maintaining the visualization rules on the side of the model)
- Returns:
django.db.models.query.QuerySet: Returns the queryset used to populate the list.
Called to return the main list filters for the ForeignKeys and ManyToMany fields.
- Parameters
request (django.http.request.HttpRequest) – HttpRequest originating the call of this function.
list_queryset (django.db.models.query.QuerySet) – Queryset of the main list.
field (django.db.models.fields.Field) – Related django field.
queryset (django.db.models.query.QuerySet) – Default queryset for the related field.
- Returns:
django.db.models.query.QuerySet: Results.
- show_edit_form(obj_pk=None)[source]
Show the edition for for a specific object
- Parameters
obj_pk (int) – Primary key of the object to be show in the edit form.
- get_editmodel_class(obj)[source]
Gets the pyforms app to edit the object
- Parameters
obj (django.db.models.Model) – Object to be edited
- set_parent(parent_model, parent_pk)[source]
Function called to set prepare the Application to work as an inline
- Parameters
parent_model (django.db.models.Model) – Model of the parent Edition form
parent_pk (int) – Primary key of the parent object
- has_add_permissions()[source]
Function called to check if one has permission to add new objects.
- Returns:
bool: True if has add permission, False otherwise.
- has_view_permissions(obj)[source]
Function called to check if one has permission to view the current queryset.
- Parameters
obj (django.db.models.Model) – object to view.
- Returns:
bool: True if has view permissions, False otherwise.
- has_remove_permissions(obj)[source]
Function called to check if one has permission to remove the current queryset.
- Parameters
obj (django.db.models.Model) – object to remove.
- Returns:
bool: True if has remove permissions, False otherwise.
- has_update_permissions(obj)[source]
Function called to check if one has permission to update the current queryset.
- Parameters
obj (django.db.models.Model) – object to update.
- Returns:
bool: True if has update permissions, False otherwise.
- has_export_csv_permissions(user)[source]
Function called to check if one has permission to export the objects to csv.
- Parameters
django.contrib.auth.models.User – User to check the permission.
- Returns:
bool: True if has permissions, False otherwise.
ModelFormWidget
- class pyforms_web.widgets.django.modelform.ModelFormWidget(*args, **kwargs)[source]
Bases:
pyforms_web.basewidget.BaseWidget
When a Pyforms application inherit from this class a form for the model ModelFormWidget.MODEL is created.
Usage example:
from funding.models import FundingOpportunity class EditFundingOpportunitiesApp(ModelFormWidget): TITLE = "Edit opportunities" MODEL = FundingOpportunity FIELDSETS = [ 'h2:Opportunity details', segment([ ('subject','fundingopportunity_published','fundingopportunity_rolling'), ('fundingopportunity_name','fundingopportunity_end'), ('_loi','fundingopportunity_loideadline', 'fundingopportunity_fullproposal'), ('fundingopportunity_link','topics'), ]), 'h2:Financing info', segment([ ('financingAgency','currency','paymentfrequency'), ('fundingtype','fundingopportunity_value','fundingopportunity_duration'), ]), 'h2:Description', segment([ 'fundingopportunity_eligibility', 'fundingopportunity_scope', 'fundingopportunity_brifdesc', ]) ]
- Parameters
title (str) – Title of the app. By default will assume the value in the class variable TITLE.
model (django.db.models.Model) – Model with the App will represent. By default will assume the value in the class variable MODEL.
inlines (list(ModelAdminWidget)) – Sub models to show in the interface
parent_pk (int) – Parent model key
parent_model (django.db.models.Model) – Parent model class
pk (int) – Model register to manage
- MODEL = None
class: Model to manage
- TITLE = None
str: Title of the application
- INLINES = []
list(class): Sub models to show in the interface
- FIELDSETS = None
Formset of the edit form
- READ_ONLY = []
list(str): List of readonly fields
- HAS_CANCEL_BTN_ON_EDIT = True
bool: Flag to show or hide the cancel button
- HAS_CANCEL_BTN_ON_ADD = True
bool: Flag to show or hide the cancel button
- CLOSE_ON_REMOVE = False
bool: Close the application on remove
- CLOSE_ON_CANCEL = False
bool: Close the application on cancel
- POPULATE_PARENT = True
bool: Call populate_list function of the parent application when object is saved, updated or deleted
- SAVE_BTN_LABEL = '<i class="save icon"></i> Save'
str: Label for the save button
- CREATE_BTN_LABEL = '<i class="plus icon"></i> Create'
str: Label for the create button
- CANCEL_BTN_LABEL = '<i class="hide icon"></i> Close'
str: Label for the cancel button
- REMOVE_BTN_LABEL = '<i class="trash alternate outline icon"></i> Remove'
str: Label for the delete button
- POPUP_REMOVE_TITLE = 'The next objects are going to be affected or removed'
str: Label for the popup window for the delete confirmation
- property parent_object
- property model_object
django.db.models.Model object: Return the current object in edition.
- get_readonly(default)[source]
The function returns the readonly fields to be set in the form.
- Returns:
list(str): Read only fields. Check class variable READ_ONLY to know more about it.
- get_fieldsets(default)[source]
The function returns the fieldsets organization to be set in the form.
- Returns:
list(str): fieldsets. Check class variable FIELDSETS to know more about it.
- get_buttons_row()[source]
This function generate the formset configuration for the save, create, cancel and remove buttons,
- Returns:
list(str): Returns the formset configuration that will be append to the end of the fieldsets.
- autocomplete_search(queryset, keyword, control)[source]
Function used by a combobox to get the items dynamically
- Parameters
queryset (django.db.models.query.QuerySet) – Queryset from where to filter the results
keyword (str) – Keyword for filter the results
pyforms.controls.BaseControl – Control calling the autocomplete
- Returns:
django.db.models.query.QuerySet: Queryset used to update the autocomplete control
Function called to manages the query for related fields like ForeignKeys and ManyToMany.
- Parameters
field (django.db.models.fields.Field) – Related django field.
queryset (django.db.models.query.QuerySet) – Default queryset for the related field.
- Returns:
django.db.models.query.QuerySet: Results for the search in the format.
Function called update the related fields like ForeignKeys and ManyToMany.
- Parameters
field (django.db.models.fields.Field) – Related django field.
pyforms_field (ControlBase) – Pyforms field that will be updated.
queryset (django.db.models.query.QuerySet) – Default queryset for the related field.
- show_edit_form(pk=None)[source]
This function prepares the fields to be shown as edit form.
- Parameters
pk (int) – Primary key of the object to be show in the edit form.
- Returns:
- django.db.models.Model object
Returns the object in edition.
- delete_event()[source]
Function called to delete the current object in edition.
- Returns:
- bool
True if the object was deleted with success, False if not.
- popup_remove_handler(popup=None, button=None)[source]
Function that handles the buttons events of the object delete confirmation popup.
- Parameters
popup (BaseWidget) – Popup application.
button (str) – Label of the pressed button.
- create_newobject()[source]
Function called to create a new object of the model.
- Returns:
- django.db.models.Model object
Created object
- save_object(obj, **kwargs)[source]
Function called to save the object It validates the form fields values.
- validate_object(obj)[source]
Function called the model object
- Parameters
obj (django.db.models.Model) – Object to validate.
- Returns:
- django.db.models.Model object
Created object or None if the object was not saved with success.
- update_object_fields(obj)[source]
Update the obj fields values with the form inputs values
- Parameters
obj (django.db.models.Model) – Object to update the values.
- Returns:
- django.db.models.Model
Updated object.
Save related fields
- Parameters
obj (django.db.models.Model) – Parent object to save.
- Returns:
- django.db.models.Mode
Object passed as parameter
- save_form_event(obj)[source]
Function handling the form save. This function, updates the obj with the form values, validate the obj fields, and call the save_event function.
- Parameters
obj (django.db.models.Model) – Model object used for the save.
- Returns:
- boolean
It returns True or False if the save was successfully.
- save_event(obj, new_object)[source]
Function handling the form save. This function, updates the obj with the form values, validate the obj fields, and call the save_event function.
- Parameters
obj (django.db.models.Model) – Model object used for the save.
new_object (Boolean) – Flag indicating if it is an Add or Update.
- Returns:
- boolean
It returns True or False if the save was successfully.
- get_visible_fields_names()[source]
Function called to get names of the visible fields.
- Returns:
- list(str)
List names of the visible fields.
- has_add_permissions()[source]
The functions returns if the user has permissions to add objects or not.
- Returns:
bool: True if has add permissions, False otherwise.
- has_view_permissions()[source]
The functions returns if the user has permissions to view the queryset or not.
- Returns:
bool: True if has view permissions, False otherwise.
- 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.
ModelViewFormWidget
- class pyforms_web.widgets.django.modelviewform.ModelViewFormWidget(*args, **kwargs)[source]
Bases:
pyforms_web.widgets.django.modelform.ModelFormWidget
When a Pyforms application inherit from this class a form for the model ModelViewFormWidget.MODEL is created with all the fields in the fieldset in read only mode.
Usage example:
from suppliers.models import Order class OrderView(ModelViewFormWidget): MODEL = Order TITLE = 'Order in read-only' FIELDSETS = [ 'h3:General Information', ('responsible','order_req'), 'supplier', {'a:Description':['order_desc'], 'b:Notes':['order_notes']}, ('order_amount', 'currency', 'order_paymethod'), ('order_reqnum', 'order_reqdate'), ('order_podate', 'order_deldate') ]
- Parameters
title (str) – Title of the app. By default will assume the value in the class variable TITLE.
model (django.db.models.Model) – Model with the App will represent. By default will assume the value in the class variable MODEL.
inlines (list(ModelAdminWidget)) – Sub models to show in the interface
parent_pk (int) – Parent model key
parent_model (django.db.models.Model) – Parent model class
pk (int) – Model register to manage