@ -263,18 +263,18 @@ class CrudBaseMixin(CrispyLayoutFormMixin):
self . model_name_set = getattr (
self . model_name_set = getattr (
obj . model , obj . model_set ) . field . model . _meta . model_name
obj . model , obj . model_set ) . field . model . _meta . model_name
if hasattr ( self , ' permission_required ' ) and self . permission_required :
if not hasattr ( obj , ' public ' ) :
if hasattr ( obj , ' public ' ) :
self . permission_required = list (
set ( self . permission_required ) - set ( obj . public ) )
else :
obj . public = [ ]
obj . public = [ ]
self . permission_required = tuple ( (
if hasattr ( self , ' permission_required ' ) and self . permission_required :
self . permission ( pr ) for pr in self . permission_required ) )
else :
self . permission_required = tuple (
obj . public = [ ]
(
self . permission ( pr ) for pr in (
set ( self . permission_required ) - set ( obj . public )
)
)
)
@classmethod
@classmethod
def url_name ( cls , suffix ) :
def url_name ( cls , suffix ) :
@ -460,7 +460,8 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView):
# URL padrão para primeira coluna da listagem
# URL padrão para primeira coluna da listagem
url = self . resolve_url (
url = self . resolve_url (
ACTION_DETAIL , args = ( obj . id , ) ) if i == 0 else None
ACTION_DETAIL , args = ( obj . id , ) ) if i == 0 else None
# gera URL para matéria a partir de fk_urlify_for_list em layouts.yaml
# gera URL para matéria a partir de fk_urlify_for_list em
# layouts.yaml
if i > 0 and func is not None :
if i > 0 and func is not None :
url = getattr ( self , func ) ( obj , name ) [ 0 ]
url = getattr ( self , func ) ( obj , name ) [ 0 ]
@ -947,6 +948,8 @@ class CrudDeleteView(PermissionRequiredContainerCrudMixin,
class Crud :
class Crud :
__abstract__ = True
BaseMixin = CrudBaseMixin
BaseMixin = CrudBaseMixin
ListView = CrudListView
ListView = CrudListView
CreateView = CrudCreateView
CreateView = CrudCreateView
@ -962,9 +965,26 @@ class Crud:
def get_urls ( cls ) :
def get_urls ( cls ) :
def _add_base ( view ) :
def _add_base ( view ) :
if view :
if not view :
return
if not cls . __abstract__ :
return view
pr = set ( )
if hasattr ( view , ' permission_required ' ) and \
view . permission_required and \
hasattr ( cls , ' public ' ) and \
cls . public :
#print(view.permission_required, view)
#print(cls.public, cls)
pr = set ( view . permission_required ) - set ( cls . public )
class CrudViewWithBase ( cls . BaseMixin , view ) :
class CrudViewWithBase ( cls . BaseMixin , view ) :
permission_required = tuple ( pr )
model = cls . model
model = cls . model
help_topic = cls . help_topic
help_topic = cls . help_topic
crud = cls
crud = cls
@ -978,6 +998,21 @@ class Crud:
CrudUpdateView = _add_base ( cls . UpdateView )
CrudUpdateView = _add_base ( cls . UpdateView )
CrudDeleteView = _add_base ( cls . DeleteView )
CrudDeleteView = _add_base ( cls . DeleteView )
cruds = CrudListView , CrudCreateView , CrudDetailView , CrudUpdateView , CrudDeleteView
if cls . __abstract__ :
class CRUD ( cls ) :
__abstract__ = False
ListView = CrudListView
CreateView = CrudCreateView
DetailView = CrudDetailView
UpdateView = CrudUpdateView
DeleteView = CrudDeleteView
for c in cruds :
if c :
c . crud = CRUD
cruds_base = [
cruds_base = [
( CrudListView . get_url_regex ( )
( CrudListView . get_url_regex ( )
if CrudListView else None , CrudListView , ACTION_LIST ) ,
if CrudListView else None , CrudListView , ACTION_LIST ) ,