Re: Read Only by user in Django Admin

2017-02-20 Thread Juan Corrales Araya
Hi.

The answer is very simple. 
you have to install   *django-admin-view-permission*

then you have to added on setting   
INSTALLED_APPS = [
...
'admin_view_permission',
...
]

finally you have to run:* python manage.py migrate*

You will see that the permission will already be available in the admin 
panel.

For more information see the package web page:  

http://django-admin-view-permission.readthedocs.io/en/latest/index.html




El domingo, 8 de febrero de 2015, 11:44:26 (UTC-3), Hangloser Firestarter 
escribió:
>
> Hello.
> I am using the admin backend of a system, but not all users of this 
> backend can access all system models.
> By default Django is the roles ADD, EDIT and DELETE, I wonder if anyone 
> has customized the model auth.permission to generate a permission 'read 
> only' to Django Admin? Or if you have used any APP to do that.
>
> Thank
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f25a3fee-59ca-45c0-a5f0-f8791149b37b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Read Only by user in Django Admin

2016-10-28 Thread Olivier Dalang
Hi,

The following PR is ready to merge and implements this:
https://github.com/django/django/pull/6734

I will squash the commits  as soon as I'm back in the office (next week)
and it will probably be merged soon.

Bests

Olivier

On 25 Oct 2016 19:03, "Luis Zárate"  wrote:

> you are looking something like
> https://code.djangoproject.com/ticket/7150
> https://code.djangoproject.com/attachment/ticket/7150/
> admin_view-permission-1.0.patch
> https://code.djangoproject.com/attachment/ticket/7150/newforms-admin-view-
> permission-r7737.patch
> https://code.djangoproject.com/ticket/8936
> https://code.djangoproject.com/ticket/22452
> https://code.djangoproject.com/ticket/18814
> https://code.djangoproject.com/ticket/17295
> https://code.djangoproject.com/ticket/3984
> https://code.djangoproject.com/ticket/2058
> https://code.djangoproject.com/ticket/820
>
>
> I don't know why Django doesn't support readonly view, various proposal
> was summit and always was reject.
>
> Django Admin needs Readonly View functionality for a complete
> implementation of CRUD.
>
> There is a lot of scenarios where you need readonly view for your staff.
> And yes you can implement a readonly  in django admin without modify django
> core admin with some tricks.
>
> I
>
>
>
> 2016-10-24 7:26 GMT-06:00 Derek :
>
>> Would it be possible to add these extra admin methods into a parent
>> class; and then have all your individual model admins inherit from it?
>> Ditto for the models.py
>>
>> On Sunday, 8 February 2015 21:15:42 UTC+2, Hangloser Firestarter wrote:
>>>
>>> Solved.
>>>
>>> In __init__.py
>>> ...
>>> from django.db.models.signals import post_syncdb
>>> from django.contrib.contenttypes.models import ContentType
>>> from django.contrib.auth.models import Permission
>>>
>>> def add_view_permissions(sender, **kwargs):
>>> """
>>> This syncdb hooks takes care of adding a view permission too all our
>>> content types.
>>> """
>>> # for each of our content types
>>> for content_type in ContentType.objects.all():
>>> # build our permission slug
>>> codename = "view_%s" % content_type.model
>>>
>>> # if it doesn't exist..
>>> if not Permission.objects.filter(content_type=content_type,
>>> codename=codename):
>>> # add it
>>> Permission.objects.create(content_type=content_type,
>>>   codename=codename,
>>>   name="Can view %s" %
>>> content_type.name)
>>> print("Added view permission for %s" % content_type.name)
>>>
>>> # check for all our view permissions after a syncdb
>>> post_syncdb.connect(add_view_permissions)
>>> ...
>>>
>>> In admin.py
>>> ...
>>> class MyAdmin(admin.ModelAdmin):
>>> def has_change_permission(self, request, obj=None):
>>> ct = ContentType.objects.get_for_model(self.model)
>>> salida = False
>>> if request.user.is_superuser:
>>> salida = True
>>> else:
>>> if request.user.has_perm('%s.view_%s' % (ct.app_label,
>>> ct.model)):
>>> salida = True
>>> else:
>>> if request.user.has_perm('%s.change_%s' %
>>> (ct.app_label, ct.model)):
>>> salida = True
>>> else:
>>> salida = False
>>> return salida
>>>
>>> def get_readonly_fields(self, request, obj=None):
>>> ct = ContentType.objects.get_for_model(self.model)
>>> if not request.user.is_superuser and
>>> request.user.has_perm('%s.view_%s' % (ct.app_label, ct.model)):
>>> return [el.name for el in self.model._meta.fields]
>>> return self.readonly_fields
>>> ...
>>>
>>> in models.py
>>> ...
>>> class City(models.Model):
>>> nome_cidade = models.CharField(max_length=100)
>>> estado_cidade = models.CharField(max_length=100)
>>> pais_cidade = models.CharField(max_length=100)
>>>
>>> def __str__(self):
>>> return self.nome_cidade
>>>
>>> class Meta:
>>> permissions = (
>>> ('view_city', 'Can view city'),
>>> )
>>> ...
>>>
>>> Thank's for help!
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/74f952fe-f0f5-4fb3-abd4-d6736cbd2743%40googlegroups.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> "La utopía sirve para 

