manager: represent page hierarchy in link cell target selection (#16957)

This commit is contained in:
Frédéric Péters 2017-06-17 22:48:25 +02:00
parent a9b4b06429
commit bd6ca39f13
2 changed files with 20 additions and 4 deletions

View File

@ -18,7 +18,7 @@ import copy
from django import forms
from .models import Page, ParametersCell, MenuCell, ConfigJsonCell
from .models import Page, ParametersCell, MenuCell, LinkCell, ConfigJsonCell
from jsonfield.widgets import JSONWidget
class ParametersForm(forms.Form):
@ -53,6 +53,10 @@ class ParametersCellForm(forms.ModelForm):
}
def get_page_choices():
pages = Page.get_as_reordered_flat_hierarchy(Page.objects.all())
return [(x.id, '%s %s' % (u'\u00a0' * x.level * 2, x.title)) for x in pages]
class MenuCellForm(forms.ModelForm):
class Meta:
model = MenuCell
@ -60,9 +64,17 @@ class MenuCellForm(forms.ModelForm):
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)
self.fields['root_page'].widget = forms.Select(choices=get_page_choices())
class LinkCellForm(forms.ModelForm):
class Meta:
model = LinkCell
fields = ('title', 'url', 'link_page', 'anchor')
def __init__(self, *args, **kwargs):
super(LinkCellForm, self).__init__(*args, **kwargs)
self.fields['link_page'].widget = forms.Select(choices=get_page_choices())
class ConfigJsonForm(forms.ModelForm):

View File

@ -655,6 +655,10 @@ class LinkCell(CellBase):
context['url'] = request.build_absolute_uri(context['url'])
return context
def get_default_form_class(self):
from forms import LinkCellForm
return LinkCellForm
@register_cell_class
class FeedCell(CellBase):