Views

class xadmin.views.BaseAdminObject[source]

The base parent class of BaseAdminView and BaseAdminPlugin , support some comm method.

get_admin_url(name, *args, **kwargs)[source]

a shortcut method to get the url by the name parameter, the url namespace of AdminSite.app_name will be appended

get_form_params(new_params=None, remove=None)[source]

add or delete a parameter to/from the current request, and generate the hidden input. This method is used to render the parameter with the form

Parameters:
  • new_params – 要新加的参数,该参数为 dict
  • remove – 要删除的参数,该参数为 list, tuple
get_model_perm(model, name)[source]

this method is used to get the permission of a specified Model, see the following example:

>>> view.get_model_perm(User, 'view')
>>> 'auth.user_view'
get_model_url(model, name, *args, **kwargs)[source]

a shortcut method, used to get the url by given model and name parameter, the urlname will be generated automatically and with the namespace of AdminSite.app_name.

get_model_view(view_class, model, *args, **kwargs)[source]

get the instance of MOdelAdminViewClass. First get the corresponding model OptionClass through AdminSite, then call get_view method.

Parameters:
  • view_class – ModelAdminViewClass 的类
  • model – 绑定的 Model 类
get_query_string(new_params=None, remove=None)[source]

generate new query string basing on the original

Parameters:
  • new_params – 要新加的参数,该参数为 dict
  • remove – 要删除的参数,该参数为 list, tuple
get_view(view_class, option_class=None, *args, **kwargs)[source]

get the instance of AdminViewClass. In fact it works by calling xadmin.sites.AdminSite.get_view_class method.

Parameters:
  • view_class – AdminViewClass 的类
  • option_class – 希望与 AdminViewClass 合并的 OptionClass
has_model_perm(model, name, user=None)[source]

check whether the current user has a certain permission of some Model, for example:

>>> view.has_model_perm(User, 'view')
>>> True
message_user(message, level='info')[source]

Send a message to the user. The default implementation posts a message using the django.contrib.messages backend.

render_response(content, response_type='json')[source]

it is a shortcut method to create an instance of HttpResponse. If the response_type is set as ‘json’, the result will be convert to json format and then output.

static(path)[source]

the shortcut method of xadmin.util.static, used to return the url of the static file.

template_response(template, context)[source]

a shortcut of creating TemplateResponse instance

class xadmin.views.BaseAdminPlugin(admin_view)[source]

It is the base class of all Plugin classes, inherited from BaseAdminObject class. Please see xadmin.sites.AdminSite.register_plugin method to check the Plugin registration and usage. Refer to the method fliter_hook about the Plugin principle.

filter_hook(func)

the methods of AdminView with this decorator can be extended by Plugin classes, and will be executed as the following procedure:

  1. get the plugins property from the instance then retrieve the plugin with the same method name

  2. order by the ‘priority’ of the plugins

  3. execute the plugin methods in order and follow the rules:

    • if no parameters are given to the plugin method, the return of AdminView method is not null and throws exception.

    • If the first parameter passed to the plugin method is ‘__’ then this parameter is the AdminView method. The plugin method will be executed through calling ‘__()’ and before the AdminView method.

      def get_context(self, __):
          c = {'key': 'value'}
          c.update(__())
          return c
      
    • If the first parameter of the plugin method is not ‘__’, the AdminView method will be executed and it’s return value will be passed as the first parameter.

  4. In final the plugins are executed sequentially and the results are returned in order.

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

This is the initialization method of plugin class, which is the first invoked method after creating the plugin. Through this method, the plugin required attributes are initialized and check whether the current request needs to load this plugin instance. For example the implementation of Ajax plugin.

def init_request(self, *args, **kwargs):
    return bool(self.request.is_ajax() or self.request.REQUEST.get('_ajax'))

if the return value is ‘False’, the corresponding AdminView instance will not load the pulgin

class xadmin.views.BaseAdminView(request, *args, **kwargs)[source]

This is the base class of all AdminView classes which is inherited from BaseAdminObject and django.views.generic.View.

the core class of Xadmin framework, all AdminView classes need to inherit from this class. The most obvious difference between Xadmin and Django Admin is that every request will cause an instance of AdminView class be created which also is Class-based View implemented in Django 1.3, see Django official document Class-based generic views <https://docs.djangoproject.com/en/1.4/topics/class-based-views/>

