pagetools.menus package¶
Subpackages¶
- pagetools.menus.templatetags package
- pagetools.menus.tests package
- Submodules
- pagetools.menus.tests.test_admin module
- pagetools.menus.tests.test_dashboard_module module
- pagetools.menus.tests.test_forms module
- pagetools.menus.tests.test_models module
ModelTestsModelTests.test_childen()ModelTests.test_created()ModelTests.test_doubleslug()ModelTests.test_entry()ModelTests.test_entry_slugs()ModelTests.test_frobidden_create()ModelTests.test_invalid_creation()ModelTests.test_menu_already_exists()ModelTests.test_renamed_entry_slugs()ModelTests.test_rm_and_add_again()ModelTests.test_validation()
- pagetools.menus.tests.test_templatetags module
- Module contents
Submodules¶
pagetools.menus.admin module¶
- class pagetools.menus.admin.EntrieableAdmin(model, admin_site)[source]¶
Bases:
ModelAdmin- form¶
alias of
EntrieableForm
- is_menu_entrieable = True¶
- property media¶
- response_add(request, obj, *args, **kwargs)[source]¶
Determine the HttpResponse for the add_view stage.
- class pagetools.menus.admin.EntrieableForm(*args, **kwargs)[source]¶
Bases:
ModelFormAdds a field: menus to the form. Preselect all menus which contain an entry for the obj
- class Media[source]¶
Bases:
Media- js = ['/static/grappelli/tinymce/jscripts/tiny_mce/tiny_mce.js', '/static/grappelli/tinymce_setup/tinymce_setup.js', '/static/pagetools/admin/js/pre_sel_menu.js']¶
Sphinx shows this as a hardcoded string, but it is not.
- base_fields = {'menus': <django.forms.fields.Field object>}¶
- clean()[source]¶
Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.
- declared_fields = {'menus': <django.forms.fields.Field object>}¶
- property media¶
Return all media required to render the widgets on this form.
- class pagetools.menus.admin.MenuAddForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]¶
Bases:
ModelForm- base_fields = {'lang': <django.forms.fields.TypedChoiceField object>, 'title': <django.forms.fields.CharField object>}¶
- declared_fields = {}¶
- property media¶
Return all media required to render the widgets on this form.
- class pagetools.menus.admin.MenuAdmin(model, admin_site)[source]¶
Bases:
TinyMCEMixin,ModelAdmin- class Media[source]¶
Bases:
object- css = {'all': ('pagetools/admin/css/menuentries.css',)}¶
- js = ('pagetools/admin/js/jquery.min.js', 'pagetools/admin/js/jquery-ui.min.js', 'pagetools/admin/js/jquery.mjs.nestedSortable.js', 'pagetools/admin/js/menuentries.js')¶
- get_form(request, obj=None, **kwargs)[source]¶
Return a Form class for use in the admin add view. This is used by add_view and change_view.
- get_queryset(request)[source]¶
Return a QuerySet of all model instances that can be edited by the admin site. This is used by changelist_view.
- list_display = ('title', 'lang')¶
- property media¶
- save_as = True¶
- save_related(request, form, formsets, change)[source]¶
Given the
HttpRequest, the parentModelForminstance, the list of inline formsets and a boolean value based on whether the parent is being added or changed, save the related objects to the database. Note that at this point save_form() and save_model() have already been called.
- class pagetools.menus.admin.MenuChangeForm(*args, **kwargs)[source]¶
Bases:
ModelForm- class Meta[source]¶
Bases:
object- fields = ('lang', 'title', 'children', 'enabled')¶
- labels = {'enabled': 'Use Cache'}¶
- base_fields = {'children': <django.forms.fields.Field object>, 'enabled': <django.forms.fields.BooleanField object>, 'lang': <django.forms.fields.TypedChoiceField object>, 'title': <django.forms.fields.CharField object>}¶
- declared_fields = {'children': <django.forms.fields.Field object>}¶
- property media¶
Return all media required to render the widgets on this form.
- class pagetools.menus.admin.MenuChildrenWidget(*args, **kwargs)[source]¶
Bases:
WidgetDrag and dropable menu entries
- property media¶
pagetools.menus.apps module¶
- class pagetools.menus.apps.MenusConfig(app_name, app_module)[source]¶
Bases:
AppConfig- auto_children_funcs: Dict[str, Callable] = {'All pages': <function pages_auto_entries>}¶
- entrieable_auto_children: List[Any] = ['All pages']¶
- entrieable_models: List[Model] = [<class 'demo_sections.models.Article'>, <class 'demo_sections.models.Section'>, <class 'demo_sections.models.SectionList'>, <class 'pagetools.menus.models.AutoPopulated'>, <class 'pagetools.menus.models.Link'>, <class 'pagetools.menus.models.ViewLink'>, <class 'pagetools.pages.models.Page'>]¶
- entrieable_reverse_names: List[str] = []¶
- name = 'pagetools.menus'¶
- verbose_name = 'Menu administration'¶
pagetools.menus.dashboard_modules module¶
- class pagetools.menus.dashboard_modules.MenuModule(*args, **kwargs)[source]¶
Bases:
DashboardModuleA module that displays a pagetools.menus.menu.
in dashboard: self.children.append(MenuModule(menu_title=’myMenu’, column=1,))
- init_with_context(context)[source]¶
Like for the
Dashboardclass, dashboard modules have ainit_with_contextmethod that is called with adjango.template.RequestContextinstance as unique argument.This gives you enough flexibility to build complex modules, for example, let’s build a “history” dashboard module, that will list the last ten visited pages:
from grappelli.dashboard import modules class HistoryDashboardModule(modules.LinkList): title = 'History' def init_with_context(self, context): request = context['request'] # we use sessions to store the visited pages stack history = request.session.get('history', []) for item in history: self.children.append(item) # add the current page to the history history.insert(0, { 'title': context['title'], 'url': request.META['PATH_INFO'] }) if len(history) > 10: history = history[:10] request.session['history'] = history
- template = 'menus/admin/dashboard_menu_module.html'¶
pagetools.menus.models module¶
- class pagetools.menus.models.AbstractLink(*args, **kwargs)[source]¶
Bases:
Model- enabled¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- title¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class pagetools.menus.models.AutoPopulated(*args, **kwargs)[source]¶
Bases:
AbstractLinkAdd entries from a function.
- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- auto_children = True¶
- enabled¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_name_display(*, field=<django.db.models.fields.CharField: name>)¶
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- name¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- title¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class pagetools.menus.models.Link(id, title, enabled, url)[source]¶
Bases:
AbstractLink- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- enabled¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- title¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- url¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class pagetools.menus.models.Menu(id, lang, title, slug, parent, content_type, object_id, enabled, lft, rght, tree_id, level)[source]¶
Bases:
MenuEntry- exception DoesNotExist¶
Bases:
DoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- content_object¶
Provide a generic many-to-one relation through the
content_typeandobject_idfields.This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.
- full_clean(*args, **kwargs)[source]¶
Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model. Raise a ValidationError for any errors that occur.
- objects = <pagetools.menus.models.MenuManager object>¶
- save(*args, **kwargs)[source]¶
If this is a new node, sets tree fields up before it is inserted into the database, making room in the tree structure as necessary, defaulting to making the new node the last child of its parent.
It the node’s left and right edge indicators already been set, we take this as indication that the node has already been set up for insertion, so its tree fields are left untouched.
If this is an existing node and its parent has been changed, performs reparenting in the tree structure, defaulting to making the node the last child of its new parent.
In either case, if the node’s class has its
order_insertion_bytree option set, the node will be inserted or moved to the appropriate position to maintain ordering by the specified field.
- class pagetools.menus.models.MenuCache(id, menu, cache)[source]¶
Bases:
Model- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- cache¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- menu¶
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.placeis aForwardOneToOneDescriptorinstance.
- menu_id¶
- objects = <django.db.models.manager.Manager object>¶
- class pagetools.menus.models.MenuEntry(id, lang, title, slug, parent, content_type, object_id, enabled)[source]¶
Bases:
MPTTModel,LangModel- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- children¶
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- clean()[source]¶
Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
- content_object¶
Provide a generic many-to-one relation through the
content_typeandobject_idfields.This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.
- content_type¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- content_type_id¶
- enabled¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_lang_display(*, field=<django.db.models.fields.CharField: lang>)¶
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- lang¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- level¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- lft¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- menucache¶
Accessor to the related object on the reverse side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Place.restaurantis aReverseOneToOneDescriptorinstance.
- object_id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <pagetools.menus.models.MenuEntryManager object>¶
- parent¶
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- parent_id¶
- rght¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- slug¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- title¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- tree_id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class pagetools.menus.models.MenuEntryManager(*args, **kwargs)[source]¶
Bases:
TreeManager,LangManager
- class pagetools.menus.models.MenuManager(*args, **kwargs)[source]¶
Bases:
MenuEntryManager
- class pagetools.menus.models.ViewLink(id, title, enabled, name)[source]¶
Bases:
AbstractLink- exception DoesNotExist¶
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned¶
Bases:
MultipleObjectsReturned
- enabled¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- id¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- name¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>¶
- title¶
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
pagetools.menus.settings module¶
pagetools.menus.utils module¶
- pagetools.menus.utils.entrieable_auto_populated(name, callback)[source]¶
Make menuentries available from a callback
The function callback with must 1. not require arguments and 2. returns a iteratable of MenuEntry like objects