1

我有以下简单的看法。有什么办法可以让它更有活力吗?

# ...

if 'folding' not in request.session:
    request.session['folding'] = {'shop':False,'users':False,'chat':False}

# ...

def update_folding_view(request,category,is_folded):
    if request.is_ajax():
        folding = request.session['folding']
        if 'shop' in category:
            folding.shop = is_folded
        if 'users' in category:
            folding.users = is_folded
        if 'chat' in category:
            folding.chat = is_folded
        request.session['folding'] = folding
    else:
        raise Http404
4

1 回答 1

4

这就是我得到的:

from collections import defaultdict

...

if 'folding' not in request.session:
    request.session['folding'] = defaultdict(bool)

...

def update_folding_view(request, category, is_folded):
    if not request.is_ajax():
         raise Http404
    for item in category:             
        request.session['folding'][item] = is_folded
于 2012-10-09T15:33:45.423 回答