Changeset 647

Show
Ignore:
Timestamp:
04/12/06 15:35:36 (3 years ago)
Author:
pacopablo
Message:

TracBlogPlugin:

  • Added option to hide the "Updated on" line for posts that have been modified
  • Fixed error in date on "Updated on" lines. Closes #305
  • Added num_posts option such that only the last X number of entries will be shown
  • Removed the <hr /> tag after the last post
  • Updated documentation for the [[BlogShow]] macro
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tracblogplugin/0.10/blog/admin.py

    r626 r647  
    6161                        'new_blog_link' : 'New Blog Post', 
    6262                        'first_week_day' : 'SUNDAY', 
     63                        'mark_updated' : 'true', 
    6364                       } 
    6465        if req.method == 'POST': 
     
    9192 '''Calendar Week Start Day''':: 
    9293   name of day that acts as the first day of the week.  Must be full day name. 
     94 '''Mark Updated Posts''':: 
     95   whether or not to mark posts that have been updated with an "Updated on" message. 
    9396 
    9497 '''strftime formatting''':: 
  • tracblogplugin/0.10/blog/templates/blog_admin.cs

    r628 r647  
    4949                </label> 
    5050            </div> 
     51            <div class="field"> 
     52                <label>Mark Updated Posts:<br/> 
     53                    <input type="text" name="mark_updated"  
     54                    value="<?cs var:blogadmin.mark_updated ?>" /> 
     55                </label> 
     56            </div> 
    5157        <div class="buttons"> 
    5258            <input type="submit" value="Apply Changes" /> 
  • tracblogplugin/0.10/blog/templates/blog.cs

    r629 r647  
    5050            </ul> 
    5151        </div> 
    52         <hr width="75%" /> 
     52        <?cs if !  bentry.last ?> 
     53            <hr width="75%" /> 
     54        <?cs /if ?> 
    5355    </div> 
    5456    <?cs /each ?> 
  • tracblogplugin/0.10/blog/web_ui.py

    r632 r647  
    1515# Author: John Hampton <pacopablo@asylumware.com> 
    1616 
     17import sys 
    1718import time 
    1819import datetime 
     
    3132from tractags.parseargs import parseargs 
    3233 
     34BOOLS_TRUE = ['true', 'yes', 'ok', 'on', 'enabled', '1'] 
     35 
    3336__all__ = ['TracBlogPlugin'] 
     37 
     38def bool_val(val): 
     39    """Returns whether or not a values represents a boolen value 
     40 
     41    """ 
     42     
     43    return val.strip().lower() in BOOLS_TRUE 
     44 
    3445 
    3546class TracBlogPlugin(Component): 
     
    3748     
    3849    The list of tags to be shown can be specified as arguments to the macro. 
    39     An options keyword argument of union can be secified.  If specified, then 
    40     the resulting blog will be a {{{union}}} of pages with the specified tags. 
    41     If the {{{union}}} parameter is omitted, then an intersection of the 
    42     specified tags is returned. 
    43  
    4450    If no tags are specified as parameters, then the default 'blog' tag is 
    4551    used. 
     52 
     53    The following options can be specified: 
     54 
     55    '''union''' - Specify whether the join for the tags listed should be a 
     56    union or intersection(default).[[br]] 
     57    '''num_posts''' - Number of posts to display.[[br]] 
     58    '''year''' - Year for which to show posts.[[br]] 
     59    '''month''' - Month for which to show posts.[[br]] 
     60    '''day''' - Day of the month for which to show posts.[[br]] 
     61    '''delta''' - How many days of posts should be shown.[[br]] 
     62    '''mark_update''' - Specify whether to show "Updated on" for posts that 
     63    have been updated.[[br]] 
     64 
     65    If specifying dates with {{{year}}}, {{{month}}}, and/or {{{day}}}, the 
     66    current value is specified if missing.  For example, if {{{day}}} is  
     67    specified but {{{year}}} and {{{month}}} are not, then {{{year}}} will be 
     68    filled in with the current year and {{{month}}} will be filled with the  
     69    current month.  If only {{{year}}} and {{{month}}} are specified, then that 
     70    indicates the whole month is desired. 
     71 
     72    The {{{num_posts}}} options is bounded by the date options if combined. For 
     73    example, if {{{num_posts=5}}} and {{{month=4}}} is specified, it will show  
     74    up to 5 posts from the month of April.  If only 3 posts exist, then only 3  
     75    are shown.  If a date option is not specified, then it will show the last  
     76    {{{num_posts}}} posts. 
    4677 
    4778    === Examples === 
     
    5081    [[BlogShow(blog,pacopablo)]] 
    5182    [[BlogShow(blog,pacopablo,union=True)]] 
     83    [[BlogShow(blog,pacopablo,num_posts=5)]] 
     84    [[BlogShow(blog,pacopablo,month=4,num_posts=5)]] 
     85    [[BlogShow(blog,pacopablo,year=2006,month=4)]] 
     86    [[BlogShow(blog,pacopablo,year=2006,month=4,day=12)]] 
     87    [[BlogShow(blog,pacopablo,delta=5)]] 
     88    [[BlogShow(blog,pacopablo,delta=5,mark_updated=False)]] 
    5289    }}} 
    5390    """ 
     
    102139        tags = req.args.getlist('tag') 
    103140        kwargs = {} 
    104         #for key,value in req.args.items(): 
    105141        for key in req.args.keys(): 
    106142            if key != 'tag': 
    107                 #kwargs[key] = value 
    108143                kwargs[key] = req.args[key] 
    109144            continue 
     
    138173            blog = tags.get_tagged_names(tlist, operation='intersection') 
    139174 
    140         poststart, postend = self._get_time_range(req, **kwargs) 
     175        poststart, postend, default_times = self._get_time_range(req, **kwargs) 
     176        mark_updated = self._choose_value('mark_updated', req, kwargs,  
     177                                          convert=bool_val) 
     178        if not mark_updated and (not isinstance(mark_updated, bool)): 
     179            mark_updated = bool_val(self.env.config.get('blog', 'mark_updated', 
     180                                                         True)) 
     181                        
     182        num_posts = self._choose_value('num_posts', req, kwargs, convert=int) 
     183        self.log.debug('num_posts: %s' % str(num_posts)) 
     184        if num_posts and default_times: 
     185            poststart = sys.maxint 
     186            postend = 0 
    141187        for blog_entry in blog: 
    142188            page = WikiPage(self.env, version=1, name=blog_entry) 
     
    161207                        'comment'   : wiki_to_oneliner(comment, self.env), 
    162208                       } 
    163                 if modified != post_time
     209                if (modified != post_time) and mark_updated
    164210                    data['modified'] = 1 
    165                     mod_str = format_datetime(post_time, format=time_format) 
     211                    mod_str = format_datetime(modified, format=time_format) 
    166212                    data['mod_time'] = mod_str 
    167213                entries[post_time] = data 
    168214            continue 
    169215        tlist = entries.keys() 
    170         # Python 2.4ism 
    171         # tlist.sort(reverse=True) 
    172216        tlist.sort() 
    173217        tlist.reverse() 
     218        if num_posts and (num_posts <= len(tlist)): 
     219            tlist = tlist[:num_posts] 
     220        self.log.debug("tlist: %s" % str(tlist)) 
     221        self.log.debug("last index: %s" % str(tlist[-1])) 
     222        entries[tlist[-1]]['last'] = 1 
    174223        req.hdf['blog.entries'] = [entries[x] for x in tlist] 
    175224        bloglink = self.env.config.get('blog', 'new_blog_link', 'New Blog Post') 
     
    342391        month = self._choose_value('month', req, kwargs, convert=int) 
    343392        day = self._choose_value('day', req, kwargs, convert=int) 
     393        defaults = not (startdate or enddate or delta or year or month or day) 
    344394        now = datetime.datetime.now() 
    345395        oneday = datetime.timedelta(days=1) 
     
    365415            else: 
    366416                end = start - HISTORY 
    367         return start, end 
     417        return start, end, defaults 
    368418 
    369419    def _choose_value(self, key, req, kwargs, convert=None):