Skip to content

Instantly share code, notes, and snippets.

@hanleybrand
Last active August 29, 2015 14:17
Show Gist options
  • Save hanleybrand/637452f34e67048a907e to your computer and use it in GitHub Desktop.
Save hanleybrand/637452f34e67048a907e to your computer and use it in GitHub Desktop.
shell plus output of an issue with rooibos.access.functions
from django.contrib.auth.models import AnonymousUser
from rooibos.storage.models import Storage
from rooibos.access.functions import filter_by_access
u = User.objects.get(pk=1)
au = AnonymousUser()
q = Storage
qo = Storage.objects.all()
print(u, au, q, qo)

(<User: admin>, <django.contrib.auth.models.AnonymousUser object at 0x1066e1fd0>, <class 'rooibos.storage.models.Storage'>, [<Storage: store>])

ok = filter_by_access(u, Storage, read=True, write=False, manage=False)

DEBUG user = admin, queryset = <class 'rooibos.storage.models.Storage'>, read = True, write = False, manage = False

nok = filter_by_access(au, Storage, read=True, write=False, manage=False)

DEBUG user = AnonymousUser, queryset = <class 'rooibos.storage.models.Storage'>, read = True, write = False, manage = False

Traceback (most recent call last): File "<console>", line 1, in <module> File "/Users/hanley/Dev/hacking-mdid3/rooibos/access/functions.py", line 126, in filter_by_access model_type = ContentType.objects.get_for_model(queryset) File "/Users/hanley/.virtualenvs/7_1_ognajD/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 42, in get_for_model opts = self._get_opts(model, for_concrete_model) File "/Users/hanley/.virtualenvs/7_1_ognajD/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 27, in _get_opts model = model._meta.concrete_model AttributeError: 'QuerySet' object has no attribute '_meta'

sok = filter_by_access(u, qo, read=True, write=False, manage=False)

DEBUG user = admin, queryset = [<Storage: store>], read = True, write = False, manage = False

nsok = filter_by_access(u, qo, read=True, write=False, manage=False)

DEBUG user = admin, queryset = [<Storage: store>], read = True, write = False, manage = False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment