Changeset 3071 for trunk/LeMillTool.py


Ignore:
Timestamp:
10/30/10 19:23:46 (9 years ago)
Author:
jukka
Message:

Fixed tag links in portlets and removed OrderingSearch?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LeMillTool.py

    r3067 r3071  
    11061106        return highlights 
    11071107 
    1108  
    1109          
    1110     def OrderingSearch(self, REQUEST=None, **kw): 
    1111         """ Do multiple catalog searches so that results come out as already ordered """     
    1112         # At this point we should have all of the necessary keywords in kw and something in request too. 
    1113         # Results should be in this order 
    1114         # 1. Materials 
    1115         # 2. Pieces 
    1116         # 3. References 
    1117         # 4. Print resources 
    1118         # 5. Other 
    1119         # 
    1120         # Then, in these are ordered in following fashion: 
    1121         # I Interface language 
    1122         # II User languages (if any) 
    1123         # III Other languages 
    1124         # 
    1125         # This all needs to be done by concatenating results of multiple searches 
    1126         #  
    1127         pc=getToolByName(self,'portal_catalog') 
    1128         form=None 
    1129         if REQUEST and hasattr(REQUEST, 'form'): 
    1130             form=REQUEST.form 
    1131         draft=True 
    1132         public=True 
    1133         sort_on=kw.get('sort_on','') 
    1134         if sort_on: 
    1135             kw['sort_order']='descending' 
    1136         state=kw.get('getState','') 
    1137         if (not isinstance(state, tuple)) and state==('draft','private'): 
    1138             public=False # viewing 'my drafts' 
    1139         elif isinstance(state, dict): 
    1140             state=state['query'] 
    1141              
    1142         # 'Blog style' results and user drafts content shouldn't be ordered by language 
    1143         if sort_on=='getLatestEdit': #and not kw.has_key('Creator')) or not public: 
    1144             results=pc(REQUEST, **kw) 
    1145             return results 
    1146          
    1147         kw_type=kw.get('Type',()) 
    1148         one_type_flag=len(kw_type)==1 
    1149         material_types=('PresentationMaterial', 'MultimediaMaterial', 'PILOTMaterial', 'ExerciseMaterial','LessonPlan', 'SchoolProjectMaterial') 
    1150         material_flag=kw.get('material') 
    1151         content_types=[material_types, ('Piece',), 
    1152             ('LeMillReference',), 
    1153             ('LeMillPrintResource',)] 
    1154         resources_flag=kw.get('resources') 
    1155         all_types=list(content_types) 
    1156         all_types.append(('Activity','Tool','MemberFolder','GroupBlog','BlogPost','Collection')) 
    1157         all_flag= not (one_type_flag or material_flag or resources_flag) 
    1158                          
    1159         # Prepare languages 
    1160         one_language= form.get('Language',[]) or kw.get('Language',[]) or form.get('getLanguage_skills',[]) or kw.get('getLanguage_skills',[]) or None 
    1161         if not one_language: 
    1162             ordered_languages=getToolByName(self,'lemill_usertool').getLanguages()         
    1163             langs = [ x for x in pc.uniqueValuesFor('Language') if x not in ordered_languages] 
    1164             ordered_languages.append(langs) 
    1165          
    1166         if one_type_flag: 
    1167             search_types=[kw_type]               
    1168         elif material_flag: 
    1169             search_types=[material_types] 
    1170         elif resources_flag: 
    1171             search_types=content_types 
    1172         elif all_flag: 
    1173             search_types=all_types  
    1174         results=[] 
    1175  
    1176         if one_type_flag and kw_type==('MemberFolder',) or kw_type==('GroupBlog',): 
    1177             # MemberFolder and GroupBlog results should be in this order: 
    1178             # 1. has coverimage 
    1179             # 2. score 
    1180             # 3. name (not implemented) 
    1181             # print 'Don't bother with languages, as these types have no single language' 
    1182             kw['getHasCoverImage']=True 
    1183             results.append(pc(REQUEST, **kw))            
    1184             kw['getHasCoverImage']=False 
    1185             results.append(pc(REQUEST, **kw)) 
    1186             return LazyCat(results) 
    1187  
    1188         if one_language:     
    1189             for types in search_types: 
    1190                 # materials order: 1.state 2.score 3.date 
    1191                 # methods and tools order: 1.coverimage 2.score 3.date 
    1192                 # print 'Doing search for one specific lang: %s' % kw 
    1193                 kw['Type']=types 
    1194                 if public: 
    1195                     kw['getState']='public' 
    1196                     results.append(pc(REQUEST, **kw)) 
    1197  
    1198                 if draft and types==material_types: 
    1199                     kw['getState']='draft' 
    1200                     results.append(pc(REQUEST, **kw)) 
    1201             return LazyCat(results) 
    1202  
    1203         # searching from all languages 
    1204         for types in search_types: 
    1205             do_drafts=draft and types==material_types 
    1206             kw['Type']=types            
    1207             for languages in ordered_languages: 
    1208                 # print 'Searchable language' 
    1209                 kw['Language']=languages 
    1210                 if public: 
    1211                     kw['getState']='public' 
    1212                     results.append(pc(REQUEST,**kw)) 
    1213                 if do_drafts: 
    1214                     kw['getState']='draft' 
    1215                     results.append(pc(REQUEST,**kw)) 
    1216         return LazyCat(results) 
    1217      
    1218     def splitResultList(self, biglist): 
    1219         """ Splits the search result list according the contents' portal_type. """ 
    1220         results=([], [], [], [], []) 
    1221         for element in biglist: 
    1222             results[MAPPING.get(element.portal_type, 4)].append(element) 
    1223         split_results= [(name, res) for name, res in zip(MAPPING_NAMES, results) if res] 
    1224         return split_results 
    1225      
     1108   
    12261109    def getMaterialTypes(self, no_references=False): 
    12271110        """ returns a list of material types """ 
Note: See TracChangeset for help on using the changeset viewer.