CRInstance¶
-
reverse_cradmin_url
(instanceid, appname=None, roleid=None, viewname='INDEX', args=None, kwargs=None)¶ Reverse an URL within a cradmin instance.
Usage is very similar to
django.core.urlresolvers.reverse()
, but you specify the cradmin instance, appname, roleid and viewname instead of the url-nameExamples
Reverse the frontpage on an app:
myapp_index_url = reverse_cradmin_url( instanceid='siteadmin', appname='myapp', roleid=site.id)
Reverse a specific view within an app:
myapp_add_url = reverse_cradmin_url( instanceid='siteadmin', appname='myapp', roleid=site.id, viewname='add')
-
class
BaseCrAdminInstance
(request)¶ Bases:
object
Base class for a django_cradmin instance.
You define a subclass of this to setup a django_cradmin instance.
-
request
¶ HttpRequest
The current HttpRequest.
Parameters: request (HttpRequest) – The current HttpRequest. Stored in request
.-
id
= None¶ The ID of the cradmin instance. Must be unique for the Django instance/site. Must be a string. This is typically a short readable slug that describes what the cradmin instance does. You do not need to specify this except you need to communicate/link between cradmin instances.
-
roleid_regex
= '\\d+'¶ The regex for matching the role id. Defaults to
\d+
.
The renderable class for the main menu. See
get_main_menu_renderable()
.alias of
DefaultMainMenuRenderable
The renderable class for the expandable menu (the menu that is toggled by a button in the main menu). See
get_expandable_menu_renderable()
.alias of
DefaultExpandableMenuRenderable
-
header_renderable_class
¶ The header class for this cradmin instance. Must be a subclass of
django_cradmin.crheader.AbstractHeaderRenderable
.alias of
DefaultHeaderRenderable
The footer class for this cradmin instance. Must be a subclass of
django_cradmin.crfooter.AbstractFooter
.
-
roleclass
= None¶ The class defining the role for this cradmin instance. If you do not set this, the role system will not be used, which means that you will not get a value in
request.cradmin_role
.
-
rolefrontpage_appname
= None¶ The name of the app that the user should be redirected to after selecting a role. Subclasses MUST eighter specify this or override
rolefrontpage_url()
.
-
flatten_rolefrontpage_url
= False¶ If this is
True
, we do not prefix the urls of therolefrontpage_appname
with the appname. This means that it is hosted on/baseurl/<roleid>/
instead of/baseurl/<roleid>/<appname>/
.If you couple this with setting
roleclass
toNone
, the frontpage will be hosted directly on/baseurl/
.If you set this to
True
, you have to be ensure that the urls of any views within the rolefrontpage app does crash any urls in any of the other apps.
-
apps
= []¶ Apps within the instance. Iterable of
(appname, appclass)
tuples whereappname
is a slug for the app andappclass
is a subclass ofdjango_cradmin.crapp.App
. Can also be specified by overridingget_apps()
.
-
get_cradmin_theme_path
()¶ Return a path to a theme in the same format as
DJANGO_CRADMIN_THEME_PATH
, to use a custom theme for this instance.
-
get_rolequeryset
()¶ Get the roles for the authenticated user.
You get the authenticated user from
self.request.user
.
-
get_titletext_for_role
(role)¶ Get a short title briefly describing the given
role
.
-
get_descriptiontext_for_role
(role)¶ Get a longer description for the given
role
.This is never used directly on its own - it is just the default text used by
get_descriptionhtml_for_role()
. If you want HTML in your description, overrideget_descriptionhtml_for_role()
instead.
-
get_descriptionhtml_for_role
(role)¶ Get a longer description for the given
role
. This is always shown after/belowget_titletext_for_role()
.Defaults to
get_descriptiontext_for_role()
filtered to make it HTML safe and wrapped in a paragraph tag.
-
get_roleid
(role)¶ Get the ID for the given
role
.
-
get_role_from_roleid
(roleid)¶ Get the role for the given
roleid
.Defaults to looking up a
roleclass
object wherepk==roleid
.Returns: A role object or None
.
-
invalid_roleid_response
(roleid)¶ This is called whenever someone requests a role slug that does not exist (if :meth:.`get_role_from_roleid`) returns
None
.Returns: Defaults to rendering django_cradmin/invalid_roleid.django.html
.Return type: django.http.HttpResponse
-
get_role_from_rolequeryset
(role)¶ Returns the given role extracted via the
get_rolequeryset()
queryset.Raises ObjectDoesNotExist if the role is not found in the queryset.
-
missing_role_response
(role)¶ This is called whenever someone requests a role that exists but that they do not have (where meth:.get_role_from_rolequeryset raises
DoesNotExist
).Returns: Defaults to rendering django_cradmin/missing_role.django.html
Return type: django.http.HttpResponse
Get the main menu renderable instance.
Defaults to a instance of the class specified in
main_menu_renderable_class
.Returns: An AbstractMenuRenderable object. Return type: django_cradmin.crmenu.AbstractMenuRenderable
Get the expandable menu renderable instance. This is the menu that is expanded by a button which by default is in the main menu.
Defaults to a instance of the class specified in
expandable_menu_renderable_class
.Returns: An AbstractMenuRenderable object. Return type: django_cradmin.crmenu.AbstractMenuRenderable
-
get_header_renderable
(headername='default')¶ Get the header renderable for this cradmin instance.
Defaults to a instance of the class specified in
header_renderable_class
.Returns: An AbstractHeaderRenderable object. Return type: django_cradmin.crheader.AbstractHeaderRenderable See also
django_cradmin.crheader.AbstractHeaderRenderable
.
Get the footer renderable for this cradmin instance.
Defaults to a instance of the class specified in
footer_renderable_class
.Returns: An AbstractHeaderRenderable object. Return type: django_cradmin.crfooter.AbstractHeaderRenderable See also
django_cradmin.crfooter.AbstractHeaderRenderable
.
-
reverse_url
(appname, viewname, args=None, kwargs=None, roleid=None)¶ Reverse an URL within this cradmin instance.
The advantage over using
django.core.urlresolvers.reverse()
is that you do not need to hardcode the id of the cradmin instance, and that theroleid
is automatically added to args or kwargs (depending on which one you use to pass arguments to the url).Parameters:
-
appindex_url
(appname, args=None, kwargs=None, roleid=None)¶ Reverse the url of the landing page for the given app.
The landing page is the view named
django_cradmin.crapp.INDEXVIEW_NAME
.This would be the same as using
reverse_url()
withviewname=crapp.INDEXVIEW_NAME
.Parameters:
-
rolefrontpage_url
(roleid=None)¶ Returns the URL that the user should be redirected to after selecting a role.
-
get_instance_frontpage_url
()¶ Return the URL of the instance frontpage view.
-
roleselectview_url
()¶ Deprecated, use
get_instance_frontpage_url()
instead.
-
get_common_http_headers
()¶ Override this to set common HTTP headers for all views in the instance.
Returns: A mapping object mapping HTTP header name to value. Returns empty dict by default.
-
has_access
()¶ Check if the given user has access to this cradmin instance.
Defaults to
self.request.user.is_authenticated()
, but you can override this.
-
get_two_factor_auth_viewname
()¶ Get the two-factor authentication view specified in settings with
DJANGO_CRADMIN_TWO_FACTOR_AUTH_VIEWNAME
Returns: The viewname if specified in settings, else it returns None
.
-
get_foreignkeyselectview_url
(model_class)¶ Get foreign key select view URL for the given model class.
This can be used by foreign key select widgets to lookup a view for this model within the current instance.
By default this returns
None
, so you have to override this if you want to use it.Parameters: model_class – A django.db.models.Model
subclass.
-
get_manytomanyselectview_url
(model_class)¶ Get many-to-many select view URL for the given model class.
This can be used by many-to-many widgets, like
django_cradmin.widgets.modelmultichoice.ModelMultiChoiceWidget
, to lookup a view for this model within the current instance.By default this returns
None
, so you have to override this if you want to use it.Parameters: model_class – A django.db.models.Model
subclass.
-
classmethod
get_roleselect_viewclass
()¶ Get the viewclass for the roleselect view.
Returns: Defaults to django_cradmin.views.roleselect.RoleSelectView
, but any subclass ofdjango.views.View
can be used.Return type: django.views.View
-
classmethod
get_roleselect_view
()¶ Get the view for selecting role.
Instanciates the view class returned by
get_roleselect_viewclass()
, and decorates the view withdjango_cradmin.decorators.has_access_to_cradmin_instance()
.You should not need to override this, override
get_roleselect_viewclass()
instead.Note
The name of the URL for this view is
<cradmin instance id>-roleselect
, where<cradmin instance id>
isid
. You can reverse the URL of this view withget_instance_frontpage_url()
.
-
classmethod
urls
()¶ Get the url patterns for the cradmin instance.
-
add_extra_instance_variables_to_request
(request)¶ Override this method to add extra attributes to the request object for all views in this cradmin instance.
This is called by the decorator that wraps all views within the instance.
-
get_body_css_classes_list
()¶ Get the css classes for the
<body>
element that this cradmin instance should add for all views as a list.Returns an empty list by default, but you should override this to add css classes to the
<body>
element for all views within this instance.
-
get_body_css_classes_string
()¶ Get the css classes for the
<body>
element that this cradmin instance should add for all views as a string.You should not override this - override
get_body_css_classes_list()
. This method only joins the list returned by that method to make it easier to use in Django templates.
-
page_cover_bem_block
¶ Get the name of the BEM block for the page cover.
Should be overridden if you do not want the default of
adminui-page-cover
.If you need more complex behavior, you should consider: - Making your own templates that extend:
django_cradmin/standalone-base.django.html
- for all the views outside the role.django_cradmin/base.django.html
- for all the views within the role
- OR override (this affects all cradmin instances):
django_cradmin/standalone-base.django.html
django_cradmin/base.django.html
-
get_default_javascriptregistry_component_ids
()¶ Get default component IDs for all views within this cradmin instance.
Defaults to
['django_cradmin_javascript']
.
-
get_default_within_role_javascriptregistry_component_ids
()¶ Get default component IDs for all views within a cradmin_role within this cradmin instance.
Defaults to
get_default_javascriptregistry_component_ids()
.
-
-
class
NoRoleMixin
¶ Bases:
object
Mixin to make a
BaseCrAdminInstance
not require a role.Must be mixed in before
BaseCrAdminInstance
.
-
class
NoLoginMixin
¶ Bases:
object
Mixin to make a
BaseCrAdminInstance
not require login.Must be mixed in before
BaseCrAdminInstance
.-
has_access
()¶ We give any user access to this instance, including unauthenticated users.
-
-
class
NoRoleNoLoginCrAdminInstance
(request)¶ Bases:
django_cradmin.crinstance.NoRoleMixin
,django_cradmin.crinstance.NoLoginMixin
,django_cradmin.crinstance.BaseCrAdminInstance
- Shortcut for creating a
BaseCrAdminInstance
with the NoRoleMixin
andNoLoginMixin
.
Parameters: request (HttpRequest) – The current HttpRequest. Stored in request
.- Shortcut for creating a