diff --git a/compilacao/views.py b/compilacao/views.py index faf4309c4..aa11d8bd2 100644 --- a/compilacao/views.py +++ b/compilacao/views.py @@ -27,7 +27,7 @@ from compilacao.models import (Dispositivo, Nota, TextoArticulado, TipoDispositivo, TipoNota, TipoPublicacao, TipoTextoArticulado, TipoVide, VeiculoPublicacao, Vide) -from crud.base import Crud, CrudListMixin, make_pagination +from crud.base import Crud, ListMixin, make_pagination DISPOSITIVO_SELECT_RELATED = ( 'tipo_dispositivo', @@ -1667,7 +1667,7 @@ class PublicacaoListView(ListView): def get_context_data(self, **kwargs): context = super(PublicacaoListView, self).get_context_data(**kwargs) - context['NO_ENTRIES_MSG'] = CrudListMixin.no_entries_msg + context['NO_ENTRIES_MSG'] = ListMixin.no_entries_msg return context diff --git a/crud/base.py b/crud/base.py index 646c19d77..e9a028348 100644 --- a/crud/base.py +++ b/crud/base.py @@ -39,7 +39,7 @@ def make_pagination(index, num_pages): return head + [None] + tail -class BaseCrudMixin(CrispyLayoutFormMixin): +class BaseMixin(CrispyLayoutFormMixin): @property def namespace(self): @@ -69,7 +69,7 @@ class BaseCrudMixin(CrispyLayoutFormMixin): return self.resolve_url('delete', args=(self.object.id,)) def get_template_names(self): - names = super(BaseCrudMixin, self).get_template_names() + names = super(BaseMixin, self).get_template_names() names.append("crud/%s.html" % self.template_name_suffix.lstrip('_')) return names @@ -83,7 +83,7 @@ class BaseCrudMixin(CrispyLayoutFormMixin): return self.model._meta.verbose_name_plural -class CrudListMixin(): +class ListMixin(): paginate_by = 10 no_entries_msg = _('Nenhum registro encontrado.') @@ -94,7 +94,7 @@ class CrudListMixin(): for i, name in enumerate(self.list_field_names)] def get_context_data(self, **kwargs): - context = super(CrudListMixin, self).get_context_data(**kwargs) + context = super(ListMixin, self).get_context_data(**kwargs) context.setdefault('title', self.verbose_name_plural) # pagination @@ -119,7 +119,7 @@ def make_form_invalid_message(msg): return '%s %s' % (_('Formulário inválido.'), msg) -class CrudCreateMixin(FormMessagesMixin): +class CreateMixin(FormMessagesMixin): form_valid_message = _('Registro criado com sucesso!') form_invalid_message = make_form_invalid_message( @@ -135,14 +135,14 @@ class CrudCreateMixin(FormMessagesMixin): 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) + return super(CreateMixin, self).get_context_data(**kwargs) -class CrudDetailMixin(): +class DetailMixin(): pass -class CrudUpdateMixin(FormMessagesMixin): +class UpdateMixin(FormMessagesMixin): form_valid_message = _('Registro alterado com sucesso!') form_invalid_message = make_form_invalid_message( @@ -156,7 +156,7 @@ class CrudUpdateMixin(FormMessagesMixin): return self.detail_url -class CrudDeleteMixin(FormMessagesMixin): +class DeleteMixin(FormMessagesMixin): form_valid_message = _('Registro excluído com sucesso!') form_invalid_message = make_form_invalid_message( @@ -173,12 +173,12 @@ class CrudDeleteMixin(FormMessagesMixin): class Crud: def __init__(self, model, help_path, - base_mixin=BaseCrudMixin, - list_mixin=CrudListMixin, - create_mixin=CrudCreateMixin, - detail_mixin=CrudDetailMixin, - update_mixin=CrudUpdateMixin, - delete_mixin=CrudDeleteMixin): + base_mixin=BaseMixin, + list_mixin=ListMixin, + create_mixin=CreateMixin, + detail_mixin=DetailMixin, + update_mixin=UpdateMixin, + delete_mixin=DeleteMixin): class CrudMixin(base_mixin): pass diff --git a/crud/tests/stub_app/views.py b/crud/tests/stub_app/views.py index f021b6541..a3da663d3 100644 --- a/crud/tests/stub_app/views.py +++ b/crud/tests/stub_app/views.py @@ -1,13 +1,13 @@ -from crud.base import Crud, CrudListMixin +from crud.base import Crud, ListMixin from .models import Country -class CountryCrudListMixin(CrudListMixin): +class CountryListMixin(ListMixin): paginate_by = 10 country_crud = Crud( Country, 'help_path', - list_mixin=CountryCrudListMixin) + list_mixin=CountryListMixin) diff --git a/crud/tests/test_base.py b/crud/tests/test_base.py index a3bebe3f6..792230fa4 100644 --- a/crud/tests/test_base.py +++ b/crud/tests/test_base.py @@ -2,11 +2,11 @@ import pytest from django.core.urlresolvers import reverse from model_mommy import mommy -from crud.base import (CrispyLayoutFormMixin, CrudListMixin, from_to, +from crud.base import (CrispyLayoutFormMixin, ListMixin, from_to, get_field_display, make_pagination) from .stub_app.models import Continent, Country -from .stub_app.views import CountryCrudListMixin +from .stub_app.views import CountryListMixin pytestmark = pytest.mark.django_db @@ -151,7 +151,7 @@ def assert_h1(res, title): assert res.html.find('main').find('h1').text.strip() == title -NO_ENTRIES_MSG = str(CrudListMixin.no_entries_msg) # "unlazy" +NO_ENTRIES_MSG = str(ListMixin.no_entries_msg) # "unlazy" def assert_on_list_page(res): @@ -196,7 +196,7 @@ def test_flux_list_paginate_detail( population=population, is_cold=is_cold) - CountryCrudListMixin.paginate_by = page_size + CountryListMixin.paginate_by = page_size res = app.get('/countries/')