entity_admin

class camelot.admin.entity_admin.EntityAdmin(app_admin, entity)[source]

Admin class specific for classes that are mapped by sqlalchemy. This allows for much more introspection than the standard camelot.admin.object_admin.ObjectAdmin.

It has additional class attributes that customise its behaviour.

Basic

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.

Filtering

list_filter

A list of fields that should be used to generate filters for in the table view. If the field named is a one2many, many2one or many2many field, the field name should be followed by a field name of the related entity

class Project( Entity ):
    oranization = OneToMany( 'Organization' )
    name = Column( Unicode(50) )

  class Admin( EntityAdmin ):
      list_display = ['organization']
      list_filter = ['organization.name']
../../_images/group_box_filter.png

Copying

copy_deep

A dictionary of fields that will be deep copied when the user presses the copy button. This is useful for OneToMany fields. The key in the dictionary should be the name of the field, and the value is a new dictionary that can contain other fields that need to be copied:

copy_deep = {'addresses':{}}
copy_exclude

A list of fields that should not be copied when the user presses the copy button:

copy_exclude = ['name']

The fields that form the primary key of the object will be excluded by default.

Searching

A list of fields that should be searched when the user enters something in the search box in the table view. By default all fields are searched for which Camelot can do a conversion of the entered string to the datatype of the underlying column.

For use with one2many, many2one or many2many fields, the same rules as for the list_filter attribute apply

search_all_fields

Defaults to True, meaning that by default all searchable fields should be searched. If this is set to False, one should explicitely set the list_search attribute to enable search.

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.

add(*args, **kwargs)[source]

Adds the entity instance to the default session, if it is not yet attached to a session

copy(*args, **kwargs)[source]

Duplicate an object. If no new object is given to copy to, a new one will be created. This function will be called every time the user presses a copy button.

Parameters:
  • obj – the object to be copied from
  • new_obj – the object to be copied to, defaults to None
Returns:

the new object

This function takes into account the deep_copy and the copy_exclude attributes. It tries to recreate relations with a minimum of side effects.

create_select_view(admin, query=None, search_text=None, parent=None)[source]

Returns a Qt widget that can be used to select an element from a query

Parameters:
  • query – sqlalchemy query object
  • parent – the widget that will contain this select view, the

returned widget has an entity_selected_signal signal that will be fired when a entity has been selected.

create_table_view(gui_context)[source]

Returns a QtGui.QWidget containing a table view :param gui_context: a camelot.admin.action.base.GuiContext object.

delete(*args, **kwargs)[source]

Delete an entity instance

expunge(*args, **kwargs)[source]

Expunge the entity from the session

flush(*args, **kwargs)[source]

Flush the pending changes of this entity instance to the backend

get_all_fields_and_attributes()[source]

In addition to all the fields that are defined in the views or through the field_attributes, this method returns all the fields that have been mapped.

get_dynamic_field_attributes(obj, field_names)[source]

Takes the dynamic field attributes from through the ObjectAdmin its get_dynamic_field_attributes and make relational fields not editable in case the object is not yet persisted.

get_expanded_search_fields(*args, **kwargs)[source]
Returns:a list of tuples of type [(field_name, field_attributes)]
get_field_attributes(*args, **kwargs)[source]

Get the attributes needed to visualize the field field_name :param field_name: the name of the field

Returns:a dictionary of attributes needed to visualize the field,
those attributes can be:
  • python_type : the corresponding python type of the object
  • editable : bool specifying wether the user can edit this field
  • widget : which widget to be used to render the field
  • ...
get_filters(*args, **kwargs)[source]

Returns the filters applicable for these entities each filter is

Returns:[(filter, filter_data)]
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
get_query(*args, **kwargs)[source]
Returns:an sqlalchemy query for all the objects that should be

displayed in the table or the selection view. Overwrite this method to change the default query, which selects all rows in the database.

classmethod get_sql_field_attributes(columns)[source]

Returns a set of default field attributes based on introspection of the SQLAlchemy columns that form a field

Param :columns a list of sqlalchemy.schema.Column objects.
Returns:a dictionary with field attributes

By default this method looks at the first column that defines the field and derives a delegate and other field attributes that make sense.

is_deleted(*args, **kwargs)[source]
Returns:True if the object has been deleted from the persistent

state, False otherwise

is_persistent(*args, **kwargs)[source]
Returns:True if the object has a persisted state, False otherwise
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 none

if the object has no primary key yet or any more.
refresh(*args, **kwargs)[source]

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

validator

alias of EntityValidator

Previous topic

application_admin

Next topic

menu

This Page