CRM - 权限
一、引入权限组件
引入权限组件 rbac
settings: 'rbac.apps.RbacConfig',
中间件: 'rbac.service.rbac.ValidPermission',
员工表UserInfo和rbac.User表关联 一对一
UserInfo中的用户名和密码也可删了,只留rbac.User中的用户名和密码。
user = models.OneToOneField("rbac.User", null=True)
makemigrations
migrate
二、分配权限
权限组
分配权限
角色分配
用户分配
rbac/stark.py
# -*- coding:utf-8 -*- from stark.service.stark import site,ModelStark from .models import * class UserConfig(ModelStark): list_display = ["name",'roles'] site.register(User,UserConfig) class RoleConfig(ModelStark): list_display = ["title","permission"] site.register(Role,RoleConfig) class PermissionConfig(ModelStark): list_display = ["id","title","url","group","action"] site.register(Permission, PermissionConfig) site.register(PermissionGroup)
三、登录、引入中间件
不同的用户具有不同的权限
知识点
登录
url(r'^login/', views.login), ------------------------------------- from django.shortcuts import render,HttpResponse # Create your views here. from rbac.models import User from rbac.service.permission import initial_session def login(request): if request.method == "POST": user = request.POST.get("user") pwd = request.POST.get("pwd") user = User.objects.filter(name=user,pwd=pwd).first() if user: request.session["user_id"] = user.pk # 注册权限到session中 initial_session(user,request) return HttpResponse("登录成功") return render(request,'login.html',locals())
引入中间件
'rbac.service.rbac.ValidPermission',
模板继承
例如:
{% extends 'base.html' %} {% block con %} <h4>我的客户</h4> <ul> {% for customer_distrubute in customer_distrubute_list %} <li> {{ customer_distrubute.customer }} -----{{ customer_distrubute.date|date:'Y-m-d' }} -----{{ customer_distrubute.get_status_display }} </li> {% endfor %} </ul> {% endblock %}
四、code
原始版