lingo: hide items cell if empty (#41190)

This commit is contained in:
Lauréline Guérin 2020-03-31 15:48:28 +02:00
parent 5bc694d32d
commit f17b9cb3f5
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
4 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2020-03-31 13:12
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('lingo', '0037_regie_transaction_options'),
]
operations = [
migrations.AddField(
model_name='activeitems',
name='hide_if_empty',
field=models.BooleanField(default=False, verbose_name='Hide if no items'),
),
]

View File

@ -646,7 +646,6 @@ class Items(CellBase):
class Meta:
abstract = True
class Media:
js = ('xstatic/jquery-ui.min.js', 'js/gadjo.js',)
@ -659,6 +658,8 @@ class Items(CellBase):
def get_default_form_class(self):
fields = ['title', 'text']
if hasattr(self, 'hide_if_empty'):
fields.append('hide_if_empty')
widgets = {}
regie_qs = Regie.objects.exclude(webservice_url='')
if len(regie_qs) > 1:
@ -714,6 +715,7 @@ class ItemsHistory(Items):
@register_cell_class
class ActiveItems(Items):
hide_if_empty = models.BooleanField(_('Hide if no items'), default=False)
class Meta:
verbose_name = _('Active Items Cell')

View File

@ -1,5 +1,6 @@
{% load i18n %}
{% block cell-content %}
{% if items or not cell.hide_if_empty %}
{% if title %}<h2>{{ title|safe }}</h2>{% endif %}
<div>
{% if text %}{{ text|safe }}{% endif %}
@ -59,4 +60,5 @@
{% trans "No items yet" %}
{% endif %}
</div>
{% endif %}
{% endblock %}

View File

@ -210,6 +210,12 @@ def test_remote_regie_past_invoices_cell(mock_send, remote_regie):
content = cell.render(context)
assert 'No items yet' in content
cell.hide_if_empty = True
cell.save()
content = cell.render(context)
assert content.strip() == ''
@mock.patch('combo.apps.lingo.models.Regie.pay_invoice')
@mock.patch('combo.apps.lingo.models.requests.get')
def test_anonymous_successful_item_payment(mock_get, mock_pay_invoice, app, remote_regie):