Changeset 3126 for trunk


Ignore:
Timestamp:
01/04/11 17:58:01 (9 years ago)
Author:
jukka
Message:

Fixed #2016. It was a bit more tricky than supposed, as catalog cannot be searched for zero values.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/CommonMixIn.py

    r3123 r3126  
    604604                v['editMetadataLink'] = 'login_form' 
    605605            elif canEdit: 
    606                 v['editMetadataLink'] = '%s/base_metadata' % url 
     606                if self.portal_type=='LeMillReference': 
     607                    v['editMetadataLink'] = '%s/edit' % url                 
     608                else: 
     609                    v['editMetadataLink'] = '%s/base_metadata' % url 
    607610            else: 
    608611                v['editMetadataLink'] = '%s/join_a_group' % url         
  • trunk/LeMillCatalogTool.py

    r3094 r3126  
    2525from Products.CMFPlone.UnicodeSplitter import CaseNormalizer as UnicodeCaseNormalizer 
    2626from Products.ZCTextIndex.ZCTextIndex import PLexicon 
    27 from Products.ZCatalog.Lazy import Lazy 
     27from Products.ZCatalog.Lazy import Lazy, LazyMap 
    2828from random import randint 
    2929from config import CONTENT_TYPES, MATERIAL_TYPES, ACTIVITY_TYPES, TOOLS_TYPES, LANGUAGES, LANGUAGES_DICT, TYPE_NAMES, SUBJECT_AREAS_DICT, TARGET_GROUPS_DICT, SUBJECT_AREAS_INVERSE_DICT, TARGET_GROUPS_INVERSE_DICT, COMMUNITY_TYPES, SEARCHABLE_TYPES, DEFAULT_ICONS, TARGET_GROUP 
     
    437437        return 'search' 
    438438 
     439    def getCloudType(self): 
     440        """ """ 
     441        form=self.REQUEST.form 
     442        base=form.get('base','') 
     443        if base in ['tags','subject_area','target_group','language']: 
     444            return base 
    439445 
    440446    def browsingSearch(self, REQUEST=None, **kw):         
     
    455461        keywords.update(src) 
    456462        keywords.update(kw) 
     463 
     464        find_empty_values=keywords.get('empties','') 
     465 
    457466        if 'language' in keywords: 
    458467            if keywords['language']=='all': 
     
    504513                del keywords['portfolio'] 
    505514            elif 'content' in path: 
    506                 keywords['portal_type']=list(CONTENT_TYPES) 
     515                if find_empty_values=='Language': # when browsing content without language set, ignore pieces 
     516                    keywords['portal_type']=list(MATERIAL_TYPES)+['LeMillReference'] 
     517                else: 
     518                    keywords['portal_type']=list(CONTENT_TYPES) 
    507519            elif 'methods' in path: 
    508520                keywords['portal_type']='Activity' 
     
    527539            found=False 
    528540            if 'RSS' in keywords: 
     541                found=True 
     542            elif 'empties' in keywords: 
    529543                found=True 
    530544            elif 'base' in keywords and keywords['base']=='language': 
     
    547561                    del keywords['Language'] 
    548562 
    549         for k in ['base','portfolio','RSS']: 
     563        for k in ['base','portfolio','RSS','empties']: 
    550564            if k in keywords: 
    551565                del keywords[k] 
     
    554568        except ParseError: 
    555569            results = [] 
     570        if find_empty_values: 
     571            results = self.fastFindEmptyValues(results, find_empty_values) 
    556572        return results 
    557573 
     
    736752            new=wakeUpFasterAndCount(results) 
    737753            return dic 
     754 
     755 
     756    def fastFindEmptyValues(self, results, index_to_look): 
     757        """ Takes Lazy results and return those results where the given index returns empty""" 
     758 
     759        t=time.time() 
     760        new_results=[] 
     761 
     762        def safeData(index, key): 
     763            v=index.getEntryForObject(key, []) 
     764            if callable(v): 
     765                return v() 
     766            return v 
     767         
     768        def wakeUpAndFilter(lazy): 
     769            for l in lazy._seq: 
     770                if isinstance(l, Lazy): 
     771                    wakeUpAndFilter(l) 
     772                else: 
     773                    val=safeData(index, l) 
     774                    if not val: 
     775                        new_results.append(l) 
     776        if not results: 
     777            return [] 
     778        index=self._catalog.getIndex(index_to_look) 
     779        wakeUpAndFilter(results) 
     780        print time.time()-t 
     781        assert isinstance(results,LazyMap) 
     782        return LazyMap(results._func, new_results, len(new_results)) 
     783 
    738784 
    739785    def getSomeMetadataForRID(self, rid, md_fields): 
     
    841887        resultlist.sort() 
    842888        return resultlist 
     889 
    843890 
    844891    ########### Front page top lists ############ 
  • trunk/Schemata.py

    r3123 r3126  
    4141 
    4242editing_settings = Schema(( 
    43     StringField('editingMode', 
     43    StringField('editingMode', # Disabled for 3.1, (made invisible) 
    4444              vocabulary = DisplayList(( 
    4545                  ("anybody_can_edit", "Anybody can edit this learning resource"), 
  • trunk/skins/lemill/cloud.pt

    r3054 r3126  
    88    <tal:taggy repeat="wordinfo wordtuples"><tal:taggyvalues define="nicename python:wordinfo[0]; tagsize python:wordinfo[1]; link_url python:wordinfo[2]; "><a tal:attributes="href link_url;class string:size$tagsize" tal:content="nicename" i18n:translate="" /> </tal:taggyvalues></tal:taggy>  
    99  </div> 
     10  <div class="clear" style="height:40px"></div> 
     11  <div class="cloud"> 
     12    <p class="size1" tal:define="cloud_type python:context.portal_catalog.getCloudType()"> 
     13    <a style="text-decoration: underline;" tal:condition="python:cloud_type=='language'" href="browse?language=&empties=Language" i18n:translate="">No language specified</a> 
     14    <a style="text-decoration: underline;" tal:condition="python:cloud_type=='subject_area'" href="browse?subject_area=&empties=getSubject_area" i18n:translate="">No subject area specified</a> 
     15    <a style="text-decoration: underline;" tal:condition="python:cloud_type=='target_group'" href="browse?target_group=&empties=getTarget_group" i18n:translate="">No target group specified</a> 
     16    <a style="text-decoration: underline;" tal:condition="python:cloud_type=='tags'" href="browse?tags=&empties=getTags" i18n:translate="">No tags specified</a> 
     17    </p> 
     18  </div> 
    1019</div> 
    1120 
  • trunk/skins/lemill/widget_chapter.pt

    r3124 r3126  
    7575    <input type="hidden" name="chapter_edited" id="chapter_edited" value="0" tal:attributes="value edit_chapter"/> 
    7676    <input type="hidden" name="chapter_last_edited" id="chapter_last_edited" value="0" tal:attributes="value edit_chapter"/> 
    77     <input type="hidden" name="chapter_type" id="chapter_type" tal:attributes="value python:value[edit_chapter]['type']"/> 
     77    <input type="hidden" name="chapter_type" id="chapter_type" tal:attributes="value python:value and value[edit_chapter]['type']"/> 
    7878   <div class="sortable"> 
    7979   <tal:chapters repeat="chapter value"> 
Note: See TracChangeset for help on using the changeset viewer.