Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(3)  |  Call(2)  |  Derive(0)  |  Import(1)
Build permission name for model_class (like 'app.add_model'). 

        def build_permission_name(model_class, prefix):
    """ Build permission name for model_class (like 'app.add_model'). """
    model_name = model_class._meta.object_name.lower()
    app_label = model_class._meta.app_label
    action_name = prefix
    perm = '%s.%s_%s' % (app_label, action_name, model_name)
    return perm
        


src/d/j/django-services-0.0.8/django_services/service/base.py   django-services(Download)
# encoding: utf-8
import logging
import numbers
from .core import BaseService, CheckMethodPermissions, build_permission_name, \
    nocheckpermission
        LOG.debug(u'Querying %s by filters=%s', self.model_class.__name__, filters)
        query = self.__queryset__()
        perm = build_permission_name(self.model_class, 'view')
        query_with_permission = filter(lambda o: self.user.has_perm(perm, obj=o), query)
        ids = map(lambda o: o.pk, query_with_permission)
                raise self.model_class.DoesNotExist()
 
        perm = build_permission_name(self.model_class, 'view')
        if not self.user.has_perm(perm, obj=obj):
            raise PermissionDenied(u'User %s has no permission %s for object %s' % (self.user, perm, obj))