From 9db46013ba0281442f1709c060fdbbd0544f6cf8 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Mon, 7 Mar 2016 11:29:45 -0300 Subject: [PATCH 1/5] =?UTF-8?q?Usa=20include=20de=20pagina=C3=A7=C3=A3o=20?= =?UTF-8?q?na=20listagem=20do=20crud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crud_tests/test_flux.py | 4 ++-- templates/crud/list.html | 36 +----------------------------------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/crud_tests/test_flux.py b/crud_tests/test_flux.py index 16a63948a..1c7cfef42 100644 --- a/crud_tests/test_flux.py +++ b/crud_tests/test_flux.py @@ -178,8 +178,8 @@ def assert_on_detail_page(res, stub_name): @pytest.mark.parametrize("num_entries, page_size, ranges, page_list", [ (0, 6, [], []), (5, 5, [(0, 5)], []), - (10, 5, [(0, 5), (5, 10)], ['«', '1', '2', '»']), - (9, 4, [(0, 4), (4, 8), (8, 9)], ['«', '1', '2', '3', '»']), + (10, 5, [(0, 5), (5, 10)], ['Anterior', '1', '2', 'Próxima']), + (9, 4, [(0, 4), (4, 8), (8, 9)], ['Anterior', '1', '2', '3', 'Próxima']), ]) def test_flux_list_paginate_detail( app, monkeypatch, num_entries, page_size, ranges, page_list): diff --git a/templates/crud/list.html b/templates/crud/list.html index cfa20b5aa..854ff30b0 100644 --- a/templates/crud/list.html +++ b/templates/crud/list.html @@ -43,40 +43,6 @@ {% endif %} +{% include "paginacao.html" %} -{% if is_paginated %} -
- -
-{% endif %} {% endblock %} From 75ec30549d9c1c3c4b5c33fc5e5f579e76d2e73d Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Tue, 8 Mar 2016 09:00:27 -0300 Subject: [PATCH 2/5] Pass crud titles on the context --- crud.py | 25 +++++++------------------ crud_tests/templates/base.html | 12 ++++++++---- crud_tests/test_flux.py | 2 +- templates/base.html | 8 ++++---- templates/crud/confirm_delete.html | 6 ------ templates/crud/detail.html | 1 - 6 files changed, 20 insertions(+), 34 deletions(-) diff --git a/crud.py b/crud.py index 1b4194739..57cfd2e22 100644 --- a/crud.py +++ b/crud.py @@ -88,10 +88,6 @@ class CrudListMixin(): paginate_by = 10 no_entries_msg = _('Nenhum registro encontrado.') - @property - def title(self): - return self.verbose_name_plural - def _as_row(self, obj): return [ (get_field_display(obj, name)[1], obj.pk if i == 0 else None) @@ -99,6 +95,7 @@ class CrudListMixin(): def get_context_data(self, **kwargs): context = super(CrudListMixin, self).get_context_data(**kwargs) + context.setdefault('title', self.verbose_name_plural) # pagination page_obj = context['page_obj'] @@ -128,11 +125,6 @@ class CrudCreateMixin(FormMessagesMixin): form_invalid_message = make_form_invalid_message( _('O registro não foi criado.')) - @property - def title(self): - return _('Adicionar %(verbose_name)s') % { - 'verbose_name': self.verbose_name} - @property def cancel_url(self): return self.list_url @@ -140,13 +132,14 @@ class CrudCreateMixin(FormMessagesMixin): def get_success_url(self): return self.detail_url + def get_context_data(self, **kwargs): + kwargs.setdefault('title', _('Adicionar %(verbose_name)s') % { + 'verbose_name': self.verbose_name}) + return super(CrudCreateMixin, self).get_context_data(**kwargs) + class CrudDetailMixin(): - - @property - def title(self): - # TODO: can we just use view.object in the templates???? - return str(self.object) + pass class CrudUpdateMixin(FormMessagesMixin): @@ -155,10 +148,6 @@ class CrudUpdateMixin(FormMessagesMixin): form_invalid_message = make_form_invalid_message( _('Suas alterações não foram salvas.')) - @property - def title(self): - return str(self.object) - @property def cancel_url(self): return self.detail_url diff --git a/crud_tests/templates/base.html b/crud_tests/templates/base.html index 75b4487c2..8a9dc002b 100644 --- a/crud_tests/templates/base.html +++ b/crud_tests/templates/base.html @@ -24,11 +24,15 @@ {% block base_header %}
- {% block title %} - {% if view.title %} -

{{ view.title|linebreaksbr }}

+ {% block title %} +

+ {% if title %} + {{ title|safe|linebreaksbr }} + {% elif object %} + {{ object|safe|linebreaksbr }} {% endif %} - {% endblock %} +

+ {% endblock %}
{% endblock base_header %} diff --git a/crud_tests/test_flux.py b/crud_tests/test_flux.py index 1c7cfef42..f60b2e6a0 100644 --- a/crud_tests/test_flux.py +++ b/crud_tests/test_flux.py @@ -148,7 +148,7 @@ def test_reverse(): def assert_h1(res, title): - assert res.html.find('main').find('h1').text == title + assert res.html.find('main').find('h1').text.strip() == title NO_ENTRIES_MSG = str(CrudListMixin.no_entries_msg) # "unlazy" diff --git a/templates/base.html b/templates/base.html index 94a6b4357..4c541d06f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -155,10 +155,10 @@ {% block title %}

- {% if view.title %} - {{ view.title|safe|linebreaksbr }} - {% else %} - {{ title|safe|linebreaksbr }} + {% if title %} + {{ title|safe|linebreaksbr }} + {% elif object %} + {{ object|safe|linebreaksbr }} {% endif %}

{% endblock %} diff --git a/templates/crud/confirm_delete.html b/templates/crud/confirm_delete.html index 703afe2a2..367f5857d 100644 --- a/templates/crud/confirm_delete.html +++ b/templates/crud/confirm_delete.html @@ -1,12 +1,6 @@ {% extends "base.html" %} {% load i18n %} -{% block title %} - {% with object as title %} - {{ block.super }} - {% endwith %} -{% endblock %} - {% block base_content %}
{% csrf_token %}
diff --git a/templates/crud/detail.html b/templates/crud/detail.html index f35d0d469..5eb502d19 100644 --- a/templates/crud/detail.html +++ b/templates/crud/detail.html @@ -3,7 +3,6 @@ {% block base_content %} - {# FIXME is this the best markup to use? #}
{% block actions %}
From e9a74e4ea4a99314f4d38934bbafec305a08366e Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Tue, 8 Mar 2016 10:27:57 -0300 Subject: [PATCH 3/5] =?UTF-8?q?Usa=20cancel=5Furl=20na=20confirma=C3=A7?= =?UTF-8?q?=C3=A3o=20de=20apagar=20no=20crud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crud.py | 4 ++++ templates/crud/confirm_delete.html | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crud.py b/crud.py index 57cfd2e22..41548d106 100644 --- a/crud.py +++ b/crud.py @@ -162,6 +162,10 @@ class CrudDeleteMixin(FormMessagesMixin): form_invalid_message = make_form_invalid_message( _('O registro não foi excluído.')) + @property + def cancel_url(self): + return self.detail_url + def get_success_url(self): return self.list_url diff --git a/templates/crud/confirm_delete.html b/templates/crud/confirm_delete.html index 367f5857d..685c0d4ac 100644 --- a/templates/crud/confirm_delete.html +++ b/templates/crud/confirm_delete.html @@ -10,7 +10,7 @@ {% endblocktrans %}
From 2769abe1b94c470e41d44ec994756ec2694e714b Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Tue, 8 Mar 2016 10:33:46 -0300 Subject: [PATCH 4/5] =?UTF-8?q?Reformata=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/crud/list.html | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/templates/crud/list.html b/templates/crud/list.html index 854ff30b0..297be1c3d 100644 --- a/templates/crud/list.html +++ b/templates/crud/list.html @@ -3,15 +3,11 @@ {% block base_content %} -{# FIXME is this the best markup to use? #}
{% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %} - - {% block more_buttons %} - {% endblock more_buttons %} - + {% block more_buttons %}{% endblock more_buttons %}
{% if not rows %} From b8f65aca757a3daf8f76b6411bfc100b163a71d7 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Tue, 8 Mar 2016 10:55:36 -0300 Subject: [PATCH 5/5] =?UTF-8?q?Reoformata=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/base.html | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/templates/base.html b/templates/base.html index 4c541d06f..1e619c84c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -111,17 +111,17 @@ {% block main_header %}
@@ -155,12 +155,12 @@ {% block title %}

- {% if title %} - {{ title|safe|linebreaksbr }} + {% if title %} + {{ title|safe|linebreaksbr }} {% elif object %} {{ object|safe|linebreaksbr }} {% endif %} -

+ {% endblock %}