Skip to content

Commit

Permalink
增加系统菜单和自定义菜单并存
Browse files Browse the repository at this point in the history
  • Loading branch information
newpanjing committed Apr 24, 2019
1 parent 9157339 commit e228943
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
5 changes: 5 additions & 0 deletions QUICK.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ simpleui内置了一个默认的首页,只是由简单的快捷导航与最近
## 自定义菜单

### system_keep 保留系统菜单
该字段用于告诉simpleui,是否需要保留系统默认的菜单,默认为False,不保留。
如果改为True,自定义和系统菜单将会并存

### menus说明

|字段|说明|
Expand All @@ -231,6 +235,7 @@ simpleui内置了一个默认的首页,只是由简单的快捷导航与最近
### 例子
```python
SIMPLEUI_CONFIG = {
'system_keep':False,
'menus': [{
'name': 'Simpleui',
'icon': 'fas fa-code',
Expand Down
49 changes: 27 additions & 22 deletions simpleui/templatetags/simpletags.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,30 +161,35 @@ def menus(context):
# return request.user.has_perm("%s.%s" % (opts.app_label, codename))

config = get_config('SIMPLEUI_CONFIG')

app_list = context.get('app_list')
for app in app_list:
models = []
if app.get('models'):
for m in app.get('models'):
models.append({
'name': str(m.get('name')),
'icon': get_icon(m.get('object_name')),
'url': m.get('admin_url'),
'addUrl': m.get('add_url'),
'breadcrumbs': [str(app.get('name')), str(m.get('name'))]
})

module = {
'name': str(app.get('name')),
'icon': get_icon(app.get('app_label')),
'models': models
}
data.append(module)

# 如果有menu 就读取,没有就调用系统的
if config and 'menus' in config:
data=config.get('menus')
pass
else:
app_list = context.get('app_list')
for app in app_list:
models = []
if app.get('models'):
for m in app.get('models'):
models.append({
'name': str(m.get('name')),
'icon': get_icon(m.get('object_name')),
'url': m.get('admin_url'),
'addUrl': m.get('add_url'),
'breadcrumbs': [str(app.get('name')), str(m.get('name'))]
})

module = {
'name': str(app.get('name')),
'icon': get_icon(app.get('app_label')),
'models': models
}
data.append(module)
if 'system_keep' in config:
temp = config.get('menus')
for i in temp:
data.append(i)
else:
data = config.get('menus')

return '<script type="text/javascript">var menus={}</script>'.format(json.dumps(data))

Expand Down

0 comments on commit e228943

Please sign in to comment.