Package Camelot :: Package camelot :: Package admin :: Module object_admin :: Class ObjectAdmin
[frames] | no frames]

Class ObjectAdmin

source code


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:

.. 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

.. attribute:: 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"

.. attribute:: list_display

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

.. attribute:: 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 forms 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'))
  ])


.. attribute:: 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 = Field(Unicode(50))

  class Admin(EntityAdmin):
    list_display = ['organization']
    list_filter = ['organization.name']

.. image:: ../_static/filter/group_box_filter.png

.. attribute:: list_search

A list of fields that should be searched when the user enters something in
the search box in the table view.  By default only character fields are
searched.  For use with one2many, many2one or many2many fields, the same
rules as for the list_filter attribute apply

.. attribute:: confirm_delete

Indicates if the deletion of an object should be confirmed by the user, defaults
to False.  Can be set to either True, False, or the message to display when asking
confirmation of the deletion.

.. attribute:: form_size

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

.. attribute:: form_actions

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')]

.. attribute:: 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))

Other field attributes process by the admin interface are:

.. attribute:: name
The name of the field used, this defaults to the name of the attribute

.. attribute:: target
In case of relation fields, specifies the class that is at the other
end of the relation.  Defaults to the one found by introspection.

.. attribute:: admin
In case of relation fields, specifies the admin class that is to be used
to visualize the other end of the relation.  Defaults to the default admin
class of the target class.

.. attribute:: model
The QAbstractItemModel class to be used to display collections of this object,
defaults to a CollectionProxy

.. attribute:: confirm_delete
set to True if the user should get a confirmation dialog before deleting data,
defaults to False

.. attribute:: TableView
The QWidget class to be used when a table view is needed

Nested Classes
  validator
A validator class for normal python objects. By default this validator declares all objects valid. Subclass this class and overwrite it's objectValidity method to change it's behaviour.
  model
The CollectionProxy contains a limited copy of the data in the actual collection, usable for fast visualisation in a QTableView
Instance Methods
 
__init__(self, app_admin, entity)
then the default application_admin is taken :param entity: the entity class for which this admin instance is to be used
source code
 
__str__(self)
str(x)
source code
 
__repr__(self)
repr(x)
source code
 
get_name(self) source code
 
get_verbose_name(self) source code
 
get_verbose_name_plural(self) source code
 
get_verbose_identifier(*args, **kwargs)
Create an identifier for an object that is interpretable for the user, eg : the 'id' of an object. This verbose identifier can be used to generate a title for a form view of an object.
source code
 
get_entity_admin(self, entity) source code
 
get_confirm_delete(self) source code
 
get_form_actions(*args, **kwargs) source code
 
get_list_actions(*args, **kwargs) source code
 
get_subclass_tree(*args, **kwargs)
Get a tree of admin classes representing the subclasses of the class represented by this admin class
source code
 
get_related_entity_admin(self, entity)
Get an admin object for another entity. Taking into account preferences of this admin object or for those of admin object higher up the chain such as the application admin object.
source code
 
get_field_attributes(self, field_name)
Get the attributes needed to visualize the field field_name
source code
 
get_columns(*args, **kwargs)
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
source code
 
create_validator(self, model) source code
 
get_fields(*args, **kwargs) source code
 
get_all_fields_and_attributes(*args, **kwargs)
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
source code
 
get_form_display(*args, **kwargs) source code
 
create_form_view(*args, **kwargs)
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.
source code
 
set_defaults(self, object_instance, include_nullable_fields=True) source code
 
create_object_form_view(*args, **kwargs)
Create a form view for a single object, PgUp/PgDown will do nothing.
source code
 
create_new_view(*args, **kwargs)
Create a Qt widget containing a form to create a new instance of the entity related to this admin class
source code
 
delete(*args, **kwargs)
Delete an entity instance
source code
 
flush(*args, **kwargs)
Flush the pending changes of this entity instance to the backend
source code
 
add(*args, **kwargs)
Add an entity instance as a managed entity instance
source code
 
copy(*args, **kwargs)
Duplicate this entity instance
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Variables
  name = None
hash(x)
  verbose_name = None
hash(x)
  verbose_name_plural = None
hash(x)
  list_display = []
  fields = []
  form = []
  form_display = []
  list_filter = []
  list_charts = []
  list_actions = []
  list_search = []
  confirm_delete = False
  list_size = (600, 400)
  form_size = (700, 500)
  form_actions = []
  form_title_column = None
hash(x)
  field_attributes = {}
  TableView = None
hash(x)
Properties

Inherited from object: __class__

Method Details

__init__(self, app_admin, entity)
(Constructor)

source code 
then the default application_admin is taken :param entity: the entity class for which this admin instance is to be used
Parameters:
  • app_admin - the application admin object for this application, if None,
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 
str(x)
Overrides: object.__str__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 
repr(x)
Overrides: object.__repr__
(inherited documentation)

get_verbose_identifier(*args, **kwargs)

source code 
Create an identifier for an object that is interpretable for the user, eg : the 'id' of an object. This verbose identifier can be used to generate a title for a form view of an object.
Decorators:
  • @model_function

get_form_actions(*args, **kwargs)

source code 
Decorators:
  • @model_function

get_list_actions(*args, **kwargs)

source code 
Decorators:
  • @model_function

get_subclass_tree(*args, **kwargs)

source code 
Get a tree of admin classes representing the subclasses of the class represented by this admin class
Returns:
[(subclass_admin, [(subsubclass_admin, [...]),...]),...]
Decorators:
  • @model_function

get_related_entity_admin(self, entity)

source code 
Get an admin object for another entity. 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:
  • entity - the entity class for which an admin object is requested

get_field_attributes(self, field_name)

source code 

Get the attributes needed to visualize the field field_name

:param field_name : the name of 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
  • ...
Returns:
a dictionary of attributes needed to visualize the field,

get_columns(*args, **kwargs)

source code 

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

@return: [(field_name,
{'widget': widget_type,
'editable': True or False, 'blank': True or False, 'validator_list':[...], 'name':'Field name'}),

...]

Decorators:
  • @model_function

get_fields(*args, **kwargs)

source code 
Decorators:
  • @model_function

get_all_fields_and_attributes(*args, **kwargs)

source code 
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
Decorators:
  • @model_function

get_form_display(*args, **kwargs)

source code 
Decorators:
  • @model_function

create_form_view(*args, **kwargs)

source code 
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:
  • title - the title of the form view
  • model - the data model to be used to fill the form view
  • index - which row in the data model to display
  • parent - the parent widget for the form
Decorators:
  • @gui_function

create_object_form_view(*args, **kwargs)

source code 
Create a form view for a single object, PgUp/PgDown will do nothing.
Parameters:
  • title - the title of the form view
  • object_getter - a function taking no arguments, and returning the object
  • parent - the parent widget for the form
Decorators:
  • @gui_function

create_new_view(*args, **kwargs)

source code 

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

Decorators:
  • @gui_function

delete(*args, **kwargs)

source code 
Delete an entity instance
Decorators:
  • @model_function

flush(*args, **kwargs)

source code 
Flush the pending changes of this entity instance to the backend
Decorators:
  • @model_function

add(*args, **kwargs)

source code 
Add an entity instance as a managed entity instance
Decorators:
  • @model_function

copy(*args, **kwargs)

source code 
Duplicate this entity instance
Decorators:
  • @model_function