The toolbar can contain various items, some of which in turn can contain other items. These items are represented by the classes listed in cms.toolbar.items
, and created using the various APIs described below.
Do not instantiate these classes manually
These classes are described here for reference purposes only. It is strongly recommended that you do not create instances yourself, but use the methods listed here.
Classes and methods¶Common parameters (key
, verbose_name
, position
, on_close
, disabled
, active
) and options are described at the end of this document.
Bases: CMSToolbarBase
Adds AjaxItem
that sends a POST request to action
with data
, and returns it. data
should be None
or a dictionary. The CSRF token will automatically be added to the item.
If a string is provided for question
, it will be presented to the user to allow confirmation before the request is sent.
Adds a Button
to the toolbar.
Adds an (empty) ButtonList
to the toolbar and returns it.
Adds an item (which must be a subclass of BaseItem
), and returns it. This is a low-level API, and you should always use one of the built-in object-specific methods to add items in preference if possible, using this method only for custom item classes.
Adds a LinkItem
that opens url
, and returns it.
Adds a ModalButton
to the toolbar.
Similar to add_sideframe_item()
, but adds a ModalItem
that opens the url
in a modal dialog instead of the sideframe, and returns it.
Adds a SideframeButton
to the toolbar.
Adds a SideframeItem
that opens url
in the sideframe and returns it.
Returns the first ItemSearchResult
that matches the search, or None
. The search strategy is the same as in find_items()
. The return value of this method is safe to use as the position
argument of the various APIs to add items.
Returns a list of ItemSearchResult
objects matching all items of item_type
(e.g. LinkItem
).
Returns the number of items in the menu.
Will return the Menu
identified with key
, or None
.
If a Menu
with key
already exists, this method will return that menu. Otherwise it will create a menu with the key
identifier.
Populates the toolbar with the CMS items.
True
if content mode is active.
True
if the structure board editing mode is active.
True
if preview mode is active.
Property; a list of models that the toolbar watches for URL changes, so it can redirect to the new URL on saving.
Bases: SubMenu
Provides a menu in the toolbar. Use a CMSToolbar.get_or_create_menu
method to create a Menu
instance. Can be added to CMSToolbar
.
Adds AjaxItem
that sends a POST request to action
with data
, and returns it. data
should be None
or a dictionary. The CSRF token will automatically be added to the item.
If a string is provided for question
, it will be presented to the user to allow confirmation before the request is sent.
Adds a visual break in the menu, at position
, and returns it. identifier
may be used to make this item searchable.
Adds an item (which must be a subclass of BaseItem
), and returns it. This is a low-level API, and you should always use one of the built-in object-specific methods to add items in preference if possible, using this method only for custom item classes.
Adds a LinkItem
that opens url
, and returns it.
Similar to add_sideframe_item()
, but adds a ModalItem
that opens the url
in a modal dialog instead of the sideframe, and returns it.
Adds a SideframeItem
that opens url
in the sideframe and returns it.
Returns the first ItemSearchResult
that matches the search, or None
. The search strategy is the same as in find_items()
. The return value of this method is safe to use as the position
argument of the various APIs to add items.
Returns a list of ItemSearchResult
objects matching all items of item_type
(e.g. LinkItem
).
Returns the context (as dictionary) for this item.
Returns the number of items in the menu.
Renders the item and returns it as a string. By default, calls get_context()
and renders template
with the context returned.
Must be set by subclasses and point to a Django template
Bases: ToolbarAPIMixin
, BaseItem
A child of a Menu
. Use a Menu.get_or_create_menu
method to create a SubMenu
instance. Can be added to Menu
.
Adds AjaxItem
that sends a POST request to action
with data
, and returns it. data
should be None
or a dictionary. The CSRF token will automatically be added to the item.
If a string is provided for question
, it will be presented to the user to allow confirmation before the request is sent.
Adds a visual break in the menu, at position
, and returns it. identifier
may be used to make this item searchable.
Adds an item (which must be a subclass of BaseItem
), and returns it. This is a low-level API, and you should always use one of the built-in object-specific methods to add items in preference if possible, using this method only for custom item classes.
Adds a LinkItem
that opens url
, and returns it.
Similar to add_sideframe_item()
, but adds a ModalItem
that opens the url
in a modal dialog instead of the sideframe, and returns it.
Adds a SideframeItem
that opens url
in the sideframe and returns it.
Returns the first ItemSearchResult
that matches the search, or None
. The search strategy is the same as in find_items()
. The return value of this method is safe to use as the position
argument of the various APIs to add items.
Returns a list of ItemSearchResult
objects matching all items of item_type
(e.g. LinkItem
).
Returns the context (as dictionary) for this item.
Returns the number of items in the menu.
Renders the item and returns it as a string. By default, calls get_context()
and renders template
with the context returned.
Must be set by subclasses and point to a Django template
Bases: BaseItem
Sends a GET request. Use an add_link_item
method to create a LinkItem
instance. Can be added to CMSToolbar
, Menu
, SubMenu
.
Returns the context (as dictionary) for this item.
Must be set by subclasses and point to a Django template
Bases: FrameItem
Sends a GET request; loads response in a sideframe. Use an add_sideframe_item
method to create a SideframeItem
instance. Can be added to CMSToolbar
, Menu
, SubMenu
.
Must be set by subclasses and point to a Django template
Bases: FrameItem
Sends a GET request; loads response in a modal window. Use an add_modal_item
method to create a ModalItem
instance. Can be added to CMSToolbar
, Menu
, SubMenu
.
Must be set by subclasses and point to a Django template
Bases: BaseItem
Sends a POST request. Use an add_ajax_item
method to create a AjaxItem
instance. Can be added to CMSToolbar
, Menu
, SubMenu
.
Returns the context (as dictionary) for this item.
Must be set by subclasses and point to a Django template
Bases: BaseItem
A visual break in a menu. Use an add_break
method to create a Break
instance. Can be added to Menu
, SubMenu
.
Must be set by subclasses and point to a Django template
Bases: BaseItem
A visually-connected list of one or more buttons. Use an add_button_list()
method to create a ButtonList
instance. Can be added to CMSToolbar
.
Adds a Button
to the list of buttons and returns it.
Adds a ModalButton
to the button list and returns it.
Adds a SideframeButton
to the button list and returns it.
Yields all buttons in the button list
Returns the context (as dictionary) for this item.
Must be set by subclasses and point to a Django template
Bases: BaseButton
Sends a GET request. Use a CMSToolbar.add_button
or ButtonList.add_button()
method to create a Button
instance. Can be added to CMSToolbar
, ButtonList
.
Bases: ModalButton
Sends a GET request. Use a CMSToolbar.add_sideframe_button
or ButtonList.add_sideframe_button()
method to create a SideframeButton
instance. Can be added to CMSToolbar
, ButtonList
.
Bases: Button
Sends a GET request. Use a CMSToolbar.add_modal_button
or ButtonList.add_modal_button()
method to create a ModalButton
instance. Can be added to CMSToolbar
, ButtonList
.
Bases: object
All toolbar items inherit from BaseItem
. If you need to create a custom toolbar item, subclass BaseItem
.
Returns the context (as dictionary) for this item.
Renders the item and returns it as a string. By default, calls get_context()
and renders template
with the context returned.
Must be set by subclasses and point to a Django template
Provides APIs used by CMSToolbar
and Menu
.
Adds AjaxItem
that sends a POST request to action
with data
, and returns it. data
should be None
or a dictionary. The CSRF token will automatically be added to the item.
If a string is provided for question
, it will be presented to the user to allow confirmation before the request is sent.
Adds an item (which must be a subclass of BaseItem
), and returns it. This is a low-level API, and you should always use one of the built-in object-specific methods to add items in preference if possible, using this method only for custom item classes.
Adds a LinkItem
that opens url
, and returns it.
Similar to add_sideframe_item()
, but adds a ModalItem
that opens the url
in a modal dialog instead of the sideframe, and returns it.
Adds a SideframeItem
that opens url
in the sideframe and returns it.
Returns the first ItemSearchResult
that matches the search, or None
. The search strategy is the same as in find_items()
. The return value of this method is safe to use as the position
argument of the various APIs to add items.
Returns a list of ItemSearchResult
objects matching all items of item_type
(e.g. LinkItem
).
Returns the number of items in the menu.
Bases: object
Returned by the find APIs in ToolbarAPIMixin
.
An ItemSearchResult
will have two useful attributes:
The item found.
The index of the item (its position amongst the other items).
The ItemSearchResult
itself can be cast to an integer, and supports addition and subtraction of numbers. See the position
parameter for more details, and Control the position of items in the toolbar for examples.
The methods described below for creating/modifying toolbar items share a number of common parameters:
a unique identifier (typically a string)
the displayed text in the item
The position index of the new item in the list of items. May be:
None
- appends the item to the list
an integer - inserts the item at that index in the list
an object already in the list - Inserts the item into the list immediately before the object; must be a sub-class of BaseItem
, and must exist in the list
an ItemSearchResult
- inserts the item into the list immediately before the ItemSearchResult
. ItemSearchResult
may be treated as an integer.
Determines what happens after closing a frame (sideframe or modal) that has been opened by a menu item. May be:
None
- does nothing when the sideframe closes
REFRESH_PAGE
- refreshes the page when the frame closes
a URL - opens the URLS when the frame is closed.
Greys out the item and renders it inoperable.
Applies to buttons only; renders the button it its ‘activated’ state.
Either cms.constants.LEFT
or cms.constants.RIGHT
(both unique objects denoted above as <object object>). Decides to which side of the toolbar the item should be added.
Supplied to on_close
arguments to refresh the current page when the frame is closed, for example:
from cms.constants import REFRESH_PAGE self.toolbar.add_modal_item( 'Modal item', url=modal_url, on_close=REFRESH_PAGE )
The Site menu (that usually shows the project’s domain name, example.com by default). ADMIN_MENU_IDENTIFIER
allows you to get hold of this object easily using cms.toolbar.toolbar.CMSToolbar.get_menu()
.
The Language menu. LANGUAGE_MENU_IDENTIFIER
allows you to get hold of this object easily using cms.toolbar.toolbar.CMSToolbar.get_menu()
.
The Page menu. PAGE_MENU_IDENTIFIER
allows you to get hold of this object easily using cms.toolbar.toolbar.CMSToolbar.get_menu()
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4