コード例 #1
0
ファイル: viewutils.py プロジェクト: vivek2010/django_bolts
    def process(self,queryset,request,field_name):                
        alias = request.REQUEST.get(field_name,None)
        name_map = self.name_map                    
#        if not alias or alias not in name_map and self.default: alias = self.default        
        field_list = OrderedDict()          
        field_list.current = {'label':name_map.get(self.default)}    
        selected = False
        for name,label in name_map.iteritems():                    
            used = False
            value = name            
            if alias == name:
                used = True
                call = self.actions[ label ]                
                if call:
                    queryset = call(request,queryset)                
            field = HelperField(value,used,request,field_name,label)
            field_list[name]=field
            if used:
                selected = True
                field_list.current = field
        if not selected:
            fl = field_list.get(self.default)
            if fl:
                fl.used = True                                      
        return field_list,queryset
コード例 #2
0
ファイル: viewutils.py プロジェクト: vivek2010/django_bolts
    def process(self,queryset,request,field_name):            
        sorter_list = OrderedDict()                
        alias = request.REQUEST.get(field_name,None)    
        desc = True
        name_map = self.name_map
        sorter_list.current = {'label':name_map.get(self.default)}
        if alias :
            if alias[0] != '-':
                desc = False
            else :
                alias = alias[1:]        
#        if alias not in name_map and self.default: 
#            alias = self.default
#            desc= True           
        for name,label in name_map.iteritems():             
            order = True            
            used = False                        
            if alias == name:  
                used = True  
                order = desc                   
                key = self.actions[ label ]             
                if callable(key): 
                    queryset = key(request,queryset,order)
                elif key:
                    if key[0] == '-':
                        key = key[1:]
                        way = not order
                    else:
                        way = order
                    queryset = queryset.order_by( "%s%s"%( "" if way else "-" ,key ) ) 
            value = name#"%s%s"%( "" if order else "-" , name)                                       
            sort_field = HelperField(value,used,request,field_name,label,asc=order)
            sorter_list[name] = sort_field
            if used:
                sorter_list.current = sort_field  
            else:
                sorter_list.current = {'label':''}                                                              
        return sorter_list, queryset