The Class-based view has many advantages. First, every time a request coming, an new instance with variables related to the current request is created to response, this is useful when extend the class or override the super class method.

Second, Class-based View is easy to implement a plugin function and dynamically loading plugin because every instance of AdminView need to load specific plugins according to its circumstance, see BaseAdminPlugin class about the details.

It is very simple to implement a customized AdminView class, for instance:

from xadmin.sites import site
from xadmin.views import BaseAdminView

class MyAdminView(BaseAdminView):

    def get(self, request, *args, **kwargs):
        pass

site.register_view(r'^me_test/$', MyAdminView, name='my_test')

By this you can access this view by me_test/. Meanwhile Xadmin offers some common AdminView classes and they are:

  • CommAdminView class, which is the basic view of general user interface, provides the data required by Xadmin general user interface (such as menu).

  • ModelAdminView class, one of the core classes, provide the Model-based AdminView classes.

classmethod as_view()[source]

this overrides View.as_view method and integrates the View.dispatch method inside. Some initialization work is moved and completed by the initi method of AdminView class, please see ‘BaseAdminView.init_request’

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

filter_hook

return the required context object to display the requested page.

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

filter_hook

retrieve the required Media object to generate css and js files.

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

this is the plugin initialization method of AdminView class, which is called after BaseAdminView.init_request method execution. All plugins from the base_plugins attribute are instantiated in order and loaded according to the result of BaseAdminPlugin.init_request method. If the plugin is required it will be kept by the plugins attribute.

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

it is designated to be overridden by the derived class to do the initialization, and has no real effects on the initialization of BaseAdminView class.

class xadmin.views.CommAdminView(request, *args, **kwargs)[source]

this is a generic AdminView class extending BaseAdminView. The global settings of Xadmin website can be done by this class, which are

  • Title of website

  • Global icon for model

  • Menu of website

** View property **

site_title = None

Title of website

网站的下角标文字

global_models_icon = {}

Global icon for model:

globe_models_icon = {User: 'user-icon'}
base_template = 'xadmin/base_site.html'

View模板继承的基础模板

default_model_icon = None
get_breadcrumb(*args, **kwargs)[source]

filter_hook

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

filter_hook

Context params:

site_title: assign a string value to this attribute to set the title of the site, the default value is “Django Xadmin”

nav_menu: it keeps the system menu items after processing the user’s permission. This attribute will be cached in SESSION if under non DEBUG mode.

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

filter_hook

It is used to get the icon of Model class, which actually is css class. The generated HTML is shown as the following:

<i class="icon-model icon-{{model_icon}}"></i>

This example applies the stand format of Bootstrap icon. For now Xadmin uses Font Icon (Font-Awesome), you can customized your icons, you can refer to http://fortawesome.github.com/Font-Awesome/#contribute to create a customized font and icon

Note

The Model icons are used by the following places, and also you can use within your customized pages.

  • system menu

  • in the title of list page

  • in the title of creating, updating and deleting page

FAQ: if define Model icons

A global Model icon can be set by the property ‘globe_models_icon’ in the OptionClass of CommAdminView class. Or set the property ‘model_icon’ in the OptionClass of Models.

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

filter_hook

this method returns the website menu. If get_site_menu method return not none, the return value will be token as the first part the menu, and Xadmin appends the Model listing menu items as the rest part the menu. If None is returned by get_site_menu method, Xadmin will automatically generate two levels of menu according to App and Model.

Return type:格式见 get_site_menu() 返回格式
get_site_menu()[source]

FAQ: how to customized system menu

a method for the derived class to override and implement customized website menu. It can be overwritten via child class or OptionClass.

({
    "title": "菜单标题", "perm": "权限标示", 
    "icon": "图标的 css class", "url": "菜单url", 
    "menus": [...]    # 子菜单项
})

the values of ‘perm’ and ‘url’ in the menu can be provide by the shortcut methods BaseAdminObject.get_model_perm and BaseAdminObject.get_model_url if base on Model. For example:

class AdminSettings(object):

    def get_site_menu(self):
        return (
            {'title': '内容管理', 'perm': self.get_model_perm(Article, 'change'), 'menus':(
                {'title': '游戏资料', 'icon': 'info-sign', 'url': self.get_model_url(Article, 'changelist') + '?_rel_categories__id__exact=2'},
                {'title': '网站文章', 'icon': 'file', 'url': self.get_model_url(Article, 'changelist') + '?_rel_categories__id__exact=1'},
            )},
            {'title': '分类管理', 'perm': self.get_model_perm(Category, 'change'), 'menus':(
                {'title': '主要分类', 'url': self.get_model_url(Category, 'changelist') + '?_p_parent__isnull=True'},
                {'title': '游戏资料', 'url': self.get_model_url(Category, 'changelist') + '?_rel_parent__id__exact=2'},
            )},
        )

