Skip to content

Commit

Permalink
项目打包
Browse files Browse the repository at this point in the history
  • Loading branch information
wkunzhi committed Dec 13, 2019
1 parent bd551be commit db81eb4
Show file tree
Hide file tree
Showing 136 changed files with 23,191 additions and 112 deletions.
Binary file added .DS_Store
Binary file not shown.
178 changes: 101 additions & 77 deletions .idea/workspace.xml

Large diffs are not rendered by default.

37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
> Django 2
> 这是对之前一个项目的升级 [旧版项目地址](https://github.com/wkunzhi/rbac-stark-crm)
包含可拆卸 权限组件rbac 与 stark插件 可以单独取出代码并运用到任意后端开发项目中。 该套CRM系统就是用rbac组件+stark组件开发的实例项目

# 开发环境
- Django 2.2.1
- Python 3.6

# 目录
- rbac **权限与菜单组件**
- stark **路由组件**
- web **业务逻辑**
- static **静态文件**


# 截图
**菜单分配**
![](https://zok-blog.oss-cn-hangzhou.aliyuncs.com/images/20191213/WX20191213-110528.png)
**用户管理**
![](https://zok-blog.oss-cn-hangzhou.aliyuncs.com/images/20191213/WX20191213-110557.png)
**权限分配**
![](https://zok-blog.oss-cn-hangzhou.aliyuncs.com/images/20191213/WX20191213-110617.png)
**菜单路由**
![](https://zok-blog.oss-cn-hangzhou.aliyuncs.com/images/20191213/WX20191213-110714.png)
**信息管理**
![](https://zok-blog.oss-cn-hangzhou.aliyuncs.com/images/20191213/WX20191213-110731.png)


# rbac 组件使用
[**rbac 说明文档**](https://blog.zhangkunzhi.com/2019/12/13/crm%E7%BB%84%E4%BB%B6%E4%BD%BF%E7%94%A8/index.html)

# stark 组件使用说明

[**stark 说明文档**](https://blog.zhangkunzhi.com/2019/12/13/stark%E7%BB%84%E4%BB%B6%E4%BD%BF%E7%94%A8/index.html)

# QQ群
![](https://zok-blog.oss-cn-hangzhou.aliyuncs.com/2019/11/18/wx201911181627012x.png)
Binary file modified rbac/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file modified rbac/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file modified rbac/forms/__pycache__/menu.cpython-37.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion rbac/forms/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class MenuModelForm(forms.ModelForm):
"""一级菜单FORM"""
class Meta:
model = models.Menu
fields = ['title', 'icon']
fields = ['title', 'sort', 'icon']
# 给标签加上boot样式
widgets = {
'title': forms.TextInput(attrs={'class': 'layui-input'}), # 渲染的时候添加class属性
'sort': forms.TextInput(attrs={'class': 'layui-input'}),
'icon': forms.RadioSelect( # 转换成单选框 Radio
choices=icon_list,
attrs={'class': 'clearfix'} # boot中清除浮动
Expand Down
Binary file modified rbac/middlewares/__pycache__/rbac.cpython-37.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion rbac/middlewares/rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ def process_request(self, request):
break

if not flag:
return HttpResponse('你的账户无权访问该页面')
return HttpResponse('你的账户无权访问该页面<a href="/login">点击登录</a>')
Binary file not shown.
3 changes: 3 additions & 0 deletions rbac/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class Menu(models.Model):
"""
title = models.CharField(verbose_name='菜单名称', max_length=32)
# 图标http://fontawesome.dashgame.com/

sort = models.IntegerField(verbose_name='显示顺序', default=1)

icon = models.CharField(verbose_name='菜单图标', max_length=32) # blank 为admin后台可以空

def __str__(self):
Expand Down
Binary file modified rbac/service/__pycache__/init_permission.cpython-37.pyc
Binary file not shown.
29 changes: 17 additions & 12 deletions rbac/service/init_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ def init_permission(current_user, request):
"""
# 取用户【权限+菜单信息】放入session。
# __多对多跨表 _单跨表查询 distinct()去重 isnull==False不为空
permission_queryset = current_user.roles.filter(permissions__isnull=False).values("permissions__id",
"permissions__url",
"permissions__title",
"permissions__name",
"permissions__pid__id",
"permissions__pid__title",
"permissions__pid__url",
"permissions__menu_id",
"permissions__menu__icon",
"permissions__menu__title",
).distinct()
permission_queryset = current_user.roles.filter(permissions__isnull=False).order_by(
'permissions__menu__sort').values("permissions__id",
"permissions__url",
"permissions__title",
"permissions__name",
"permissions__pid__id",
"permissions__pid__title",
"permissions__pid__url",
"permissions__menu_id",
"permissions__menu__icon",
"permissions__menu__title",
"permissions__menu__sort",
).distinct()
# 取菜单+权限
permission_dict = {} # 储存权限信息(包含对应归属菜单 id,自己本身是菜单就为null)key 就是权限表中的别名name
menu_dict = {} # 储存(一二级)菜单信息 字典
Expand All @@ -44,7 +46,8 @@ def init_permission(current_user, request):
if not menu_id: # null则不是菜单
continue

node = {'id': item['permissions__id'], 'title': item['permissions__title'], 'url': item['permissions__url']} # 当前二级菜单信息存遍历node,便于调用
node = {'id': item['permissions__id'], 'title': item['permissions__title'],
'url': item['permissions__url']} # 当前二级菜单信息存遍历node,便于调用
if menu_id in menu_dict:
# 有1级菜单id就添加append
menu_dict[menu_id].get('children').append(node)
Expand All @@ -53,9 +56,11 @@ def init_permission(current_user, request):
menu_dict[menu_id] = {
'title': item['permissions__menu__title'], # 取menu表内对应一级菜单名
'icon': item['permissions__menu__icon'],
'sort': item['permissions__menu__sort'],
'children': [node, ]
}

print('权限', permission_dict)
print('菜单', menu_dict)
request.session[settings.MENU_SESSION_KEY] = menu_dict
request.session[settings.PERMISSION_SESSION_KEY] = permission_dict
2 changes: 1 addition & 1 deletion rbac/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<a href="javascript:;"> <cite><i class="layui-icon layui-icon-username"></i> 用户</cite> <span
class="layui-nav-more"></span></a>
<dl class="layui-nav-child layui-anim layui-anim-upbit">
<dd layadmin-event="logout" style="text-align: center;"><a>退出</a></dd>
<dd layadmin-event="logout" style="text-align: center;"><a href="\logout">退出</a></dd>
</dl>
</li>
<li class="layui-nav-item layui-hide-xs" lay-unselect="">
Expand Down
2 changes: 1 addition & 1 deletion rbac/templates/rbac/menu_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div class="layui-card">
<div class="layui-card-header">菜单说明</div>
<div class="layui-card-body">
后台左侧菜单可以在此处进行配置 | 图标设置清空缓存才生效<br>
修改菜单后需要重新登录才生效!!<br>
可进行操作右包含: 增加、删除、修改一级二级菜单
</div>
</div>
Expand Down
Binary file modified rbac/templatetags/__pycache__/rbac.cpython-37.pyc
Binary file not shown.
4 changes: 1 addition & 3 deletions rbac/templatetags/rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ def multi_menu(request):
:return:
"""
menu_dict = request.session[settings.MENU_SESSION_KEY]

'''必须排序,因为dict 是无序的,可能后台显示菜单每次顺序不同'''
# 对字典的key进行排序
key_list = sorted(menu_dict)

key_list = menu_dict
# 空的有序字典
ordered_dict = OrderedDict()

Expand Down
8 changes: 0 additions & 8 deletions rbac/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
url(r'^role/edit/(?P<pk>\d+)/$', role.role_edit, name='role_edit'), # {% url 'rbac:role_edit' %}
url(r'^role/del/(?P<pk>\d+)/$', role.role_del, name='role_del'), # {% url 'rbac:role_edit' %}

# 用户管理
# path('user/list/', user.user_list, name='user_list'),
# path('user/add/', user.user_add, name='user_add'),
# url(r'^user/edit/(?P<pk>\d+)/$', user.user_edit, name='user_edit'), # {% url 'rbac:user_edit' %}
# url(r'^user/del/(?P<pk>\d+)/$', user.user_del, name='user_del'), # {% url 'rbac:user_edit' %}
# url(r'^user/reset/password/(?P<pk>\d+)/$', user.user_reset_pwd, name='user_reset_pwd'), # {% url 'rbac:user_edit' %}


# 权限分配菜单(一级菜单)
path('menu/list/', menu.menu_list, name='menu_list'),
path('menu/add/', menu.menu_add, name='menu_add'),
Expand Down
Binary file modified rbac/views/__pycache__/menu.cpython-37.pyc
Binary file not shown.
3 changes: 1 addition & 2 deletions rbac/views/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def menu_list(request):
:param request:
:return:
"""
menus = models.Menu.objects.all()

menus = models.Menu.objects.order_by('sort')
menu_id = request.GET.get('mid') # 这是str类型 用户选择的一级菜单
second_sid = request.GET.get('sid') # 用户选择的二级菜单,做选中状态
# print('second_sid', second_sid)
Expand Down
Empty file added stark/__init__.py
Empty file.
Binary file added stark/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added stark/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file added stark/__pycache__/apps.cpython-37.pyc
Binary file not shown.
Binary file added stark/__pycache__/models.cpython-37.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions stark/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
9 changes: 9 additions & 0 deletions stark/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.apps import AppConfig
from django.utils.module_loading import autodiscover_modules


class StarkConfig(AppConfig):
name = 'stark'

def ready(self):
autodiscover_modules('stark')
1 change: 1 addition & 0 deletions stark/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# by [email protected]
Empty file.
6 changes: 6 additions & 0 deletions stark/forms/widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# by [email protected]
from django import forms


class DateTimePickerInput(forms.TextInput):
template_name = 'stark/forms/widgets/datetime_picker.html'
Empty file added stark/migrations/__init__.py
Empty file.
Binary file added stark/migrations/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions stark/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Binary file added stark/service/__pycache__/v1.cpython-37.pyc
Binary file not shown.
Loading

0 comments on commit db81eb4

Please sign in to comment.