python - Permissions for a site only -


I have a multilingual Django project. Every language is a separate subdomain so we use the "site" application and Have decided to create a separate site for.

On that project, I also have a "page" application, which is similar to CMS. Users can create pages containing content and they will appear on the appropriate language site.

I am now looking to be able to manage advanced permissions. What I need to do is, in the Admin app, a user only allows to create and update pages for one (or more) specific language / site.

What would be the cleaner to do something like this

Edit: Chris I

, I am making a decorator who checks whether the user is appropriate for the user or not the group who is reaching Lang, Chris accepts the answer for this example. In the "normal" view, I do the following:

  def view (self): # if you want to return Return_to_presson ('Page1', {} , See requestcontent (request)) = group_require (see)  

If the user is in the group, then that method will return, otherwise it will return a "login denied" error.

And in my admin, I do the following:

  class PageAdmin (admin.ModelAdmin): list_display = ('title', 'published') field = [( None, {'field': ['title', 'slug', 'whatever_field_use_heave']}), DEF is_ad_promotion (auto, request): return_group_required (requested) Admin.site.register (page, pageadmin) < / Code> 

where in_group_required is similarly the group_required method described above but if we have access or not, then only true or false return on the basis of its basis Will come

And because we use them very much in the previous examples, you will tell here what I have in my group and group-wise methods

  def group_required ( Return_decorator def in_group (request): language (func): def _decorator (request, * args, ** kwargs): if not in_group (request): return HttpResponse ("login denied") return func (* args, ** kwargs) Language.objects.get (site__domain__exact = request.get_host ()) for group in group.group.all (): if request.user () in group.user_set.all: return correct return incorrect  

You add per group / group of languages ​​and groups accordingly.

Then, you can check whether the request.user.groups belongs to the group. (You can do this with the decorator:

  def group_required (func): def _decorator (request, * args, ** kwargs): hostname = request.META.get ('HTTP_HOST' ) Lang = hostname.split (".") [0] If request.user.groups do not have a gender: return HttpResponse ("Access denied") return func (* args, ** kwargs) _decorator  < / Pre> 

(Correct / Modify the code according to your needs ...)


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -