summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauréline Guérin <zebuline@entrouvert.com>2020-01-23 15:18:51 (GMT)
committerLauréline Guérin <zebuline@entrouvert.com>2020-01-27 09:53:24 (GMT)
commite40a3e8b670b1529ba8666b269eb19eea874257c (patch)
tree4d9f274f9d49f9d4b67a56b2ce74c799f0e8e502
parentcfdaeaf94df49121c55ef9d0b37dcae2d96c592a (diff)
downloadcombo-wip/37135-optional-placeholder.zip
combo-wip/37135-optional-placeholder.tar.gz
combo-wip/37135-optional-placeholder.tar.bz2
placeholder: optional placeholders display and edition (#37135)wip/37135-optional-placeholder
-rw-r--r--combo/data/models.py5
-rw-r--r--combo/manager/templates/combo/page_view.html14
-rw-r--r--combo/manager/views.py31
-rw-r--r--combo/public/templates/combo/page_template.html2
-rw-r--r--tests/test_lingo_manager.py6
-rw-r--r--tests/test_manager.py69
6 files changed, 113 insertions, 14 deletions
diff --git a/combo/data/models.py b/combo/data/models.py
index 25d5e3a..025346b 100644
--- a/combo/data/models.py
+++ b/combo/data/models.py
@@ -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
diff --git a/combo/manager/templates/combo/page_view.html b/combo/manager/templates/combo/page_view.html
index 7623210..b9c8f0d 100644
--- a/combo/manager/templates/combo/page_view.html
+++ b/combo/manager/templates/combo/page_view.html
@@ -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 #}
diff --git a/combo/manager/views.py b/combo/manager/views.py
index 8977bc9..5d28d23 100644
--- a/combo/manager/views.py
+++ b/combo/manager/views.py
@@ -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),
diff --git a/combo/public/templates/combo/page_template.html b/combo/public/templates/combo/page_template.html
index 5d830ad..f3c481e 100644
--- a/combo/public/templates/combo/page_template.html
+++ b/combo/public/templates/combo/page_template.html
@@ -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 %}
diff --git a/tests/test_lingo_manager.py b/tests/test_lingo_manager.py
index 43fefa9..0c692a7 100644
--- a/tests/test_lingo_manager.py
+++ b/tests/test_lingo_manager.py
@@ -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'
diff --git a/tests/test_manager.py b/tests/test_manager.py
index 58ad4db..69ebc46 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -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()