Browse Source

Fix #733

pull/736/merge
LeandroRoberto 8 years ago
parent
commit
c0a53d5ee4
  1. 1
      sapl/comissoes/views.py
  2. 18
      sapl/crud/base.py
  3. 26
      sapl/materia/views.py

1
sapl/comissoes/views.py

@ -30,6 +30,7 @@ class ParticipacaoCrud(MasterDetailCrud):
public = [RP_DETAIL, ]
ListView = None
is_m2m = True
link_return_to_parent_field = True
class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['composicao', 'parlamentar', 'cargo']

18
sapl/crud/base.py

@ -919,6 +919,7 @@ class CrudAux(Crud):
class MasterDetailCrud(Crud):
is_m2m = False
link_return_to_parent_field = False
class BaseMixin(Crud.BaseMixin):
@ -1145,11 +1146,14 @@ class MasterDetailCrud(Crud):
pk = root_pk
namespace = parent_object._meta.app_config.name
return reverse('%s:%s' % (
namespace,
'%s_%s' % (parent_object._meta.model_name, ACTION_DETAIL)),
args=(pk,))
if obj.is_m2m:
namespace = parent_object._meta.app_config.name
return reverse('%s:%s' % (
namespace,
'%s_%s' % (parent_object._meta.model_name, ACTION_DETAIL)),
args=(pk,))
else:
return self.resolve_url(ACTION_LIST, args=(pk,))
class DetailView(Crud.DetailView):
permission_required = RP_DETAIL,
@ -1166,7 +1170,7 @@ class MasterDetailCrud(Crud):
if not obj.ListView:
return ''
if not obj.ListView.permission_required or\
if obj.ListView.permission_required not in obj.public or\
self.request.user.has_perm(self.permission(RP_LIST)):
if '__' in obj.parent_field:
fields = obj.parent_field.split('__')
@ -1262,6 +1266,8 @@ class MasterDetailCrud(Crud):
@property
def detail_root_detail_url(self):
obj = self.crud if hasattr(self, 'crud') else self
if not obj.link_return_to_parent_field:
return ''
if hasattr(obj, 'parent_field'):
parent_field = obj.parent_field.split('__')
if not obj.is_m2m or len(parent_field) > 1:

26
sapl/materia/views.py

@ -757,7 +757,28 @@ class LegislacaoCitadaCrud(MasterDetailCrud):
args=args)
def has_permission(self):
return self.request.user.has_module_perms('materia')
perms = self.get_permission_required()
# Torna a view pública se não possuir conteudo
# no atributo permission_required
return self.request.user.has_module_perms('materia')\
if len(perms) else True
def permission(self, rad):
return '%s%s%s' % ('norma' if rad.endswith('_') else '',
rad,
self.model_name if rad.endswith('_') else '')
@property
def detail_create_url(self):
obj = self.crud if hasattr(self, 'crud') else self
if self.request.user.has_module_perms('materia'):
parent_field = obj.parent_field.split('__')[0]
parent_object = getattr(self.object, parent_field)
root_pk = parent_object.pk
return self.resolve_url(ACTION_CREATE, args=(root_pk,))
return ''
@property
def list_url(self):
@ -802,6 +823,9 @@ class LegislacaoCitadaCrud(MasterDetailCrud):
def layout_key(self):
return 'LegislacaoCitadaDetail'
class DeleteView(MasterDetailCrud.DeleteView):
pass
class NumeracaoCrud(MasterDetailCrud):
model = Numeracao

Loading…
Cancel
Save