misago.admin.views.generic
module that can offload most of burden of writing views handling items lists and forms from you.AdminBaseMixin
). This mixin will define common properties and behaviours of all admin views, like which model are admin views focused on, how to fetch its instances from database as well as where to seek templates and which message should be used when model could not be found.ListView
for items lists. Supports pagination, sorting, filtering and mass actions.FormView
and ModelFormView
for displaying and handling forms submissions.ButtonView
for handling state-changing button presses like "delete item" actions.misago.admin.views.generic.AdminBaseMixin
model
property or get_model(self)
method to get model type.root_link
property that is string with link name for "index" view for admin actions (usually link to items list).templates_dir
property being string with name of directory with admin templates used by mixin views.message_404
property on mixin to make all your views use same message when requested model could not be found.misago.admin.views.generic.ListView
template_name
- name of template file located in templates_dir
used to render this view. Defaults to list.html
items_per_page
- integer controlling number of items displayed on single page. Defaults to 0 which means no paginationfilter_form
- Form type used to construct form for filtering this list. Either this field or get_filter_form
method is required to make list filterable.ordering
- list of supported sorting methods. List of tuples. Each tuple should countain two items: name of ordering method (eg. "Usernames, descending") and order_by
argument (-username
). Defaults to none which means queryset will not be ordered. If contains only one element, queryset is ordered, but option for changing ordering method is not displayed.mass_actions
- list of dicts defining list's mass actions. Each dict should have action
key that will be used to identify method to call, name
for displayed name, icon
for icon and optional confirmation
message. Actions can define optional "is_atomic" key to control if they should be wrapped in transaction or not. This is default behaviour for mass actions.selection_label
- Label displayed on mass action button if there are items selected. 0
will be replaced with number of selected items automatically.empty_selection_label
- Label displayed on mass action button if there are no items selected.get_queryset(self)
add_item_action(cls, name, icon, link, style=None)
add_item_action(cls, action, name, prompt=None)
get_filter_form(self, request)
Form
must meet following requirements:filter_queryset(self, criteria, queryset)
method that will be passed unfiltered queryset, which it should modify using filter/exclude clauses and data from criteria
.mass_actions
list, you have to define custom method following this definition:action_ACTION(self, request, items)
ACTION
will be replaced with action dict action
value. Request is HttpRequest
instance used to call view and items
is queryset with items selected for this action. This method should return nothing or HttpResponse
. If you need to, you can raise MassActionError
with error message as its first argument to interrupt mass action handler.misago.admin.views.generic.FormView
template_name
- name of template file located in templates_dir
used to render this view. Defaults to form.html
form_class
property or get_form_class method - get_form_class
method is called with request
as its argument and is expected to return form type that will be used by view. If you need to build form type dynamically, instead of defining form_class
property, define your own get_form_class
.get_form_class(self, request)
form_class
property.get_form(self, form_class, request)
form_class
provided.handle_form(self, form, request)
HttpResponse
from this function. If nothing is returned, view returns redirect to root_link
.name="stay"
attribute defined, pressing which will cause view to redirect you to clean form instead.misago.admin.views.generic.ModelFormView
FormView
, except it's tailored at handling ModelForm
and modifying model states. All methos documented for FormView
are present in ModelformView
, but they accept one more argument named "target", containing model instance to which model form will be tied.save()
on model instance and (if defined) sets success message using value of objects message_submit
parameter.misago.admin.views.generic.ButtonView
POST
requests.button_action
method:button_action(self, request, target)
request
.HttpResponse
. If nothing is returned, view returns redirect to root_link
instead.ModelFormView
and ButtonView
are called "targeted views", because they are expected to manipulate model instances. They both inherit from TargetedView
view, implements simple API that is used for associating request with corresponding model instance:get_target_or_none(self, request, kwargs)
message_404
attribute and returns redirect to root_link
.get_target(self, kwargs)
get_target_or_none
.kwargs
len is 1, its assumed to be value of seeked model pk value. This makes function call model manager get()
method to fetch model instance from database. Otherwhise "empty" instance is created and returned instead. Eventual DoesNotExist
errors are handled by get_target_or_none
.check_permissions(self, request, target)
None
if no issues are found or string containing error message. If string is returned, its set as error messages, and view interrupts its execution by returning redirect to root_link
.is_atomic
attribute with value False
.process_context
method before rendering template to response. This method accepts two arguments:request
- HttpRequest instance received by view.context
- Dict that is going to be used to render template.render()
.site
that contains tree of links and urlpatterns
that is included in misago:admin
namespace.admin
module, just like Django admin does. If module is found, Misago checks if it defines MisagoAdminExtension
class. If such class is found, its instantiated with no arguments, and two of its methods are called:register_urlpatterns(self, urlpatterns)
misago:admin
namespace.register_navigation_nodes(self, site)
misago:admin
namespacemisago.admin.urlpatterns.URLPatterns
available as urlpatterns
argument passed to register_urlpatterns
method. This object exposes two methods as public api:namespace(path, namespace, parent=None)
path
- Path prefix for links within this namespace. For example r'^users/'
.namespace
- Non-prefixed (eg. without misago:admin
part) namespace name.parent
- Optional. Name of parent namespace (eg. users
).patterns(namespace, *urlpatterns)
users:accounts
). Every next argument is expected to be valid Django link created with url
function from django.conf.urls
module.misago:admin
prefix of namespaces is implicit. Do not prefix namespaces passed as arguments to those functions with it.misago.admin.hierarchy.AdminHierarchyBuilder
class available as site
argument passed to register_navigation_nodes
method of your MisagoAdminExtension
class. It has plenty of functions, but it's public api consists of one method:add_node(name=None, icon=None, parent=None, after=None, before=None, namespace=None, link="index")
parent
- name of parent namespace under which this action link is displayed. Should exclude the misago:admin
part.after
- link before which one this one should be displayed. Should exclude the misago:admin
, but has to include link
part, eg. users:index
.before
- link after which one this one should be displayed. Should exclude the misago:admin
, but has to include link
part, eg. users:index
.namespace
- this link namespace.link
- link name, defaults to index
.name
- page title.after
and before
arguments are exclusive. If you specify both, this will result in an error.misago:admin
. Depending on complexity of your app's admin, it can define links that are one level deep, or two levels deep.misago:admin:payments:index
:misago:admin:settings:profile-fields:index
and appear under misago:admin:settings:attachment-types:index
:add_item_action
classmethod of ListView
class that is documented above.