manager: order and indent options for menu cell root page option (#10936)

This commit is contained in:
Frédéric Péters 2016-05-29 23:42:18 +02:00
parent 3a6a4f91fb
commit ed73a8ef82
2 changed files with 33 additions and 1 deletions

View File

@ -1,6 +1,22 @@
# combo - content management system
# Copyright (C) 2016 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django import forms
from .models import ParametersCell
from .models import Page, ParametersCell, MenuCell
from jsonfield.widgets import JSONWidget
class ParametersForm(forms.Form):
@ -33,3 +49,15 @@ class ParametersCellForm(forms.ModelForm):
'style': 'resize: none'
})
}
class MenuCellForm(forms.ModelForm):
class Meta:
model = MenuCell
fields = ('depth', 'initial_level', 'root_page')
def __init__(self, *args, **kwargs):
super(MenuCellForm, self).__init__(*args, **kwargs)
pages = Page.get_as_reordered_flat_hierarchy(Page.objects.all())
choices = [(x.id, '%s %s' % (u'\u00a0' * x.level * 2, x.title)) for x in pages]
self.fields['root_page'].widget = forms.Select(choices=choices)

View File

@ -543,6 +543,10 @@ class MenuCell(CellBase):
class Meta:
verbose_name = _('Menu')
def get_default_form_class(self):
from .forms import MenuCellForm
return MenuCellForm
def render(self, context):
from combo.public.menu import render_menu
return render_menu(context, level=self.initial_level,