|
@ -8,16 +8,19 @@ from django.views.generic import (CreateView, DeleteView, DetailView, ListView, |
|
|
|
|
|
|
|
|
from crispy_layout_mixin import CrispyLayoutFormMixin, get_field_display |
|
|
from crispy_layout_mixin import CrispyLayoutFormMixin, get_field_display |
|
|
|
|
|
|
|
|
|
|
|
LIST, CREATE, DETAIL, UPDATE, DELETE = \ |
|
|
|
|
|
'list', 'create', 'detail', 'update', 'delete' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _form_invalid_message(msg): |
|
|
def _form_invalid_message(msg): |
|
|
return '%s %s' % (_('Formulário inválido.'), msg) |
|
|
return '%s %s' % (_('Formulário inválido.'), msg) |
|
|
|
|
|
|
|
|
FORM_MESSAGES = {'create': (_('Registro criado com sucesso!'), |
|
|
FORM_MESSAGES = {CREATE: (_('Registro criado com sucesso!'), |
|
|
_('O registro não foi criado.')), |
|
|
_('O registro não foi criado.')), |
|
|
'update': (_('Registro alterado com sucesso!'), |
|
|
UPDATE: (_('Registro alterado com sucesso!'), |
|
|
_('Suas alterações não foram salvas.')), |
|
|
_('Suas alterações não foram salvas.')), |
|
|
'delete': (_('Registro excluído com sucesso!'), |
|
|
DELETE: (_('Registro excluído com sucesso!'), |
|
|
_('O registro não foi excluído.'))} |
|
|
_('O registro não foi excluído.'))} |
|
|
FORM_MESSAGES = {k: (a, _form_invalid_message(b)) |
|
|
FORM_MESSAGES = {k: (a, _form_invalid_message(b)) |
|
|
for k, (a, b) in FORM_MESSAGES.items()} |
|
|
for k, (a, b) in FORM_MESSAGES.items()} |
|
|
|
|
|
|
|
@ -64,23 +67,23 @@ class BaseMixin(CrispyLayoutFormMixin): |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def list_url(self): |
|
|
def list_url(self): |
|
|
return self.resolve_url('list') |
|
|
return self.resolve_url(LIST) |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def create_url(self): |
|
|
def create_url(self): |
|
|
return self.resolve_url('create') |
|
|
return self.resolve_url(CREATE) |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def detail_url(self): |
|
|
def detail_url(self): |
|
|
return self.resolve_url('detail', args=(self.object.id,)) |
|
|
return self.resolve_url(DETAIL, args=(self.object.id,)) |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def update_url(self): |
|
|
def update_url(self): |
|
|
return self.resolve_url('update', args=(self.object.id,)) |
|
|
return self.resolve_url(UPDATE, args=(self.object.id,)) |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def delete_url(self): |
|
|
def delete_url(self): |
|
|
return self.resolve_url('delete', args=(self.object.id,)) |
|
|
return self.resolve_url(DELETE, args=(self.object.id,)) |
|
|
|
|
|
|
|
|
def get_template_names(self): |
|
|
def get_template_names(self): |
|
|
names = super(BaseMixin, self).get_template_names() |
|
|
names = super(BaseMixin, self).get_template_names() |
|
@ -131,7 +134,7 @@ class CrudListView(ListView): |
|
|
|
|
|
|
|
|
class CrudCreateView(FormMessagesMixin, CreateView): |
|
|
class CrudCreateView(FormMessagesMixin, CreateView): |
|
|
|
|
|
|
|
|
form_valid_message, form_invalid_message = FORM_MESSAGES['create'] |
|
|
form_valid_message, form_invalid_message = FORM_MESSAGES[CREATE] |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def cancel_url(self): |
|
|
def cancel_url(self): |
|
@ -148,7 +151,7 @@ class CrudCreateView(FormMessagesMixin, CreateView): |
|
|
|
|
|
|
|
|
class CrudUpdateView(FormMessagesMixin, UpdateView): |
|
|
class CrudUpdateView(FormMessagesMixin, UpdateView): |
|
|
|
|
|
|
|
|
form_valid_message, form_invalid_message = FORM_MESSAGES['update'] |
|
|
form_valid_message, form_invalid_message = FORM_MESSAGES[UPDATE] |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def cancel_url(self): |
|
|
def cancel_url(self): |
|
@ -160,7 +163,7 @@ class CrudUpdateView(FormMessagesMixin, UpdateView): |
|
|
|
|
|
|
|
|
class CrudDeleteView(FormMessagesMixin, DeleteView): |
|
|
class CrudDeleteView(FormMessagesMixin, DeleteView): |
|
|
|
|
|
|
|
|
form_valid_message, form_invalid_message = FORM_MESSAGES['delete'] |
|
|
form_valid_message, form_invalid_message = FORM_MESSAGES[DELETE] |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def cancel_url(self): |
|
|
def cancel_url(self): |
|
@ -197,11 +200,11 @@ class Crud: |
|
|
|
|
|
|
|
|
return [url(regex, view.as_view(), name=view.url_name(suffix)) |
|
|
return [url(regex, view.as_view(), name=view.url_name(suffix)) |
|
|
for regex, view, suffix in [ |
|
|
for regex, view, suffix in [ |
|
|
(r'^$', CrudListView, 'list'), |
|
|
(r'^$', CrudListView, LIST), |
|
|
(r'^create$', CrudCreateView, 'create'), |
|
|
(r'^create$', CrudCreateView, CREATE), |
|
|
(r'^(?P<pk>\d+)$', CrudDetailView, 'detail'), |
|
|
(r'^(?P<pk>\d+)$', CrudDetailView, DETAIL), |
|
|
(r'^(?P<pk>\d+)/edit$', CrudUpdateView, 'update'), |
|
|
(r'^(?P<pk>\d+)/edit$', CrudUpdateView, UPDATE), |
|
|
(r'^(?P<pk>\d+)/delete$', CrudDeleteView, 'delete'), ]] |
|
|
(r'^(?P<pk>\d+)/delete$', CrudDeleteView, DELETE), ]] |
|
|
|
|
|
|
|
|
@classonlymethod |
|
|
@classonlymethod |
|
|
def build(cls, _model, _help_path): |
|
|
def build(cls, _model, _help_path): |
|
|