object_admin

Admin class for Plain Old Python Object

class camelot.admin.object_admin.FieldAttributesList(original_list)[source]

A list with field attributes that documents them for sphinx

class camelot.admin.object_admin.ObjectAdmin(app_admin, entity)[source]

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.

verbose_name

A human-readable name for the object, singular

verbose_name = _('movie')

If this isn’t given, the class name will be used

verbose_name_plural

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

list_display

a list with the fields that should be displayed in a table view

lines_per_row

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.

form_display

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

list_action

The camelot.admin.action.base.Action that will be triggered when the user selects an item in a list of objects. This defaults to camelot.admin.action.list_action.OpenFormView, which opens a form for the current object.

form_close_action

The action triggered when the form window is closed by the operating system or the window manager. By default this is the camelot.admin.action.form_action.CloseForm action, which validates the form and allows the user to discard the changes when the form is invalid. To change the form close action in the toolbar, the camelot.admin.object_admin.ObjectAdmin.get_form_actions() method should be overwritten.

form_size

a tuple indicating the size of a form view, defaults to (700,500)

form_actions

Actions to be accessible by pushbuttons on the side of a form, a list of camelot.admin.action.base.Action objects.

class Admin( EntityAdmin ):
    form_actions = [CloseForm()]

These actions will be triggered with a camelot.admin.action.form_action.FormActionModelContext as the model_context parameter in the camelot.admin.action.base.Action.model_run() method.

related_toolbar_actions

list of actions that appear in the toolbar of a OneToMany editor.

drop_action

the action that is triggered when a drag and drop occured on the table view

