From 46055a6bfae171d2d70f54290ecae8ccd03aadc6 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Fri, 11 Mar 2016 15:52:46 -0300 Subject: [PATCH] Retira namespaces das urls do crud --- comissoes/urls.py | 6 ++---- crud/base.py | 28 ++++++++++++---------------- crud/tests/test_base.py | 10 +++++----- materia/urls.py | 5 +---- norma/urls.py | 6 ++---- sessao/urls.py | 6 ++---- 6 files changed, 24 insertions(+), 37 deletions(-) diff --git a/comissoes/urls.py b/comissoes/urls.py index dfbde7d40..bff625ee0 100644 --- a/comissoes/urls.py +++ b/comissoes/urls.py @@ -7,9 +7,7 @@ from comissoes.views import (CadastrarComissaoView, CargoCrud, ComissaoCrud, PeriodoComposicaoCrud, ReunioesView, TipoComissaoCrud) -comissao_url_patterns, namespace = ComissaoCrud.get_urls() - -comissao_url_patterns = comissao_url_patterns + [ +comissao_url_patterns = ComissaoCrud.get_urls() + [ url(r'^(?P\d+)/composicao$', ComposicaoView.as_view(), name='composicao'), url(r'^(?P\d+)/materias-em-tramitacao$', @@ -29,7 +27,7 @@ comissao_url_patterns = comissao_url_patterns + [ ] urlpatterns = [ - url(r'^comissoes/', include(comissao_url_patterns, namespace)), + url(r'^comissoes/', include(comissao_url_patterns)), url(r'^sistema/comissoes/cargo/', include(CargoCrud.get_urls())), url(r'^sistema/comissoes/periodo-composicao/', diff --git a/crud/base.py b/crud/base.py index 0010209ee..c778cdb7a 100644 --- a/crud/base.py +++ b/crud/base.py @@ -55,12 +55,12 @@ def make_pagination(index, num_pages): class BaseMixin(CrispyLayoutFormMixin): - @property - def namespace(self): - return self.model._meta.model_name + @classmethod + def url_name(cls, suffix): + return '%s_%s' % (cls.model._meta.model_name, suffix) - def resolve_url(self, url_name, args=None): - return reverse('%s:%s' % (self.namespace, url_name), args=args) + def resolve_url(self, suffix, args=None): + return reverse(self.url_name(suffix), args=args) @property def list_url(self): @@ -195,17 +195,13 @@ class Crud: CrudUpdateView = _add_base(cls.UpdateView) CrudDeleteView = _add_base(cls.DeleteView) - urlpatterns = [ - url(r'^$', CrudListView.as_view(), name='list'), - url(r'^create$', CrudCreateView.as_view(), name='create'), - url(r'^(?P\d+)$', CrudDetailView.as_view(), name='detail'), - url(r'^(?P\d+)/edit$', - CrudUpdateView.as_view(), name='update'), - url(r'^(?P\d+)/delete$', - CrudDeleteView.as_view(), name='delete'), - ] - - return urlpatterns, _add_base(object)().namespace + return [url(regex, view.as_view(), name=view.url_name(suffix)) + for regex, view, suffix in [ + (r'^$', CrudListView, 'list'), + (r'^create$', CrudCreateView, 'create'), + (r'^(?P\d+)$', CrudDetailView, 'detail'), + (r'^(?P\d+)/edit$', CrudUpdateView, 'update'), + (r'^(?P\d+)/delete$', CrudDeleteView, 'delete'), ]] @classonlymethod def build(cls, _model, _help_path): diff --git a/crud/tests/test_base.py b/crud/tests/test_base.py index b8a94a4c9..2021b8447 100644 --- a/crud/tests/test_base.py +++ b/crud/tests/test_base.py @@ -140,11 +140,11 @@ def test_layout_detail_fieldsets(monkeypatch): def test_reverse(): - assert '/countries/' == reverse('country:list') - assert '/countries/create' == reverse('country:create') - assert '/countries/2' == reverse('country:detail', args=(2,)) - assert '/countries/2/edit' == reverse('country:update', args=(2,)) - assert '/countries/2/delete' == reverse('country:delete', args=(2,)) + assert '/countries/' == reverse('country_list') + assert '/countries/create' == reverse('country_create') + assert '/countries/2' == reverse('country_detail', args=(2,)) + assert '/countries/2/edit' == reverse('country_update', args=(2,)) + assert '/countries/2/delete' == reverse('country_delete', args=(2,)) def assert_h1(res, title): diff --git a/materia/urls.py b/materia/urls.py index a608d1364..9cef0a76b 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -22,11 +22,8 @@ from materia.views import (AcompanhamentoConfirmarView, TramitacaoEditView, TramitacaoView, UnidadeTramitacaoCrud, ProposicaoEditView) -materia_legislativa_patterns, namespace = MateriaLegislativaCrud.get_urls() - - urlpatterns = [ - url(r'^materia/', include(materia_legislativa_patterns, namespace)), + url(r'^materia/', include(MateriaLegislativaCrud.get_urls())), url(r'^materia/(?P[0-9]+)/ta$', diff --git a/norma/urls.py b/norma/urls.py index ad3edf43a..0085740df 100644 --- a/norma/urls.py +++ b/norma/urls.py @@ -14,15 +14,13 @@ from norma.views import (AssuntoNormaCrud, NormaEditView, NormaIncluirView, # o código abaixo: # url(r'^norma/(?P[0-9]+)/ta$', NormaTaView.as_view(), name='ta') # bem como a classe NormaTaView que está em norma.views -norma_url_patterns, namespace = NormaTemporarioCrud.get_urls() - -norma_url_patterns += [ +norma_url_patterns = NormaTemporarioCrud.get_urls() + [ url(r'^norma/(?P[0-9]+)/ta$', NormaTaView.as_view(), name='ta') ] urlpatterns = [ - url(r'^norma/', include(norma_url_patterns, namespace)), + url(r'^norma/', include(norma_url_patterns)), url(r'^sistema/norma/tipo/', include(TipoNormaCrud.get_urls())), url(r'^sistema/norma/assunto/', include(AssuntoNormaCrud.get_urls())), diff --git a/sessao/urls.py b/sessao/urls.py index 95fba3701..79a9d471b 100644 --- a/sessao/urls.py +++ b/sessao/urls.py @@ -21,9 +21,7 @@ from sessao.views import (EditExpedienteOrdemDiaView, EditMateriaOrdemDiaView, VotacaoNominalExpedienteView, VotacaoNominalView, VotacaoView) -urlpatterns_sessao, namespace = SessaoCrud.get_urls() - -urlpatterns_sessao = urlpatterns_sessao + [ +urlpatterns_sessao = SessaoCrud.get_urls() + [ url(r'^(?P\d+)/expediente$', ExpedienteView.as_view(), name='expediente'), url(r'^(?P\d+)/presenca$', @@ -105,7 +103,7 @@ sessao_rest = [ ] urlpatterns = [ - url(r'^sessao/', include(urlpatterns_sessao, namespace)), + url(r'^sessao/', include(urlpatterns_sessao)), url(r'^media/(?P.*)$', serve, {'document_root': settings.MEDIA_ROOT}), url(r'^rest/', include(sessao_rest)),