placeholder: optional placeholders display and edition (#37135)
This commit is contained in:
parent
cfdaeaf94d
commit
e40a3e8b67
|
@ -84,11 +84,12 @@ def element_is_visible(element, user=None):
|
|||
|
||||
|
||||
class Placeholder(object):
|
||||
def __init__(self, key, name=None, acquired=False, render=True, cell=None,
|
||||
force_synchronous=False):
|
||||
def __init__(self, key, name=None, acquired=False, optional=False,
|
||||
render=True, cell=None, force_synchronous=False):
|
||||
self.key = key
|
||||
self.name = name
|
||||
self.acquired = acquired
|
||||
self.optional = optional
|
||||
self.render = render
|
||||
self.cell = cell
|
||||
self.force_synchronous = force_synchronous
|
||||
|
|
|
@ -106,6 +106,20 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if optional_placeholders %}
|
||||
<div class="page-options">
|
||||
<h3>{% trans 'Optional sections' %}</h3>
|
||||
<ul>
|
||||
{% for placeholder in optional_placeholders %}
|
||||
<li>
|
||||
{{ placeholder.name }} ({% if placeholder.is_empty %}{% trans "empty" %}{% else %}{% trans "like parent" %}{% endif %})
|
||||
(<a href="{% url 'combo-manager-page-view' pk=object.id %}?include-section={{ placeholder.key }}">{% trans 'change' %}</a>)
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</aside>
|
||||
{% endblock %} {# sidebar #}
|
||||
|
||||
|
|
|
@ -264,6 +264,7 @@ class PageView(DetailView):
|
|||
cells = CellBase.get_cells(page_id=self.object.id)
|
||||
template = self.object.template_name
|
||||
placeholders = []
|
||||
optional_placeholders = []
|
||||
combo_template = settings.COMBO_PUBLIC_TEMPLATES.get(template)
|
||||
|
||||
for placeholder in self.object.get_placeholders(request=self.request, traverse_cells=True):
|
||||
|
@ -272,9 +273,39 @@ class PageView(DetailView):
|
|||
'name': placeholder.get_name(),
|
||||
}
|
||||
placeholder_dict['cells'] = [x for x in cells if x.placeholder == placeholder.key]
|
||||
|
||||
# not optional placeholder
|
||||
if not placeholder.optional:
|
||||
placeholders.append(placeholder_dict)
|
||||
continue
|
||||
|
||||
# optional placeholder, but requested for edition
|
||||
if self.request.GET.get('include-section') == placeholder.key:
|
||||
placeholders.append(placeholder_dict)
|
||||
continue
|
||||
|
||||
# empty optional placeholder: in optional sections
|
||||
if not placeholder_dict['cells']:
|
||||
placeholder_dict['is_empty'] = True
|
||||
optional_placeholders.append(placeholder_dict)
|
||||
continue
|
||||
|
||||
# optional placeholder with at least 2 cells: in page edition
|
||||
if len(placeholder_dict['cells']) > 1:
|
||||
placeholders.append(placeholder_dict)
|
||||
continue
|
||||
|
||||
# optional placeholder with only one ParentContentCell: in optional sections
|
||||
if isinstance(placeholder_dict['cells'][0], ParentContentCell):
|
||||
placeholder_dict['is_empty'] = False
|
||||
optional_placeholders.append(placeholder_dict)
|
||||
continue
|
||||
|
||||
# other cases: in page edition
|
||||
placeholders.append(placeholder_dict)
|
||||
|
||||
context['placeholders'] = placeholders
|
||||
context['optional_placeholders'] = optional_placeholders
|
||||
|
||||
context.update({
|
||||
'previous_page': self.object.get_previous_page(check_visibility=False),
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<div id="footer">
|
||||
{% block footer %}
|
||||
{% trans "Footer" as name %}
|
||||
{% placeholder "footer" name=name acquired=True %}
|
||||
{% placeholder "footer" name=name acquired=True optional=True %}
|
||||
{% skeleton_extra_placeholder footer %}
|
||||
<span style="display: none">{% now "Y-m-d H:i:s" %}</span> {# generation time #}
|
||||
{% end_skeleton_extra_placeholder %}
|
||||
|
|
|
@ -534,9 +534,9 @@ def test_configure_invoices_cell(app, admin_user, payment_backend):
|
|||
app = login(app)
|
||||
resp = app.get('/manage/pages/%s/' % page.id, status=200)
|
||||
|
||||
# 2 occurences of tipi payment form should be present, and no other cells
|
||||
assert resp.text.count('lingo') == 2
|
||||
assert resp.text.count('lingo_tipipaymentformcell') == 2
|
||||
# 1 occurence of tipi payment form should be present, and no other cells
|
||||
assert resp.text.count('lingo') == 1
|
||||
assert resp.text.count('lingo_tipipaymentformcell') == 1
|
||||
|
||||
regie = Regie()
|
||||
regie.label = 'Test'
|
||||
|
|
|
@ -21,7 +21,7 @@ from webtest import TestApp
|
|||
from webtest import Upload
|
||||
|
||||
from combo.wsgi import application
|
||||
from combo.data.models import Page, CellBase, TextCell, LinkCell, ConfigJsonCell, JsonCell, PageSnapshot, LinkListCell
|
||||
from combo.data.models import Page, CellBase, TextCell, LinkCell, ConfigJsonCell, JsonCell, PageSnapshot, LinkListCell, ParentContentCell
|
||||
from combo.apps.assets.models import Asset
|
||||
from combo.apps.family.models import FamilyInfosCell
|
||||
from combo.apps.search.models import SearchCell
|
||||
|
@ -139,6 +139,57 @@ def test_edit_page(app, admin_user):
|
|||
resp = resp.follow()
|
||||
assert Page.objects.all()[0].exclude_from_navigation is True
|
||||
|
||||
|
||||
def test_edit_page_optional_placeholder(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
page = Page.objects.create(title='One', slug='one', template_name='standard')
|
||||
app = login(app)
|
||||
|
||||
# empty placeholder footer
|
||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content']
|
||||
assert len(resp.context['optional_placeholders']) == 1
|
||||
assert resp.context['optional_placeholders'][0]['key'] == 'footer'
|
||||
assert resp.context['optional_placeholders'][0]['name'] == 'Footer'
|
||||
assert resp.context['optional_placeholders'][0]['is_empty'] is True
|
||||
assert '/manage/pages/%s/?include-section=footer' % page.pk in resp.text
|
||||
assert 'Footer (empty)' in resp.text
|
||||
assert '<div class="placeholder" data-placeholder-key="footer">' not in resp.text
|
||||
|
||||
# add a ParentContentCell
|
||||
like_parent_cell = ParentContentCell.objects.create(page=page, placeholder='footer', order=0)
|
||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content']
|
||||
assert len(resp.context['optional_placeholders']) == 1
|
||||
assert resp.context['optional_placeholders'][0]['key'] == 'footer'
|
||||
assert resp.context['optional_placeholders'][0]['name'] == 'Footer'
|
||||
assert resp.context['optional_placeholders'][0]['is_empty'] is False
|
||||
assert '/manage/pages/%s/?include-section=footer' % page.pk in resp.text
|
||||
assert 'Footer (like parent)' in resp.text
|
||||
assert '<div class="placeholder" data-placeholder-key="footer">' not in resp.text
|
||||
|
||||
# click on the edit link
|
||||
resp = resp.click(href='.*?include-section=footer')
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', 'footer']
|
||||
assert len(resp.context['optional_placeholders']) == 0
|
||||
assert '<div class="placeholder" data-placeholder-key="footer">' in resp.text
|
||||
assert '<option data-add-url="/manage/pages/%s/add-cell-to-footer/data_textcell/default/"' % page.pk in resp.text
|
||||
|
||||
# add a cell (so there is 2 cells)
|
||||
resp = app.get('/manage/pages/%s/add-cell-to-footer/data_textcell/default/' % page.pk)
|
||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', 'footer']
|
||||
assert len(resp.context['optional_placeholders']) == 0
|
||||
assert '<div class="placeholder" data-placeholder-key="footer">' in resp.text
|
||||
|
||||
# remove parent content cell
|
||||
like_parent_cell.delete()
|
||||
resp = app.get('/manage/pages/%s/' % page.pk)
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', 'footer']
|
||||
assert len(resp.context['optional_placeholders']) == 0
|
||||
assert '<div class="placeholder" data-placeholder-key="footer">' in resp.text
|
||||
|
||||
|
||||
def test_edit_page_unknown_template(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
page = Page(title='One', slug='one', template_name='broken')
|
||||
|
@ -1185,15 +1236,15 @@ def test_page_cell_placeholder(app, admin_user):
|
|||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', 'footer']
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content']
|
||||
|
||||
# check a placeholder within a cell is included
|
||||
cell.template_string = '{% placeholder "foobar" name="Foobar" %}'
|
||||
cell.save()
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', 'foobar', 'footer']
|
||||
assert re.findall('<h2>(.*)</h2>', resp.text) == [
|
||||
'Page - One', 'Content', 'JSON Prototype / Foobar', 'Footer']
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', 'foobar']
|
||||
assert re.findall('<h2>(.*)</h2>', resp.text) == ['Page - One', 'Content', 'JSON Prototype / Foobar']
|
||||
|
||||
|
||||
def test_page_familycell_placeholder(app, admin_user):
|
||||
page = Page(title='My family', slug='my-family', template_name='standard')
|
||||
|
@ -1203,10 +1254,11 @@ def test_page_familycell_placeholder(app, admin_user):
|
|||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', "family_unlinked_user", "footer"]
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', "family_unlinked_user"]
|
||||
assert re.findall('<h2>(.*)</h2>', resp.text) == [
|
||||
'Page - My family', 'Content',
|
||||
'Family Information Cell / Top content for unlinked users', 'Footer']
|
||||
'Family Information Cell / Top content for unlinked users']
|
||||
|
||||
|
||||
def test_page_discover_placeholder_with_error_cells(app, admin_user):
|
||||
page = Page(title='One', slug='one', template_name='standard')
|
||||
|
@ -1223,7 +1275,8 @@ def test_page_discover_placeholder_with_error_cells(app, admin_user):
|
|||
cell.render({})
|
||||
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', 'footer']
|
||||
assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content']
|
||||
|
||||
|
||||
def test_page_versionning(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
|
|
Loading…
Reference in New Issue