site.register(CommAdminView, AdminSettings)
class xadmin.views.ModelAdminView(request, *args, **kwargs)[source]

this is a Model-based AdminView class. The AdminSite instance will automatically create a url to the class extending ModelAdminView for each registered Model class. The registration is completed by calling the register_modelview method of AdminSite instance. To see the details please refer to the method API document, or see the following example:

from xadmin.views import ModelAdminView

class TestModelAdminView(ModelAdminView):
    
    def get(self, request, obj_id):
        pass

site.register_modelview(r'^(.+)/test/$', TestModelAdminView, name='%s_%s_test')

the user can access this view by path /%(app_label)s/%(module_name)s/123/test after it is registered.

Option properties

fields = None

list or tuple type, it defines the fields will be displayed

exclude = None

list or tuple type, it defines the fields will be excluded from the editing page

ordering = None

it is a dict type, the default order for the reterieved Model queryset.

model = None

a bounded Model class, which is automatically assigned to OptionClass when register the Model class, see the regsiter method of AdminSite class

instance property

opts

Model._meta

app_label

即 Model._meta.app_label

module_name

Model._meta.module_name

model_info

即 (self.app_label, self.module_name)

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

filter_hook

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

filter_hook

Context params:

opts: the _meta attribute of Model class

app_label: the app_label attribute of Model class

module_name: the module_name attribute of Model class

verbose_name: the verbose_name of Model class

get_model_perms()[source]

return a dict containing all permissions, which has key values: add, view, change, delete with boolean values indicating whether the current user has the corresponding permission.

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

filter_hook

get the unique instance of Model through object_id. If the Model instance does not exist return None.

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

filter_hook

get_ordering()[source]

return the ordering of the Model list. The default return value is ModelAdminView.ordering, which can be overridden by the subclass.

get_template_list(template_name)[source]

return a list of templates according to template_name. The created page is one of these templates and you can easily override this method to get the customized template. The list format is shown as the following:

"xadmin/%s/%s/%s" % (opts.app_label, opts.object_name.lower(), template_name),
"xadmin/%s/%s" % (opts.app_label, template_name),
"xadmin/%s" % template_name,
has_add_permission()[source]

return whether the current user has addition right

has_change_permission(obj=None)[source]

return whether the current user has the updating right

has_delete_permission(obj=None)[source]

return whether the current user has the deletion right

has_view_permission(obj=None)[source]

return whether the current user has the view right

Note

in the current version, if a user has the updating right then also own the view right. This default can be changed with your customized subclass

model_admin_url(name, *args, **kwargs)[source]

this method function is equivalent BaseAdminObject.get_admin_url, expect for using its model attribute inherited from ModelAdminView class, therefore the model parameter is not required.

queryset()[source]

return the Model queryset. This can be used to query the model data

class xadmin.views.ListAdminView(request, *args, **kwargs)[source]

this is the data list AdminView class, which implements the data sorting and paging functions.

Option properties

list_display = ('__str__',)

the default field list to display

the list of links to display data in details which are editable

the setting of whether load the related data in advance, using select_related

list_per_page = 50

the number of data records displayed in each page.

list_max_show_all = 200

the maximum number of data records displayed in each page.

list_exclude = ()

the list of fields excluded from displaying, this list contains the fields that are not be displayed in the page.

search_fields = ()

search data with fields keywords listed by this attribute.

ordering = None

the default data order

object_list_template = None

define the template used to display data

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

filter_hook

display the Model list

get_check_field_url(f)[source]

return the url of every item in the ‘show list’ menu item

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

filter_hook

Context params:

‘model_fields’ defines the list information that can be displayed, which is used for ‘select list to show’ function

result_headers contains the head information of list table, is the instance of ResultHeader class

‘results’: the cells in each row of the table, which is the instance object of ResultItem class

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

filter_hook

obtain the columns to display. If the request contains ‘_cols’ parameter then use ‘_cols’, otherwise use ‘list_display’ attribute

Note