Re: Read Only by user in Django Admin

2016-10-25 Thread Luis Zárate
you are looking something like
https://code.djangoproject.com/ticket/7150
https://code.djangoproject.com/attachment/ticket/7150/admin_view-permission-1.0.patch
https://code.djangoproject.com/attachment/ticket/7150/newforms-admin-view-permission-r7737.patch
https://code.djangoproject.com/ticket/8936
https://code.djangoproject.com/ticket/22452
https://code.djangoproject.com/ticket/18814
https://code.djangoproject.com/ticket/17295
https://code.djangoproject.com/ticket/3984
https://code.djangoproject.com/ticket/2058
https://code.djangoproject.com/ticket/820


I don't know why Django doesn't support readonly view, various proposal was
summit and always was reject.

Django Admin needs Readonly View functionality for a complete
implementation of CRUD.

There is a lot of scenarios where you need readonly view for your staff.
And yes you can implement a readonly  in django admin without modify django
core admin with some tricks.

I



2016-10-24 7:26 GMT-06:00 Derek :

> Would it be possible to add these extra admin methods into a parent class;
> and then have all your individual model admins inherit from it?  Ditto for
> the models.py
>
> On Sunday, 8 February 2015 21:15:42 UTC+2, Hangloser Firestarter wrote:
>>
>> Solved.
>>
>> In __init__.py
>> ...
>> from django.db.models.signals import post_syncdb
>> from django.contrib.contenttypes.models import ContentType
>> from django.contrib.auth.models import Permission
>>
>> def add_view_permissions(sender, **kwargs):
>> """
>> This syncdb hooks takes care of adding a view permission too all our
>> content types.
>> """
>> # for each of our content types
>> for content_type in ContentType.objects.all():
>> # build our permission slug
>> codename = "view_%s" % content_type.model
>>
>> # if it doesn't exist..
>> if not Permission.objects.filter(content_type=content_type,
>> codename=codename):
>> # add it
>> Permission.objects.create(content_type=content_type,
>>   codename=codename,
>>   name="Can view %s" %
>> content_type.name)
>> print("Added view permission for %s" % content_type.name)
>>
>> # check for all our view permissions after a syncdb
>> post_syncdb.connect(add_view_permissions)
>> ...
>>
>> In admin.py
>> ...
>> class MyAdmin(admin.ModelAdmin):
>> def has_change_permission(self, request, obj=None):
>> ct = ContentType.objects.get_for_model(self.model)
>> salida = False
>> if request.user.is_superuser:
>> salida = True
>> else:
>> if request.user.has_perm('%s.view_%s' % (ct.app_label,
>> ct.model)):
>> salida = True
>> else:
>> if request.user.has_perm('%s.change_%s' % (ct.app_label,
>> ct.model)):
>> salida = True
>> else:
>> salida = False
>> return salida
>>
>> def get_readonly_fields(self, request, obj=None):
>> ct = ContentType.objects.get_for_model(self.model)
>> if not request.user.is_superuser and
>> request.user.has_perm('%s.view_%s' % (ct.app_label, ct.model)):
>> return [el.name for el in self.model._meta.fields]
>> return self.readonly_fields
>> ...
>>
>> in models.py
>> ...
>> class City(models.Model):
>> nome_cidade = models.CharField(max_length=100)
>> estado_cidade = models.CharField(max_length=100)
>> pais_cidade = models.CharField(max_length=100)
>>
>> def __str__(self):
>> return self.nome_cidade
>>
>> class Meta:
>> permissions = (
>> ('view_city', 'Can view city'),
>> )
>> ...
>>
>> Thank's for help!
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/74f952fe-f0f5-4fb3-abd4-d6736cbd2743%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"La utopía sirve para caminar" Fernando Birri

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 

