Admin class for Plain Old Python Object
A list with field attributes that documents them for sphinx
The ObjectAdmin class describes the interface that will be used to interact with objects of a certain class. The behaviour of this class and the resulting interface can be tuned by specifying specific class attributes:
The name used in the GUI
The name used in the GUI for things like window titles and such can be specified using the verbose_name attribute.
A human-readable name for the object, singular
verbose_name = _('movie')
If this isn’t given, the class name will be used
A human-readable name for the object, plural
verbose_name_plural = _('movies')
If this isn’t given, Camelot will use verbose_name + “s”
Fields displayed
a list with the fields that should be displayed in a table view
the number of columns on the left of the tableview that should be frozen (don’t dissapear when the user uses the horizontal scroll bar), defaults to zero
An integer number specifying the height of a row in the table view, expressed as the number of lines of text it should be able to display. Defaults to 1.
a list with the fields that should be displayed in a form view, defaults to the same fields as those specified in list_display
class Admin(EntityAdmin):
form_display = ['title', 'rating', 'cover']
instead of telling which fields to display. It is also possible to define the form itself
from camelot.view.forms import Form, TabForm, WidgetOnlyForm, HBoxForm
class Admin(EntityAdmin):
form_display = TabForm([
('Movie', Form([
HBoxForm([['title', 'rating'], WidgetOnlyForm('cover')]),
'short_description',
'releasedate',
'director',
'script',
'genre',
'description', 'tags'], scrollbars=True)),
('Cast', WidgetOnlyForm('cast'))
])
Behaviour
Specifies when the data should be send from the view to the model and flushed to the database. The default mode is ‘on_change’, meaning that every change in the view will be send immediately to the database. Other possibilities are :
- ‘on_leave’ : the data will be send from the view to the model when the view
is closed, eg. : the form is closed.
Indicates if the deletion of an object should be confirmed by the user, defaults to ‘on_request’, indicating object should be deleted when the user hits the trash button. Other possibilities are :
- ‘on_confirm’ : the user will be asked for confirmation before the delete takes place.
a tuple indicating the size of a form view, defaults to (700,500)
Actions to be accessible by pushbuttons on the side of a form, a list of tuples (button_label, action_function) where action_function takes as its single argument, a method that returns the the object that was displayed by the form when the button was pressed:
class Admin(EntityAdmin):
form_actions = [('Foo', lamda o_getter:print 'foo')]
Field attributes
A dictionary specifying for each field of the model some additional attributes on how they should be displayed. All of these attributes are propagated to the constructor of the delegate of this field:
class Movie(Entity):
title = Field(Unicode(50))
class Admin(EntityAdmin):
list_display = ['title']
field_attributes = dict(title=dict(editable=False))
The Field Attributes documentation describes the various keys that can be used in the field attributes class attribute of an ObjectAdmin or EntityAdmin.
Window state
Set this attribute to ‘maximized’ or ‘minimized’ for respective behaviour. These are the only two defined at the moment. Please use the constants defined in camelot.core.constants (MINIMIZE and MAXIMIZE). Note that this attr needs to be set at the form, highest in the form hierarchy to work. Setting this on embedded forms will not influence the window state. Example:
class Movie(Entity):
title = Field(Unicode(50))
class Admin(EntityAdmin):
from camelot.core import constants
list_display = ['title']
form_state = constants.MAXIMIZED
field_attributes = dict(title=dict(editable=False))
Varia
The QAbstractItemModel class to be used to display collections of this object, defaults to a CollectionProxy
The QWidget class to be used when a table view is needed
A generic tableview widget that puts together some other widgets. The behaviour of this class and the resulting interface can be tuned by specifying specific class attributes which define the underlying widgets used
class MovieRentalTableView(TableView):
title_format = 'Grand overview of recent movie rentals'
The attributes that can be specified are :
The widget class to be used as a header in the table view:
header_widget = HeaderWidget
The widget class used to display a table within the table view
table_widget = TableWidget
A string used to format the title of the view
title_format = ‘%(verbose_name_plural)s’
A class implementing QAbstractTableModel that will be used as a model for the table view
table_model = QueryTableProxy
A table widget that inspects the admin class and changes the behavior of the table as specified in the admin class
resets search filtering to default
reimplements close event
Copy the selected rows in this tableview
Create a table model for the given admin interface
delete the selected rows in this tableview
return the columns to be displayed in the table view
generator for data queried by table model
return the name of the entity managed by the admin attribute
Returns: | a list with all the objects corresponding to the rows in the table |
---|
Returns: | a function that when called return an iterable with all the |
---|
objects corresponding to the selected rows in the table.
alias of HeaderWidget
“import data : the data will be imported in the activeMdiChild
Create a new row in the tableview
resets the table model query
Refresh the whole view
emits a row_selected signal
selects the specified row
returns a list of selected rows indexes
Switch to a different subclass, where admin is the admin object of the subclass
sets filters for the tableview
rebuilds query based on filtering text
alias of QueryTableProxy
generates html of the table
selects first row
selects last row
selects next row
selects previous row
Creates a Qt widget containing a form view, for a specific index in a model. Use this method to create a form view for a collection of objects, the user will be able to use PgUp/PgDown to move to the next object.
Parameters: |
|
---|
Create a Qt widget containing a form to create a new instance of the entity related to this admin class
The returned class has an ‘entity_created_signal’ that will be fired when a valid new entity was created by the form
Parameters: | collection_proxy – if specified, the object will be appended to |
---|
its underlying collection upon creation and removed from it upon discarding.
Create a form view for a single object, PgUp/PgDown will do nothing.
Parameters: |
|
---|
Flush the pending changes of this entity instance to the backend
A dictionary of (field_name:field_attributes) for all fields that can possibly appear in a list or a form or for which field attributes have been defined
The columns to be displayed in the list view, returns a list of pairs of the name of the field and its attributes needed to display it properly
- {‘widget’: widget_type,
- ‘editable’: True or False, ‘blank’: True or False, ‘validator_list’:[...], ‘name’:’Field name’}),
...]
Overwrite this function to generate a list of objects that depend on a given object. When obj is modified by the user, this function will be called to determine which other objects need their views updated.
Parameters: | obj – an object of the type that is managed by this admin class |
---|---|
Returns: | an iterator over objects that depend on obj |
Convenience function to get all the field attributes that are dynamic (depend on the object being visualized). This method is called once for each object/row in a table view and once for each object being visualized in a form view.
Parameters: |
|
---|---|
Returns: | [{field_attribute_name:field_attribute_value, ...}, {}, ...] |
The returned list has the same order than the requested field_names.
Get the attributes needed to visualize the field field_name. This function is called by get_static_field_attributes and get_dynamic_field_attributes.
This function first tries to fill the dictionary with field attributes for a field with those gathered through introspection, and then updates them with those found in the field_attributes class attribute.
Parameters: | field_name – the name of the field |
---|---|
Returns: | a dictionary of attributes needed to visualize the field |
The values of the returned dictionary either contain the value of the field attribute, or in the case of dynamic field attributes, a function that returns the value of the field attribute.
Get an admin object for another object class. Taking into account preferences of this admin object or for those of admin object higher up the chain such as the application admin object.
Parameters: | cls – the class for which an admin object is requested |
---|
deprecated : use get_related_admin
Convenience function to get all the field attributes that are static (don’t depend on the object being visualized). This method is only called once for a table or form view, independent of the number of objects/records being visualized.
Parameters: | field_names – a list of field names |
---|---|
Returns: | [{field_attribute_name:field_attribute_value, ...}, {}, ...] |
The returned list has the same order than the requested field_names.
Get a tree of admin classes representing the subclasses of the class represented by this admin class
Returns: | [(subclass_admin, [(subsubclass_admin, [...]),...]),...] |
---|
Create an identifier for an object that is interpretable for the user, eg : the primary key of an object. This verbose identifier can be used to generate a title for a form view of an object.
Returns: | True if the object has been deleted from the persistent |
---|
state, False otherwise
Returns: | True if the object has a persisted state, False otherwise |
---|
alias of CollectionProxy
Undo the pending changes to the backend and restore the original state
Set the defaults of an object :param include_nullable_fields: also set defaults for nullable fields, depending on the context, this should be set to False to allow the user to set the field to None
alias of ObjectValidator