this method only save the value of list_display with the ‘base_list_display’ attribute. If some plugin (e.g. Action plugin) add extra values to this method returned value, the number of displayed column increases but the added data is not effective to other plugins (e.g. the export plugin). This keeps the original data of displayed column separated, which can be retrieved from ‘base_list_display’.

filter_hook

return a group of column displayed as links to editing page (if the current user has editing permission) or to view page. In default, the attribute of ‘list_display_links’ is used for this function if it is not None, or make the first item in list_display attribute as a link.

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

filter_hook

obtain the Model’s queryset that is sorted and filtered, and other plugins can modify this queryset.

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

filter_hook

return the Media object, and ListAdminView employs ‘xadmin.page.list.js’ javascript file

get_model_method_fields()[source]

make and display a column with the returned value from methods in OptionClass which has True for is_column attribute. Those methods are wrapped by FakeMethodField and the displayed values are turned to fake database fields.

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

filter_hook

Returns the list of ordering fields for the change list. First we check the get_ordering() method in model admin, then we check the object’s default ordering. Then, any manually-specified ordering from the query string overrides anything. Finally, a deterministic order is guaranteed by ensuring the primary key is used as the last ordering field.

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

filter_hook

obtain the field names need to be sorted from the ‘field_name’ parameter which can be a standard database field or callable or one Model attribute of OptionClass. In this case, the ‘admin_order_field’ attribute is taken for sorting. If no value of ‘admin_order_field’ is given return None.

class UserAdmin(object):
    def my_field(self, obj):
        return obj.name.lower()
    my_field.admin_order_field = 'name'
get_ordering_field_columns(*args, **kwargs)[source]

filter_hook

Returns a SortedDict of ordering field column numbers and asc/desc

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

filter_hook

return the html code of pagination component, bootstrap is applied in default.

Parameters:i – 页码, 可能是 DOT
get_paginator(*args, **kwargs)[source]

filter_hook

use paginator_class to instantiate a paginator object and return it.

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

filter_hook

in default this method has no return value after executing ‘get_context’ method, but plugins can override it and return specified HttpResponse object.

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

filter_hook

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

initialize the request and check whether the current user has view permission, then do initializing the variables required by generating data for the list view.

make_result_list()[source]

make data and pagination for the list view, the displayed data is assigned to ‘result_list’ arrtibute. Plugins can process the generated data after this method.

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

filter_hook

process the POST request of Model list view and return the same result with GET request in default. Plugins can override ‘post_response’ method to change the return value for POST request.

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

filter_hook

this method can be used to process the response to POST request, it returns None in default. Plugins can override it and return specified HttpResponse.

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

filter_hook

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

filter_hook

return a column header information of the table in list view, which is an instance of ResultHeader class.

Parameters:
  • field_name – 列的名字
  • rowResultHeader 实例
result_headers(*args, **kwargs)[source]

filter_hook

return the header information of the table in list view, which is an instance of ‘ResultRow’ class. The column information is kept by ‘cells’ attribute of ‘ResultRow’ class

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

filter_hook

return a field value of a Model object record, which is a ‘ResultItem’ instance.

Parameters:
  • obj – Model 对象
  • field_name – 列的名字
  • rowResultHeader 实例
result_row(*args, **kwargs)[source]

filter_hook

return a row with model instance data to display, which is actually instance of ‘ResultRow’ class. The ‘cells’ attribute of ‘ResultRow’ contains the detail information for all columns.

Parameters:obj – Model 对象
results(*args, **kwargs)[source]

filter_hook

return entire data to display with list view, and an object of ‘ResultRow’ class contains all rows information.

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

filter_hook

return a link to the details of the displayed data. If the current user has the updating permission, the link will redirect to updating page, otherwise to the details page.

Parameters:result – Model 对象
class xadmin.views.ModelFormAdminView(request, *args, **kwargs)[source]

this AdminView class is a base class used to create or update data basing on a model form. It provides functions such as displaying and updating data through form. Class ‘CreateAdminView’ and ‘UpdateAdminView’ inherit from this class.

Option properties

form = <class 'django.forms.models.ModelForm'>

refers to the Form class used to generate form object basing on Model class, it is django.forms.ModelForm by default.

formfield_overrides = {}

specify a Form Field class to override the Model Field, for example:

class AtricleAdmin(object):
    formfield_overrides = {
        models.FileField:{'widget': mywidgets.XFileWidget},
    }

by this, mywidgets.XFileWidget is used to display all FileField defined in the model class.