Field attributes

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 = Column( Unicode(50) )

    class Admin( EntityAdmin ):
        list_display = ['title']
        field_attributes = { 'title' : {'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.

Searching

A list of fields that should be searched when the user enters something in the search box in the table view. The field will only be searched when the entered string can be converted to the datatype of the underlying column using the from_string field attribute of the column.

A list of fields that will be searchable through the expanded search. When set to None, all the fields in list_display will be searchable. Use this attribute to limit the number of search widgets. Defaults to None.

Window state

form_state

Set this attribute to maximized or minimized for respective behaviour

class Movie( Entity ):

    title = Column( Unicode(50) )

    class Admin( EntityAdmin ):
        list_display = ['title']
        form_state = 'maximized'

Varia

name

The name of the group in settings in which user dependent settings will be stored, defaults to the class name for which this Admin class is used.

class TableView(gui_context, admin, search_text=None, proxy=<class 'camelot.view.proxy.queryproxy.QueryTableProxy'>, parent=None)
Parameters:

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 :

header_widget

The widget class to be used as a header in the table view:

header_widget = HeaderWidget

table_widget

The widget class used to display a table within the table view

table_widget = TableWidget

title_format

A string used to format the title of the view

title_format = ‘%(verbose_name_plural)s’

  • emits the row_selected signal when a row has been selected
class AdminTableWidget(admin, parent=None)

A table widget that inspects the admin class and changes the behavior of the table as specified in the admin class

ObjectAdmin.TableView.cancelSearch()

resets search filtering to default

ObjectAdmin.TableView.closeEvent(event)

reimplements close event

ObjectAdmin.TableView.header_widget

alias of HeaderWidget

ObjectAdmin.TableView.rebuild_query()

resets the table model query

ObjectAdmin.TableView.refresh()

Refresh the whole view

ObjectAdmin.TableView.sectionClicked(section)

emits a row_selected signal

ObjectAdmin.TableView.set_admin(admin)

Switch to a different subclass, where admin is the admin object of the subclass

ObjectAdmin.TableView.set_list_actions(actions)

sets filters for the tableview

ObjectAdmin.TableView.startSearch(text)

rebuilds query based on filtering text

ObjectAdmin.add(entity_instance)[source]

Add an entity instance as a managed entity instance

ObjectAdmin.copy(entity_instance)[source]

Duplicate this entity instance

ObjectAdmin.delete(entity_instance)[source]

Delete an entity instance

ObjectAdmin.expunge(entity_instance)[source]

Remove this object from the objects being managed

ObjectAdmin.flush(entity_instance)[source]

Flush the pending changes of this entity instance to the backend

ObjectAdmin.get_all_fields_and_attributes()[source]

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

ObjectAdmin.get_application_admin()[source]

Provide access to the ApplicationAdmin

Returns:the camelot.admin.application_admin.ApplicationAdmin object for the application.
ObjectAdmin.get_columns()[source]

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

Returns:
[(field_name,
{‘widget’: widget_type,
‘editable’: True or False, ‘blank’: True or False, ‘validator_list’:[...], ‘name’:’Field name’}),

...]

ObjectAdmin.get_compounding_objects(obj)[source]

Overwrite this function to generate a list of objects out of which obj is build. These objects will be validated if obj is validated. The effect of returning compounding objects will be :

  • obj will only be valid if all its compounding object are valid as well.
  • default values will be set for the attributes of the compounding objects
  • when an object is expired or refreshed, all its compounding objects will be expired and refreshed as well
ObjectAdmin.get_depending_objects(obj)[source]

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
ObjectAdmin.get_descriptor_field_attributes(field_name)[source]

Returns a set of default field attributes based on introspection of the descriptor of a field. This method is called within get_field_attributes. Overwrite it to handle custom descriptors.

The default implementation checks if the descriptor is a property, and sets the editable field attribute to True if the property has a setter defined.

Parameters:field_name – the name of the field
Returns:a dictionary with field attributes, empty in case no introspection of the attribute was possible
ObjectAdmin.get_dynamic_field_attributes(obj, field_names)[source]

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:
  • field_names – a list of field names
  • obj – the object at the row for which to get the values of the dynamic field attributes
Returns:

[{field_attribute_name:field_attribute_value, ...}, {}, ...]

The returned list has the same order than the requested field_names. A reimplementation of this method can look like:

def get_dynamic_field_attributes(self, obj, field_names):
    for field_attributes in super( MyAdmin, self ).get_dynamic_field_attributes(obj, field_names):
        if obj.status == 'finished':
            field_attributes['editable'] = True
        else:
            field_attributes['editable'] = False
        yield field_attributes
ObjectAdmin.get_entity_admin(entity)[source]

deprecated : use get_related_admin

ObjectAdmin.get_field_attributes(field_name)[source]

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.

ObjectAdmin.get_form_actions(obj=None)[source]

Specify the list of action buttons that should appear on the side of the form view.

Parameters:obj – the object displayed in the form (Deprecated, use action states to make the appearance of actions dynamic on a form)
Returns:a list of camelot.admin.action.base.Action objects
ObjectAdmin.get_form_toolbar_actions(toolbar_area)[source]

By default this function will return the same as camelot.admin.application_admin.ApplicationAdmin.get_form_toolbar_actions()

Parameters:toolbar_area – an instance of Qt.ToolBarArea indicating where the toolbar actions will be positioned
Returns:a list of camelot.admin.action.base.Action objects that should be displayed on the toolbar of a form view. return None if no toolbar should be created.
ObjectAdmin.get_list_action()[source]

Get the action that should be triggered when an object is selected in a table of objects.

Returns:by default returns the list_action attribute
ObjectAdmin.get_modifications(obj)[source]

Get the modifications on an object since the last flush. :param obj: the object for which to get the modifications :return: a dictionary with the changed attributes and their old

value
ObjectAdmin.get_name()[source]

The name of the group in settings in which user dependent settings will be stored, this is either the name attribute of this class or, the class name of the class for which this Admin class is used.

Returns:a string with the name of the settings group

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

Specify the toolbar actions that should appear in a OneToMany editor.

Parameters:
  • toolbar_area – the position of the toolbar
  • direction – the direction of the relation : ‘onetomany’ or ‘manytomany’
Returns:

a list of camelot.admin.action.base.Action objects

ObjectAdmin.get_search_fields(substring)[source]

Generate a list of fields in which to search. By default this method returns the list_search attribute.

Parameters:substring – that part of the complete search string for which the search fields are requested. This allows analysis of the search string to improve the search behavior
Returns:a list with the names of the fields in which to search
ObjectAdmin.get_search_identifiers(obj)[source]

Create a dict of identifiers to be used in search boxes. The keys are Qt roles.

ObjectAdmin.get_settings()[source]

A settings object in which settings related to this admin can be stored.

Returns:a QtCore.QSettings object
ObjectAdmin.get_static_field_attributes(field_names)[source]

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.

ObjectAdmin.get_subclass_tree()[source]

Get a tree of admin classes representing the subclasses of the class represented by this admin class

Returns:[(subclass_admin, [(subsubclass_admin, [...]),...]),...]
ObjectAdmin.get_table()[source]

The definition of the table to be used in a list view :return: a camelot.admin.table.Table object

ObjectAdmin.get_validator(model=None)[source]

Get a validator object

Returns:a camelot.admin.validator.object_validator.Validator
ObjectAdmin.get_verbose_identifier(obj)[source]

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.

ObjectAdmin.get_verbose_name()[source]

The name of the associated entity.

ObjectAdmin.get_verbose_object_name(obj)[source]

Textual representation of the current object.

ObjectAdmin.is_deleted(_obj)[source]
Returns:True if the object has been deleted from the persistent state, False otherwise
ObjectAdmin.is_persistent(_obj)[source]
Returns:True if the object has a persisted state, False otherwise
ObjectAdmin.model

alias of CollectionProxy

ObjectAdmin.primary_key(obj)[source]

Get the primary key of an object :param obj: the object to get the primary key from :return: a tuple with with components of the primary key, or an

emtpy list if the object has no primary key yet or any more.
ObjectAdmin.refresh(entity_instance)[source]

Undo the pending changes to the backend and restore the original state

ObjectAdmin.set_defaults(object_instance, include_nullable_fields=True)[source]

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

ObjectAdmin.set_field_value(obj, field_name, value)[source]

Set the value of a field on an object. By default this method calls the builtin setattr() function.

Parameters:
  • obj – the object on which to set the value
  • field_name – the name of the field, which by default will be used as the name of the attribute to set
  • value – the value to set
ObjectAdmin.validator

alias of ObjectValidator