Changeset 3055 for trunk


Ignore:
Timestamp:
10/07/10 15:08:55 (10 years ago)
Author:
jukka
Message:

Recent views now sort by edit/created date and display the time to last change/creation.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LeMillCatalogTool.py

    r3054 r3055  
    132132        d_list=[] 
    133133        lutool=getToolByName(self, 'lemill_usertool') 
     134        ltool=getToolByName(self, 'lemill_tool') 
    134135        url_base=getToolByName(self, 'portal_url')() 
    135  
     136        created=False 
     137        edited=False 
     138        if hasattr(self, 'REQUEST') and hasattr(self.REQUEST, 'form'): 
     139            form=self.REQUEST.form 
     140            if form: 
     141                created= 'created' in form 
     142                edited='edited' in form 
    136143        if hasattr(batch._sequence, '_seq'): 
    137144            print 'using fast metadata to build results' 
    138             seq=list(batch._sequence._seq[batch.start:batch.end]) 
    139             print time.time()-t 
    140             md=self.fastMetadata(seq, ['rid','getHasCoverImage','getNicename','portal_type','getLocation_country','getTags', 'Language','listCreators']) 
    141             print time.time()-t 
     145            seq=list(batch._sequence._seq[batch.start-1:batch.end]) 
     146            keys=['rid','getHasCoverImage','getNicename','portal_type','getLocation_country','getTags', 'Language','listCreators'] 
     147            if created: 
     148                keys.append('created') 
     149            elif edited: 
     150                keys.append('getLatestEdit') 
     151            md=self.fastMetadata(seq, keys) 
    142152            for item in md: 
    143153                if item[3] not in TYPE_NAMES: 
    144                     print 'rejected item:', item  
     154                    print 'rejected item:', item 
     155                    raise hell 
    145156                    continue 
    146157                d={'url':self.getpath(item[0]), 
     
    152163                    'language':item[6], 
    153164                    'authors':item[7]} 
     165                if created: 
     166                    d['created']=item[8] # These are in weird DateIndex format, difficult to map to actual dates 
     167                elif edited: 
     168                    d['edited']=item[8] 
    154169                d_list.append(d) 
     170            if created or edited: 
     171                now=time.gmtime() # mirrors DateIndex's conversion script to provide a compatible 'now' 
     172                now= ( ( ( ( now[0] * 12 + now[1] ) * 31 + now[2] ) * 24 + now[3] ) * 60 + now[4] ) 
     173                useDateIndex=True                           
    155174        else: # batch has already been converted to catalog Brains object 
    156175            print 'using Brains objects to build results' 
     
    164183                    'language':item.Language, 
    165184                    'authors':item.listCreators}                   
     185                if created: 
     186                    d['created']=item.created 
     187                elif edited: 
     188                    d['edited']=item.getLatestEdit 
    166189                d_list.append(d) 
     190            now=time.time() 
     191            useDateIndex=False 
    167192        tag_base='/'.join((url_base,'search?index_type=tags&q=')) 
    168193        lang_base='/'.join((url_base,'search?language=')) 
    169194        country_base='/'.join((url_base,'community/browse?country=')) 
     195         
    170196        # Manipulate raw index data to something more useful 
    171197        for item in d_list: 
     
    186212                item['country_link']=''.join((country_base,item['country'])) 
    187213            item['readable_type']=TYPE_NAMES.get(item['readable_type'], None)[0] 
    188  
     214            if 'created' in item:  
     215                item['timedif']=ltool.getTimeDifference(item['created'], now=now, useDateIndex=useDateIndex) 
     216            elif 'edited' in item: 
     217                item['timedif']=ltool.getTimeDifference(item['edited'], now=now, useDateIndex=useDateIndex) 
    189218        print 'result batch creation took: ',time.time()-t 
    190219        return d_list 
     
    447476        if 'created' in keywords: 
    448477            keywords['created']={'query': self.ZopeTime()-int(keywords['created']), 'range':'min'} 
     478            keywords['sort_on']='created' 
    449479        if 'edited' in keywords: 
    450480            keywords['getLatestEdit']={'query': self.ZopeTime()-int(keywords['edited']), 'range':'min'} 
     481            keywords['sort_on']='getLatestEdit' 
    451482            del keywords['edited'] 
    452483        if not 'Language' in keywords: 
  • trunk/LeMillTool.py

    r3052 r3055  
    946946        return d 
    947947         
    948     def getTimeDifference(self,modtime, seconds=False): 
     948    def getTimeDifference(self,modtime, seconds=False, now=0, useDateIndex=False): 
    949949        """ Returns difference between now and given time in dictionary""" 
    950         now=time.time() 
    951         modtime=DateTime(modtime).timeTime() 
    952         diff=int(now-modtime) 
     950        if not now: 
     951            now=time.time()                     
     952        if useDateIndex: 
     953            diff=int(now-modtime)*60 
     954        else: 
     955            modtime=DateTime(modtime).timeTime() 
     956            diff=int(now-modtime) 
    953957        if seconds: 
    954958            return diff 
     
    962966                break 
    963967        return dict 
    964  
    965  
    966968 
    967969    def stripHTML(self, html): 
  • trunk/skins/lemill/resource_list_macro.pt

    r3053 r3055  
    242242        <div class="list_data_box"> 
    243243            <p><b><a href="" tal:attributes="href item/url" tal:content="item/title" >Title</a></b><br/> 
    244             <tal:block i18n:translate="" content="item/readable_type">Resource type</tal:block><br/> 
     244            <tal:block i18n:translate="" content="item/readable_type">Resource type</tal:block><tal:block condition="python:'created' in item" tal:define="timedif item/timedif | nothing" >, <tal:tr i18n:translate="label_created">created</tal:tr> <metal:use_nicetimes use-macro="here/macros_timedifference/macros/days_ago" /></tal:block><tal:block condition="python:'edited' in item" tal:define="timedif item/timedif | nothing" >, <tal:tr i18n:translate="label_created">edited</tal:tr> <metal:use_nicetimes use-macro="here/macros_timedifference/macros/days_ago" /></tal:block><br/> 
    245245            <tal:block condition="python:item['authors'] and len(item['authors'])>1"><tal:tr i18n:translate="label_authors">Authors</tal:tr>: <tal:block tal:repeat="author item/authors"><a href="" tal:attributes="href python:author[1]" tal:content="python:author[0]">name</a><tal:block condition="not:repeat/author/end">, </tal:block></tal:block><br/></tal:block><tal:block condition="python:item['authors'] and len(item['authors'])==1"><tal:tr i18n:translate="label_author">Author</tal:tr>: <a href="" tal:attributes="href python:item['authors'][0][1]" tal:content="python:item['authors'][0][0]">name</a><br/></tal:block> 
    246  
    247246            <tal:block condition="item/country"><tal:tr i18n:translate="label_location">Location</tal:tr>: <a href="" tal:content="item/country" tal:attributes="href item/country_link">Country</a><br/></tal:block> 
    248247            <tal:block condition="item/tags"><tal:tr i18n:translate="label_tags">Tags</tal:tr>: <tal:block tal:repeat="tag item/tags"><a href="" tal:attributes="href python:tag[1]" tal:content="python:tag[0]">tag</a><tal:block condition="not:repeat/tag/end">, </tal:block></tal:block><br/></tal:block> 
Note: See TracChangeset for help on using the changeset viewer.