Re: Read Only by user in Django Admin

2016-10-24 Thread Derek
Would it be possible to add these extra admin methods into a parent class; 
and then have all your individual model admins inherit from it?  Ditto for 
the models.py

On Sunday, 8 February 2015 21:15:42 UTC+2, Hangloser Firestarter wrote:
>
> Solved.
>
> In __init__.py
> ...
> from django.db.models.signals import post_syncdb
> from django.contrib.contenttypes.models import ContentType
> from django.contrib.auth.models import Permission
>
> def add_view_permissions(sender, **kwargs):
> """
> This syncdb hooks takes care of adding a view permission too all our 
> content types.
> """
> # for each of our content types
> for content_type in ContentType.objects.all():
> # build our permission slug
> codename = "view_%s" % content_type.model
>
> # if it doesn't exist..
> if not Permission.objects.filter(content_type=content_type, 
> codename=codename):
> # add it
> Permission.objects.create(content_type=content_type,
>   codename=codename,
>   name="Can view %s" % 
> content_type.name)
> print("Added view permission for %s" % content_type.name)
>
> # check for all our view permissions after a syncdb
> post_syncdb.connect(add_view_permissions)
> ...
>
> In admin.py
> ...
> class MyAdmin(admin.ModelAdmin):
> def has_change_permission(self, request, obj=None):
> ct = ContentType.objects.get_for_model(self.model)
> salida = False
> if request.user.is_superuser:
> salida = True
> else:
> if request.user.has_perm('%s.view_%s' % (ct.app_label, 
> ct.model)):
> salida = True
> else:
> if request.user.has_perm('%s.change_%s' % (ct.app_label, 
> ct.model)):
> salida = True
> else:
> salida = False
> return salida
>
> def get_readonly_fields(self, request, obj=None):
> ct = ContentType.objects.get_for_model(self.model)
> if not request.user.is_superuser and 
> request.user.has_perm('%s.view_%s' % (ct.app_label, ct.model)):
> return [el.name for el in self.model._meta.fields]
> return self.readonly_fields
> ...
>
> in models.py
> ...
> class City(models.Model):
> nome_cidade = models.CharField(max_length=100)
> estado_cidade = models.CharField(max_length=100)
> pais_cidade = models.CharField(max_length=100)
>
> def __str__(self):
> return self.nome_cidade
>
> class Meta:
> permissions = (
> ('view_city', 'Can view city'),
> )
> ...
>
> Thank's for help!
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/74f952fe-f0f5-4fb3-abd4-d6736cbd2743%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Read Only by user in Django Admin

2016-10-24 Thread Naveen Kumar
Hello,

This looks perfect when i don't have any fields in list_editable.

This code is not working with list_editable.

On Sunday, February 8, 2015 at 8:14:26 PM UTC+5:30, Hangloser Firestarter 
wrote:
>
> Hello.
> I am using the admin backend of a system, but not all users of this 
> backend can access all system models.
> By default Django is the roles ADD, EDIT and DELETE, I wonder if anyone 
> has customized the model auth.permission to generate a permission 'read 
> only' to Django Admin? Or if you have used any APP to do that.
>
> Thank
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c8f793bc-c780-459f-816a-f1b3a5d902cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Read Only by user in Django Admin

2015-02-08 Thread Hangloser Firestarter
Solved.

In __init__.py
...
from django.db.models.signals import post_syncdb
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Permission

