Tags¶
Views advertise themselves to introspected menus with a tags attribute.
Well-known constants are Tag instances and compare equal
to their string names. Call a constant to set a position (list-style
indexing: 0 is first, -1 is last); custom tags are plain strings, or
Tag when they need a position:
import djcrud
class Dashboard(djcrud.views.TemplateView):
tags = djcrud.tags.NAVIGATION(position=0)
class ReportList(djcrud.views.ListView):
tags = djcrud.tags.Tag("reports", position=-1)
A view that belongs to several menus can mix constants, positioned copies, and strings:
tags = [
djcrud.tags.NAVIGATION(position=0),
djcrud.tags.TOPBAR,
"reports",
]
get_tagged_views() places position >= 0 items
at the start (0, then 1, …), unpositioned items next in declaration
order, then negative positions (-2, then -1 last).
djcrud_auth uses this to keep Log in first and Log out last:
class LoginView(djcrud.views.FormView):
tags = [
djcrud.tags.TOPBAR(position=0),
djcrud.tags.NAVIGATION(position=0),
]
class LogoutView(djcrud.views.FormView):
tags = [
djcrud.tags.TOPBAR(position=-1),
djcrud.tags.NAVIGATION(position=-1),
]
Menu discovery tags used with get_tagged_views().
Well-known constants (NAVIGATION, MODEL, OBJECT,
LIST_ACTION, TOPBAR) are Tag instances. They compare equal
to their string names, so templates may still pass 'navigation'. Custom
tags are plain strings, or Tag when they need a position:
tags = djcrud.tags.NAVIGATION
tags = djcrud.tags.NAVIGATION(position=0)
tags = djcrud.tags.NAVIGATION(position=-1)
tags = "reports"
tags = djcrud.tags.Tag("reports", position=0)
Tag.position uses list-style indexing: 0 is first, 1 is
second, -1 is last, -2 is second last. Tags without a position keep
declaration order between the leading and trailing groups.
- class djcrud.tags.Tag(name, *, position=None)[source]¶
Bases:
objectA menu discovery tag with an optional list-style position.
Constants such as
NAVIGATIONareTaginstances. Call one to attach a position; the constant itself is left unchanged:tags = djcrud.tags.NAVIGATION(position=0) tags = djcrud.tags.NAVIGATION(position=-1)
Custom names use a string, or construct a
Tagwhen they need a position:tags = djcrud.tags.Tag("reports", position=0)
- Parameters:
name – Tag name. A
Tagis also accepted and contributes its name.position – Menu index for this tag.
0is first,-1is last.None(the default) leaves the view in declaration order between positively and negatively indexed items.
- djcrud.tags.NAVIGATION = Tag('navigation')¶
Sidebar / navigation menu.
- djcrud.tags.MODEL = Tag('model')¶
Model-level actions (create on the list page, …).
- djcrud.tags.OBJECT = Tag('object')¶
Per-object actions (detail, update, delete, …).
- djcrud.tags.LIST_ACTION = Tag('list_action')¶
Bulk actions on the list action bar.
- djcrud.tags.TOPBAR = Tag('topbar')¶
Site topbar (login, logout, …).