day71 菜单的排序 点击被选中
菜单的排序:(给菜单设置权重,权重高的让他显示在上面)

from django import template
from django.conf import settings
from collections import OrderedDict
import re register = template.Library() @register.inclusion_tag('menu.html')
def menu(request):
menu_dict = request.session[settings.MENU_SESSION_KEY] order_dict=OrderedDict()
ret=sorted(menu_dict,key=lambda x:menu_dict[x]['weight'],reverse=True) for i in ret:
order_dict[i] = menu_dict[i] for r in order_dict.values():
r['class']='hide'
for i in r['children']:
if re.match(r'^{}$'.format(i['url']),request.path_info):
i['class'] = 'active'
r['class']= '' return {'menu_list': order_dict.values()}
menu.html文件
<div class="multi-menu">
{% for menu in menu_list %}
<div class="item">
<div class="title"><i class="fa {{ menu.icon }}"></i> {{ menu.title }}</div>
<div class="body">
{% for child in menu.children %}
<a href="{{ child.url }}""> {{ child.title }} </a>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
menu.html标签
点击后被选中

自定义标签.rbac.py中 :
from django import template
from django.conf import settings
from collections import OrderedDict
import re register = template.Library() @register.inclusion_tag('menu.html')
def menu(request):
menu_dict = request.session[settings.MENU_SESSION_KEY] order_dict=OrderedDict()
ret=sorted(menu_dict,key=lambda x:menu_dict[x]['weight'],reverse=True) for i in ret:
order_dict[i] = menu_dict[i] for r in order_dict.values(): for i in r['children']:
if re.match(r'^{}$'.format(i['url']),request.path_info):
i['class'] = 'active' return {'menu_list': order_dict.values()}
menu.html文件
{#<div class="static-menu">#}
{#{% for menu in menu_list %}#}
{# <a href="{{ menu.url }}" class="{{ menu.class }}">#}
{# <span class="icon-wrap"><i class="fa {{ menu.icon }}"></i></span> {{ menu.title }}</a>#}
{#{% endfor %}#}
{#</div>#}
<div class="multi-menu">
{% for menu in menu_list %}
<div class="item">
<div class="title"><i class="fa {{ menu.icon }}"></i> {{ menu.title }}</div>
<div class="body">
{% for child in menu.children %}
<a href="{{ child.url }}" class="{{ child.class }}"> {{ child.title }} </a>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
day71 菜单的排序 点击被选中的更多相关文章
- android selector 背景选择器的使用, button (未点击,点击,选中保持状态)效果实现
android selector 背景选择器的使用, button (未点击,点击,选中保持状态)效果实现 首先看到selector的属性: android:state_focus ...
- jquery点击图片选中特效
jquery点击图片选中特效 点击在线预览效果
- 点击盒子选中里面的单选框,并给盒子添加相应样式,美化单选框、复选框样式css用法,响应式滴
pc效果图: 移动端效果图: 代码直接上: <!DOCTYPE html> <html> <head> <meta http-equiv="Cont ...
- Taro button点击切换选中状态
1.引入组件 2.state中设置选中状态 // button按钮的默认选中,0代表选中 state = { currentIndex: 0 } 3.设置class的样式,点击更改选中 selectN ...
- radio点击一下选中,再点击恢复未选状态
radio点击一下选中,再点击恢复未选状态 实现方式1: <input type="radio" id="cat" name="ca ...
- Selenium操作示例——鼠标悬停显示二级菜单,再点击二级菜单或下拉列表
这两天在玩python中selenium,遇到一个问题,就是鼠标移动到页面中某按钮或菜单,自动弹出二级菜单或下拉菜单,再自动点击其中的二级菜单或下拉列表. 首先,手工操作:打开母校的主页 http:/ ...
- 【WPF】右键菜单ContextMenu可点击区域太小的问题
问题描述 正常使用右键菜单ContextMenu时,如果菜单项是不变的,可以直接在XAML中写死,如下是给一个Button按钮添加了右键菜单功能. <Button Content="T ...
- unity3d点击屏幕选中物体
原文 http://blog.csdn.net/mycwq/article/details/19906335 前些天接触unity3d,想实现点击屏幕选中物体的功能.后来研究了下,实现原理就是检测从 ...
- juey点击tr选中里面的radio
//点击一行选中银行卡 $("tr").bind("click",function(){ $("input:radio").attr(&qu ...
随机推荐
- Python基础(二)自定义函数
1.判断字符串,内容是否为数字 我们用python:xlrd读Excel内容时,本来只是输入的整数字,经常读出来的是float类型 我们需要自动转成整型,意思就是说,读出来的和我们输入的一样,但是,我 ...
- ASP.NET Core 之 Identity
Claims:声明(证件单元)Identity:身份Principal:当事人Authentication :认证Authorization:授权 http://www.cnblogs.com/sav ...
- C++重载操作符自增自减
#include <iostream> using namespace std; class Test { friend ostream& operator<<(ost ...
- 3D印表機 零件採購資訊
3D印表機 零件採購資訊 採購資訊僅供參考,零件的品質由店家擔保! 壓克力 螺絲螺帽牙條 高來螺絲 滑套.軸承 五連軸承 掏寶-廣發軸承 光軸 掏寶-廣發軸承 彈簧 雅銅彈簧 鐵氟龍製品 馬達 電源供 ...
- IntelliJ Idea 使用笔记
1. IntelliJ Idea解决Could not autowire. No beans of 'xxxx' type found的错误提示. 原因可能有两个,第一个是IntellijIDEA本身 ...
- docker 启动失败
今天本来想抽空弄一下openshift,新装了个centos结果docker起不来. 报错内容: [root@master docker]# systemctl status docker.servi ...
- AES,BigInteger,MD5加密
http://tool.oschina.net/apidocs/apidoc?api=jdk-zh package cn.com.gome.cashier.web; import java.lang. ...
- jmeter如何玩之badboy + jmeter并发性能测试
今天下班时公司安排了一个同事来对项目做集群性能测试,怀着对性能测试的好奇心,下班后没有着急离开,而是等待 那位同事的到来,然后在旁边学习了下如何使用Badboy和jmeter做性能测试. 1. 软件介 ...
- BDD数据集(mask_rcnn)1
mask_rcnn中ballon的例子 classsification VS semantic segmention VS object detection VS instance segmentio ...
- C#中抽象类和接口的区别与使用
一.抽象类: 抽象类是特殊的类,只是不能被实例化:除此以外,具有类的其他特性:重要的是抽象类可以包括抽象方法,这是普通类所不能的.抽象方法只能声明于抽象类中,且不包含任何实现,派生类必须覆盖它们.另外 ...