예제 #1
0
파일: sites.py 프로젝트: richardxia/baya
 def __init__(self, *args, **kwargs):
     super(NestedGroupsAdminSite, self).__init__(*args, **kwargs)
     _admin_registry.add(self)
     all_groups = self._get_required_baya_groups()
     if all_groups is not None:
         self.index = requires(all_groups)(self.index)
         self.app_index = requires(all_groups)(self.app_index)
예제 #2
0
 def __init__(self, *args, **kwargs):
     super(NestedGroupsAdminSite, self).__init__(*args, **kwargs)
     _admin_registry.add(self)
     all_groups = self._get_required_baya_groups()
     if all_groups is not None:
         self.index = requires(all_groups)(self.index)
         self.app_index = requires(all_groups)(self.app_index)
예제 #3
0
    def get_urls(self):
        """Ensure that urls included in get_urls() are behind requires().

        We need to fix the include() logic for admin URLs. Django admin isn't
        very extensible, so we have to call super, remove the url patterns
        for model_admins that have a _gate, and replace the pattern with
        a properly built include behind the model admin's gate.

        Would be a lot easier if django exposed something like
        get_patterns_for_app(app_label), but noooooo.
        """
        # We have to maintain the URL ordering due to the way URLs are resolved
        # TODO - Test this, can lead to heisenbugs
        urls = OrderedDict(
            (urlp.regex.pattern, urlp)
            for urlp in super(NestedGroupsAdminSite, self).get_urls())
        for model, model_admin in self._get_admins_with_gate():
            if hasattr(model._meta, 'module_name'):
                model_name = model._meta.module_name
            elif hasattr(model._meta, 'model_name'):
                model_name = model._meta.model_name
            else:
                raise ValueError(
                    "Model Admin is missing a module or model name.")
            pattern = (r'^%s/%s/' % (model._meta.app_label, model_name))
            urls[pattern] = url(
                pattern,
                requires(get=model_admin._gate.get_requires,
                         post=model_admin._gate.post_requires)(include(
                             model_admin.urls)))
        return urls.values()
예제 #4
0
파일: sites.py 프로젝트: richardxia/baya
    def get_urls(self):
        """Ensure that urls included in get_urls() are behind requires().

        We need to fix the include() logic for admin URLs. Django admin isn't
        very extensible, so we have to call super, remove the url patterns
        for model_admins that have a _gate, and replace the pattern with
        a properly built include behind the model admin's gate.

        Would be a lot easier if django exposed something like
        get_patterns_for_app(app_label), but noooooo.
        """
        # We have to maintain the URL ordering due to the way URLs are resolved
        # TODO - Test this, can lead to heisenbugs
        urls = OrderedDict((urlp.regex.pattern, urlp) for urlp in
                           super(NestedGroupsAdminSite, self).get_urls())
        for model, model_admin in self._get_admins_with_gate():
            if hasattr(model._meta, 'module_name'):
                model_name = model._meta.module_name
            elif hasattr(model._meta, 'model_name'):
                model_name = model._meta.model_name
            else:
                raise ValueError(
                    "Model Admin is missing a module or model name.")
            pattern = (
                r'^%s/%s/' %
                (model._meta.app_label, model_name))
            urls[pattern] = url(
                pattern,
                requires(get=model_admin._gate.get_requires,
                         post=model_admin._gate.post_requires)(
                             include(model_admin.urls)))
        return urls.values()