readonly_fields = ()

specifies read-only fields which can not be edited.

style_fields = {}

specifies the Style for a given Field. Style can make different display effects for one field type. For instance, radio button has common and inline Style values. Xadmin will implement more Field Style for form plugins. You can apply a certain style by setting a defined Style value.

class AtricleAdmin(object):
    style_fields = {"content": "rich-textarea"}

rich-textarea is Style value provided by some plugin class, thus the ‘content’ will displayed by this plugin style.

relfield_style = None

if the model is referred by some other models, this referred model will apply the value of relfield_style as the Field Style to display in other models.

save_as = False

whether display ‘Save as’ button.

save_on_top = False

whether display a group of button on the top of the page.

add_form_template = None

the template page for adding model.

change_form_template = None

the template page for updating model.

form_layout = None

this is the object of form Layout, which is also a standard object of Crispy Form Layout. Using Layout can easily define the structure of the page. Please refer to Crispy Form document http://django-crispy-forms.readthedocs.org/en/latest/layouts.html to see details. Here is an example of form_layout:

from xadmin.layout import Main, Side, Fieldset, Row, AppendedText

class AtricleAdmin(object):
    form_layout = (
        Main(
            Fieldset('Comm data',
                'title', 'category'
            ),
            Inline(Log),
            Fieldset('Details',
                'short_title',
                Row(AppendedText('file_size', 'MB'), 'author'),
                'content'
            ),
        ),
        Side(
            Fieldset('Status',
                'status',
            ),
        )
    )

please check the document of ‘form_layout’ about the elements information of Layout.

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

filter_hook

a callback method during the process of generating form instance, returns instance of Form Field.

Parameters:db_field – Model 的 DB Field
get(*args, **kwargs)[source]

filter_hook

display the form, the detail procedure is shown as the following:

  1. call ‘perpare_form’ method

  2. call ‘instance_forms’ method

    2.1 call ‘get_form_datas’ method

  3. call ‘setup_forms’ method

  4. call ‘get_response’ method

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

filter_hook

Context Params:

‘form’: a Form object

‘original’: the original data object for updating

show_delete: whether display the deleted items

‘add’: whether this is adding data

‘change’: whether this is updating data

‘errors’: the form error messages

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

filter_hook

get the list of form error messges

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

filter_hook

return a dict containing the Form Field attributes according to the model Field attributes

Parameters:db_field – Model 的 DB Field
get_field_style(*args, **kwargs)[source]

filter_hook

return the Form Field attributes according to the Field Style. This method can be filtered out by plugins and provide different Styles.

Parameters:
  • db_field – Model 的 DB Field
  • style – 配置的 Field Style,该值来自于属性 style_fields
get_form_helper(*args, **kwargs)[source]

filter_hook

obtain the instance of FormHelper required by the Crispy Form. The details can be found with Crisp Form document

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

filter_hook

return the Form Layout object. If the form_layout attribute is set then return it, otherwise return the automatically generated Form Layout object. More Form Layout information can see Crispy Form document. Setting customized Form Layout object is more flexible way to render every element of form.

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

filter_hook

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

filter_hook

return ModelForm object which is used to display the form.

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

filter_hook

return the read-only fields, the derived classes or OPtionClass can override this method.

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

filter_hook

instantiate the Form object with the return value of ‘get_form_datas’ method, and then keep this Form object with ‘form_obj’ attribute.

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

filter_hook

save form data. The detail procedure is executed as the following:

  1. call ‘perpare_form’ method

  2. call ‘instance_forms’ method

    2.1 call ‘get_form_datas’ method

  3. call ‘setup_forms’ method

  4. ‘valid_forms’ method

    4.1 call ‘save_forms’ method

    4.2 call ‘save_models’ method

    4.3 call ‘save_related’ method

    4.4 call ‘post_response’ method

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

filter_hook

prepare the Form class through call method ‘get_model_form’, then assign to ‘model_form’ attribute

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

filter_hook

save the form object to ‘new_obj’ attribute, note that this model object has not been saved to database nor pk is generated.

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

filter_hook

save the data to the corresponding table in the database.

filter_hook

save the related data.

setup_forms()[source]

set up a Form class

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

filter_hook

validate the Form data.

class xadmin.views.CreateAdminView(request, *args, **kwargs)[source]

this Model AdminView is used to create a model object which inherits from ModelFormAdminView class.

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

filter_hook

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

filter_hook

