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

Examples

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 FakeRoleFrontpageView(**kwargs)

Bases: django.views.generic.base.View

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

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

main_menu_renderable_class

alias of django_cradmin.crmenu.DefaultMainMenuRenderable

expandable_menu_renderable_class

alias of django_cradmin.crmenu.DefaultExpandableMenuRenderable

header_renderable_class

alias of django_cradmin.crheader.DefaultHeaderRenderable

footer_renderable_class = None

The footer class for this cradmin instance. Must be a subclass of django_cradmin.crfooter.AbstractFooter.

breadcrumb_item_list_renderable_class

alias of django_cradmin.crbreadcrumb.WrappedBreadcrumbItemList

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 the rolefrontpage_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 to None, 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 where appname is a slug for the app and appclass is a subclass of django_cradmin.crapp.App. Can also be specified by overriding get_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_titletext_for_current_role()

Shortcut for get_titletext_for_role(role=request.cradmin_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, override get_descriptionhtml_for_role() instead.

get_descriptiontext_for_current_role()

Shortcut for get_descriptiontext_for_role(role=request.cradmin_role).

get_descriptionhtml_for_role(role)

Get a longer description for the given role. This is always shown after/below get_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 where pk==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_main_menu_renderable()

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_expandable_menu_renderable()

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.

add_breadcrumb_list_items(breadcrumb_item_list)

Add items to the breadcrumb item list.

If you completely override the get_breadcrumb_item_list_renderable() method without calling super (or calling this method explicitly), this method will have no effect.

Examples:

Simple example::

    def add_breadcrumb_list_items(self, breadcrumb_item_list):
        breadcrumb_item_list.append(url='#', label='Test')
Parameters:breadcrumb_item_list (django_cradmin.crbreadcrumb.BreadcrumbItemList) – The breadcrumb item list to add items to.
get_breadcrumb_item_list_renderable()

Get the breadcrumb item list renderable common for all (or at least most) views within the cradmin instance.

You can override this, or you can set the class in breadcrumb_item_list_renderable_class.

If you just want to add some items to the breadcrumb, you can override add_breadcrumb_list_items() instead.

The value returned here is used as the default value for django_cradmin.crapp.App.get_breadcrumb_item_list_renderable() (enables apps to add breadcrumb items), which in turn is used by django_cradmin.viewhelpers.mixins.CommonCradminViewMixin.get_breadcrumb_item_list_renderable() (enables views to add breadcrumb items).

You can return None to not render a breadcrumb at all. Apps and views can still have breadcrumbs, but they will then have to initialize a django_cradmin.crbreadcrumb.BreadcrumbItemList in their get_breadcrumb_item_list_renderable-methods.

Returns:
A breadcrumb item list renderable object
or None.
Return type:django_cradmin.crbreadcrumb.BreadcrumbItemList
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 the roleid is automatically added to args or kwargs (depending on which one you use to pass arguments to the url).

Parameters:
  • appname (str) – The name of the app.
  • viewname (str) – The name of the view within the app.
  • args (list) – Args for the view
  • kwargs (dict) – Keyword args for the view.
  • roleid – The roleid. Defaults to the ID of the current role (or None if there is no current role).
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() with viewname=crapp.INDEXVIEW_NAME.

Parameters:
  • appname (str) – The name of the app.
  • args (list) – Args for the view
  • kwargs (dict) – Keyword args for the view.
  • roleid – The roleid. Defaults to the ID of the current role (or None if there is no current role).
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.

See:
get_instance_frontpage_url().
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.

See get_roleselect_view().

Returns:
Defaults to django_cradmin.views.roleselect.RoleSelectView,
but any subclass of django.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 with django_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> is id. You can reverse the URL of this view with get_instance_frontpage_url().

classmethod get_apps()

See apps. Defaults to returning apps, but can be overridden.

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 and NoLoginMixin.
Parameters:request (HttpRequest) – The current HttpRequest. Stored in request.