def add_view_permissions(sender, **kwargs):
"""
This syncdb hooks takes care of adding a view permission too all our 
content types.
"""
# for each of our content types
for content_type in ContentType.objects.all():
# build our permission slug
codename = "view_%s" % content_type.model

# if it doesn't exist..
if not Permission.objects.filter(content_type=content_type, 
codename=codename):
# add it
Permission.objects.create(content_type=content_type,
  codename=codename,
  name="Can view %s" % 
content_type.name)
print("Added view permission for %s" % content_type.name)

# check for all our view permissions after a syncdb
post_syncdb.connect(add_view_permissions)
...

In admin.py
...
class MyAdmin(admin.ModelAdmin):
def has_change_permission(self, request, obj=None):
ct = ContentType.objects.get_for_model(self.model)
salida = False
if request.user.is_superuser:
salida = True
else:
if request.user.has_perm('%s.view_%s' % (ct.app_label, 
ct.model)):
salida = True
else:
if request.user.has_perm('%s.change_%s' % (ct.app_label, 
ct.model)):
salida = True
else:
salida = False
return salida

def get_readonly_fields(self, request, obj=None):
ct = ContentType.objects.get_for_model(self.model)
if not request.user.is_superuser and 
request.user.has_perm('%s.view_%s' % (ct.app_label, ct.model)):
return [el.name for el in self.model._meta.fields]
return self.readonly_fields
...

in models.py
...
class City(models.Model):
nome_cidade = models.CharField(max_length=100)
estado_cidade = models.CharField(max_length=100)
pais_cidade = models.CharField(max_length=100)

def __str__(self):
return self.nome_cidade

class Meta:
permissions = (
('view_city', 'Can view city'),
)
...

Thank's for help!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b7bda756-e5ed-4f70-8524-46daec061e23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Read Only by user in Django Admin

2015-02-08 Thread Edgar Gabaldi
In the get_readonly_fields, you have access to the request.user, you can
check the permission inside the method, something like that:


def get_readonly_fields(self, request, obj=None):

if obj and not request.user.has_perm('your_app.your_custom_permission'):
# return a tuple with all fields that needs to be read only.
return None

You can add your custom permission to a group.

On Sun, Feb 8, 2015 at 12:55 PM, Hangloser Firestarter 
wrote:

> Gabaldi.
>
> Can I integrate this get_readonly_fields with auth.groups?
>
> And show whitelisted django admin.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e376a4ce-dd8d-4ba9-9dbd-f0fbfc96bd96%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGjPPHmmTuX2%3DoAn24My0j%2BhZdthWcajSPfrLHoa6%3D8ase6jhg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Read Only by user in Django Admin

2015-02-08 Thread Hangloser Firestarter
Gabaldi.

Can I integrate this get_readonly_fields with auth.groups?

And show whitelisted django admin.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e376a4ce-dd8d-4ba9-9dbd-f0fbfc96bd96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Read Only by user in Django Admin

2015-02-08 Thread Edgar Gabaldi
The ModelAdmin has a method get_readonly_fields [1]. You can override this
method and check a custom permission[2].

[1]
https://docs.djangoproject.com/en/1.7/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_readonly_fields
[2] https://docs.djangoproject.com/en/1.7/ref/models/options/#permissions

On Sun, Feb 8, 2015 at 12:44 PM, Hangloser Firestarter 
wrote:

> Hello.
> I am using the admin backend of a system, but not all users of this
> backend can access all system models.
> By default Django is the roles ADD, EDIT and DELETE, I wonder if anyone
> has customized the model auth.permission to generate a permission 'read
> only' to Django Admin? Or if you have used any APP to do that.
>
> Thank
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/977d9fa7-0f27-4346-8322-e7938f263fac%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGjPPHk%2BrhFCgm2V9-qJri0YMkmaOzqdUp%3DZpPQv25rhfp1vaA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Read Only by user in Django Admin

2015-02-08 Thread Hangloser Firestarter
Hello.
I am using the admin backend of a system, but not all users of this backend can 
access all system models.
By default Django is the roles ADD, EDIT and DELETE, I wonder if anyone has 
customized 
the model auth.permission to generate a permission 'read only' to Django 
Admin? Or if you have used any APP to do that.

Thank

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/977d9fa7-0f27-4346-8322-e7938f263fac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.