Context Params:

‘title’: the form title

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

filter_hook

get the form initial data from Requet

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

filter_hook

返回显示表单页面的 Response ,子类或是 OptionClass 可以复写该方法

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

filter_hook

this method returns a HttpResponse object or HttpRedirectResponse object after successfully saving the model object to database.

class xadmin.views.UpdateAdminView(request, *args, **kwargs)[source]

this Model AdminView class is for updating model object, which inherits from ModelFormAdminView class.

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

filter_hook

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

filter_hook

Context Params:

‘title’: the form title

‘object_id’: the id of updated object

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

filter_hook

obtain the Form object data

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

filter_hook

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

filter_hook

return HttpResponse or HttpRedirectResponse object after the model object is successfully updated.

class xadmin.views.DeleteAdminView(request, *args, **kwargs)[source]

the Model AdminView used to delete model object.

Option attributes

delete_confirmation_template = None

the template page for confirming deletion

instance property

obj

the model object that will be deleted

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

filter_hook

delete ‘self.obj’

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

filter_hook

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

filter_hook

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

filter_hook

Context Params:

title : 确认删除的标题,如果您没有权限删除的话,会提示无法删除

‘object’: the object that will be deleted

deleted_objects : 关联被删除的所有数据对象

‘perms_lacking’: the missing permissions

‘protected’: the protected data, the data can not be deleted.

init_request(object_id, *args, **kwargs)[source]

do initialization. Retrieve the object that will be deleted by the keyword of ‘object_id’ and check whether the current user has the required permission.

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

filter_hook

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

filter_hook

the process after successfully deleting. First message the user about the result then redirect to corresponding view according to the user’s permission. If the user has view permission then redirected page is view page, otherwise go to the index page.

class xadmin.views.DetailAdminView(request, *args, **kwargs)[source]

the mode AdminView class that shows the details of model. The view page is only for view data. The view layout is the same with class:`xadmin.views.edit.ModelFormAdminView

Option attributes

detail_layout = None

the Layout object of the detail page is a standard Crispy Form Layout object. The advantage of using Layout is that page layout can be well organized.

detail_show_all = True

whether display all fields, and the default value is ‘True’. If this is set as ‘True’, those fields not set with the layout object will be displayed, otherwise hide them.

detail_template = None

the template of the detail view page.

instance property

obj

the model object that will be deleted

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

filter_hook

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

filter_hook

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

filter_hook

Context params:

‘form’: the form object used to display model object data.

‘object’: the Model object that will be dispalyed

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

filter_hook

return the instance of ResultField class which contains the field content.

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

filter_hook

obtain the instance of FormHelper required by the Crispy Form. The details can be found with Crisp Form document

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

filter_hook

return the Form Layout object, if the attribute ‘detail_layout’ is set then return it, or return the automatically generated Form Layout object. More Form Layout information can see Crispy Form document. Setting customized Form Layout object is more flexible way to render every element of form.

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

filter_hook

return the Media object of the current view instance, which contains information of ‘form.css’ file.

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

filter_hook

return ModelForm object which is used to display the form.

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

filter_hook

return a HttpResponse object, plugins can override this method to return specified HttpResponse object.

init_request(object_id, *args, **kwargs)[source]

do initialization. Display the model object data according to passed parameter ‘object_id’. The current user’s permission will be checked, if no view right the view page will be not shown.

xadmin.views.filter_hook(func)[source]

the methods of AdminView with this decorator can be extended by Plugin classes, and will be executed as the following procedure:

  1. get the plugins property from the instance then retrieve the plugin with the same method name

  2. order by the ‘priority’ of the plugins

  3. execute the plugin methods in order and follow the rules:

    • if no parameters are given to the plugin method, the return of AdminView method is not null and throws exception.

    • If the first parameter passed to the plugin method is ‘__’ then this parameter is the AdminView method. The plugin method will be executed through calling ‘__()’ and before the AdminView method.

      def get_context(self, __):
          c = {'key': 'value'}
          c.update(__())
          return c
      
    • If the first parameter of the plugin method is not ‘__’, the AdminView method will be executed and it’s return value will be passed as the first parameter.

  4. In final the plugins are executed sequentially and the results are returned in order.

xadmin.views.csrf_protect_m(func)

This decorator adds CSRF protection in exactly the same way as CsrfViewMiddleware, but it can be used on a per view basis. Using both, or using the decorator multiple times, is harmless and efficient.