pagetools.menus package

Subpackages

Submodules

pagetools.menus.admin module

class pagetools.menus.admin.EntrieableAdmin(model, admin_site)[source]

Bases: ModelAdmin

form

alias of EntrieableForm

get_fields(request, obj=None)[source]

See pagetools.menus.admin.entrieable_admin_get_fields()

get_fieldsets(request, obj=None)[source]

Hook for specifying fieldsets.

is_menu_entrieable = True
property media
response_add(request, obj, *args, **kwargs)[source]

Determine the HttpResponse for the add_view stage.

response_change(request, obj, *args, **kwargs)[source]

Determine the HttpResponse for the change_view stage.

Entrieable save_related (for monkeypatching)

class pagetools.menus.admin.EntrieableForm(*args, **kwargs)[source]

Bases: ModelForm

Adds 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

class Meta[source]

Bases: object

fields = ('lang', 'title')
model

alias of Menu

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')
class Meta[source]

Bases: object

model

alias of Menu

addable_entries(obj, **_kwargs)[source]
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
render_change_form(request, context, add=False, change=False, form_url='', obj=None)[source]
save_as = True

Given the HttpRequest, the parent ModelForm instance, 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'}
model

alias of Menu

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>}
clean_children(*args, **_kwargs)[source]
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: Widget

Drag and dropable menu entries

property media
render(*_args, **_kwargs)[source]

Render the widget as an HTML string.

class pagetools.menus.admin.MenuEntryAdmin(model, admin_site)[source]

Bases: ModelAdmin

list_display = ('title', 'lang', 'enabled')
list_filter = ('lang', 'enabled')
property media
pagetools.menus.admin.make_entrieable_admin(clz)[source]

Monkeypatch an admin class

Call this with an admin class to allow the instance class to be a menu entry.

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'
ready()[source]

Override this method in subclasses to run code when Django starts.

verbose_name = 'Menu administration'

pagetools.menus.dashboard_modules module

class pagetools.menus.dashboard_modules.MenuModule(*args, **kwargs)[source]

Bases: DashboardModule

A module that displays a pagetools.menus.menu.

in dashboard: self.children.append(MenuModule(menu_title=’myMenu’, column=1,))

add_entrychildren(children, collected=None)[source]
init_with_context(context)[source]

Like for the Dashboard class, dashboard modules have a init_with_context method that is called with a django.template.RequestContext instance 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

Bases: Model

class Meta[source]

Bases: object

abstract = False
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: AbstractLink

Add 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_absolute_url()[source]
get_children()[source]
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>
classmethod show_in_menu_add()[source]
title

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

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.

get_absolute_url()[source]
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

children_list(for_admin=False)[source]
content_object

Provide a generic many-to-one relation through the content_type and object_id fields.

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>
render(selected)[source]
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_by tree option set, the node will be inserted or moved to the appropriate position to maintain ordering by the specified field.

update_cache()[source]
update_entries(orderstr)[source]

orderstr = jquery.mjs.nestedSortable.js / serialize()

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.

get_absolute_url()[source]
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.place is a ForwardOneToOneDescriptor instance.

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.children is a ReverseManyToOneDescriptor instance.

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_type and object_id fields.

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.parent is a ForwardManyToOneDescriptor instance.

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_absolute_url()[source]
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.restaurant is a ReverseOneToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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

add_child(content_object, **kwargs)[source]
class pagetools.menus.models.MenuManager(*args, **kwargs)[source]

Bases: MenuEntryManager

add_root(title, **kwargs)[source]
create(*args, **kwargs)[source]

Create a new object with the given kwargs, saving it to the database and returning the created object.

class pagetools.menus.models.SelectedEntries[source]

Bases: defaultdict

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.

get_absolute_url()[source]
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>
classmethod show_in_menu_add()[source]
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.models.delete_content(sender, **kwargs)[source]

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

pagetools.menus.utils.entrieable_reverse_name(name, app_name=None)[source]

Make menuentry available from a view

The view specified by its reverse name must not require paramenters

pagetools.menus.utils.get_menukey(obj)[source]

pagetools.menus.views module

class pagetools.menus.views.SelectedMenuentriesMixin[source]

Bases: object

Tries to find a slug from view or model add adds it to context. Used for find the selected menu-entries.

get_context_data(**kwargs)[source]
get_menukey()[source]
get_object(*args, **kwargs)[source]

Module contents