list_user_post_permission.tpl 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
{% autoescape off %}
# WARNING
# THIS FILE HAS BEEN AUTOMATICALLY GENERATED
# WITH /backend/generate/generate_backend_files.py
# MODIFY THE FILE ABOVE IF YOUR NOT SATISFIED 
# THIS WARNING DOESN'T APPLY TO .tpl FILES...

from django.conf import settings

ALL_VIEWSETS = {}
{% for model in data %}{% if not model.requires_testing %}{% if model.viewset != 'UserDataViewSet' %}
from backend.models.{{model.import_location}} import {{model.viewset}}
ALL_VIEWSETS["{{model.viewset}}"] = {{model.viewset}}
{% endif %}{% endif %}{% endfor %}

if settings.TESTING:
    {% for model in data %}{% if model.requires_testing %}
    from backend.models.{{model.import_location}} import {{model.viewset}}
    ALL_VIEWSETS["{{model.viewset}}"] = {{model.viewset}}
    {% endif %}{% endfor %}


class Request(object):
    def __init__(self, user, method):
        self.user = user
        self.method = method

def list_user_post_permission(user):
    viewsets_user_can_post = []
    request = Request(user, 'POST')
    for viewset_name in ALL_VIEWSETS:
        viewset = ALL_VIEWSETS[viewset_name]
        user_can_post = True
        for permission_class in viewset.permission_classes:
            if not permission_class.has_permission(None, request, None):
                user_can_post = False
                break
        if user_can_post:
            name = viewset_name.split('ViewSet')[0]
            name = name[0].lower() + name[1:]
            viewsets_user_can_post.append(name)
    return viewsets_user_can_post

{% endautoescape %}