예제 #5
0
파일: sites.py 프로젝트: kreneskyp/baya
    def get_urls(self):
        """Ensure that urls included in get_urls() are behind requires().

        We need to fix the include() logic for admin URLs. Django admin isn't
        very extensible, so we have to call super, remove the url patterns
        for model_admins that have a _gate, and replace the pattern with
        a properly built include behind the model admin's gate.

        Would be a lot easier if django exposed something like
        get_patterns_for_app(app_label), but noooooo.
        """
        # We have to maintain the URL ordering due to the way URLs are resolved
        # TODO - Test this, can lead to heisenbugs
        urls = OrderedDict(
            (_get_regex(urlp), urlp)
            for urlp in super(NestedGroupsAdminSite, self).get_urls())
        for model, model_admin in self._get_admins_with_gate():
            if hasattr(model._meta, 'module_name'):
                model_name = model._meta.module_name
            elif hasattr(model._meta, 'model_name'):
                model_name = model._meta.model_name
            else:
                raise ValueError(
                    "Model Admin is missing a module or model name.")
            pattern = (r'^%s/%s/' % (model._meta.app_label, model_name))

            # The pattern is used as a key and must be formatted to match what is already in urls
            # else it will be added as a new pattern. When the newly constructed pattern doesn't
            # match, both the old and new version of the pattern will be in the urls. The old
            # pattern will match requests because it's earlier in the list.
            if django.VERSION[0] == 1:
                compiled_pattern = pattern
            elif django.VERSION[0] >= 2:
                # django >= 2.0 pattern must be compiled into regex
                if sys.version_info[0] == 3 and sys.version_info[1] <= 6:
                    # python 3.0 through 3.6 must escape slashes in the regex
                    escaped_pattern = pattern.replace('/', '\/')
                else:
                    escaped_pattern = pattern
                compiled_pattern = re.compile(escaped_pattern)

            urls[compiled_pattern] = url(
                pattern,
                requires(get=model_admin._gate.get_requires,
                         post=model_admin._gate.post_requires)(include(
                             model_admin.urls)))
        return list(urls.values())
예제 #6
0
    def __init__(self, *args, **kwargs):
        super(BayaModelAdmin, self).__init__(*args, **kwargs)
        if hasattr(self, '_gate'):
            self._gate.get_requires &= self.READ
        else:
            requires(self.READ).decorate_admin(self)

        self.add_view = requires(self.CREATE)(self.add_view)
        self.changelist_view = requires(get=self.READ, post=self.UPDATE)(
            self.changelist_view)
        self.change_view = requires(get=self.READ, post=self.UPDATE)(
            self.change_view)
        self.delete_view = requires(self.DELETE)(self.delete_view)
예제 #7
0
 def admin_view(self, view, cacheable=False):
     fn = super(NestedGroupsAdminSite, self).admin_view(view, cacheable)
     all_groups = self._get_required_baya_groups()
     if all_groups is not None:
         fn = requires(all_groups)(fn)
     return fn
예제 #8
0
from django.conf.urls import url

from baya.permissions import requires

from .views import my_view
from .views import my_undecorated_view


urlpatterns = [
    url(r'^my_view/$', my_view, name='nested_nested_my_view'),
    url(r'^my_undecorated_view/$',
        requires('A')(my_undecorated_view),
        name='nested_nested_my_undecorated_view'),
]
예제 #9
0
from django.conf.urls import include, url

from baya.permissions import requires

from .views import my_view
from .views import my_undecorated_view
from . import nested_urls2

app_name = 'nested1'

urlpatterns = [
    url(r'^my_view/$', my_view, name='nested1_my_view'),
    url(r'^my_undecorated_view/$',
        requires('aa')(my_undecorated_view),
        name='nested1_my_undecorated_view'),
    url(r'^nested2/',
        requires('aa')(include(nested_urls2))),
]
예제 #10
0
from django.conf.urls import include, url

from baya.permissions import requires

from .views import my_view
from .views import my_undecorated_view
from . import nested_urls2


urlpatterns = [
    url(r'^my_view/$', my_view, name='nested1_my_view'),
    url(r'^my_undecorated_view/$',
        requires('aa')(my_undecorated_view),
        name='nested1_my_undecorated_view'),
    url(r'^nested2/', requires('aa')(include(nested_urls2))),
]
예제 #11
0
from django.conf.urls import url

from baya.permissions import requires

from .views import my_view
from .views import my_undecorated_view

urlpatterns = [
    url(r'^my_view/$', my_view, name='nested_nested_my_view'),
    url(r'^my_undecorated_view/$',
        requires('A')(my_undecorated_view),
        name='nested_nested_my_undecorated_view'),
]
예제 #12
0
파일: sites.py 프로젝트: richardxia/baya
 def admin_view(self, view, cacheable=False):
     fn = super(NestedGroupsAdminSite, self).admin_view(view, cacheable)
     all_groups = self._get_required_baya_groups()
     if all_groups is not None:
         fn = requires(all_groups)(fn)
     return fn
예제 #13
0
 def has_delete_permission(self, request, obj=None):
     return has_permission(requires(self.DELETE), request.user, 'post')
예제 #14
0
 def has_change_permission(self, request, obj=None):
     return has_permission(requires(self.UPDATE), request.user, 'post')
예제 #15
0
 def has_add_permission(self, request):
     return has_permission(requires(self.CREATE), request.user, 'post')