|
|
@ -7,27 +7,25 @@ from django.views.generic import ( |
|
|
|
|
|
|
|
|
|
|
|
class Crud(object): |
|
|
|
pass |
|
|
|
|
|
|
|
def __init__(self, model_form): |
|
|
|
|
|
|
|
self.model_form = model_form |
|
|
|
|
|
|
|
self.model = model_form._meta.model |
|
|
|
|
|
|
|
# urls names |
|
|
|
self.namespace = self.model._meta.model_name |
|
|
|
def build_crud(model_form): |
|
|
|
crud = Crud() |
|
|
|
crud.model = model_form._meta.model |
|
|
|
crud.namespace = crud.model._meta.model_name |
|
|
|
|
|
|
|
def in_namespace(url_name): |
|
|
|
return '%s:%s' % (self.namespace, url_name) |
|
|
|
return '%s:%s' % (crud.namespace, url_name) |
|
|
|
|
|
|
|
def make_form_invalid_message(msg): |
|
|
|
return '%s %s' % (_('Formulário inválido.'), msg) |
|
|
|
|
|
|
|
class BaseMixin(object): |
|
|
|
model = self.model |
|
|
|
model = crud.model |
|
|
|
|
|
|
|
verbose_name = self.model._meta.verbose_name |
|
|
|
verbose_name_plural = self.model._meta.verbose_name_plural |
|
|
|
verbose_name = crud.model._meta.verbose_name |
|
|
|
verbose_name_plural = crud.model._meta.verbose_name_plural |
|
|
|
|
|
|
|
list_url = reverse_lazy(in_namespace('list')) |
|
|
|
create_url = reverse_lazy(in_namespace('create')) |
|
|
@ -89,13 +87,13 @@ class Crud(object): |
|
|
|
def get_success_url(self): |
|
|
|
return self.list_url |
|
|
|
|
|
|
|
self.CrudListView = CrudListView |
|
|
|
self.CrudCreateView = CrudCreateView |
|
|
|
self.CrudDetailView = CrudDetailView |
|
|
|
self.CrudUpdateView = CrudUpdateView |
|
|
|
self.CrudDeleteView = CrudDeleteView |
|
|
|
crud.CrudListView = CrudListView |
|
|
|
crud.CrudCreateView = CrudCreateView |
|
|
|
crud.CrudDetailView = CrudDetailView |
|
|
|
crud.CrudUpdateView = CrudUpdateView |
|
|
|
crud.CrudDeleteView = CrudDeleteView |
|
|
|
|
|
|
|
self.urls = [ |
|
|
|
crud.urls = [ |
|
|
|
url(r'^$', CrudListView.as_view(), name='list'), |
|
|
|
url(r'^create$', CrudCreateView.as_view(), name='create'), |
|
|
|
url(r'^(?P<pk>\d+)$', CrudDetailView.as_view(), name='detail'), |
|
|
@ -103,4 +101,6 @@ class Crud(object): |
|
|
|
CrudUpdateView.as_view(), name='update'), |
|
|
|
url(r'^(?P<pk>\d+)/delete$', |
|
|
|
CrudDeleteView.as_view(), name='delete'), |
|
|
|
], self.namespace, self.namespace |
|
|
|
], crud.namespace, crud.namespace |
|
|
|
|
|
|
|
return crud |
|
|
|