Changeset 632

Show
Ignore:
Timestamp:
04/07/06 17:58:19 (3 years ago)
Author:
pacopablo
Message:

TracBlogPlugin:

  • Finally satisfied with the calendar. Days that have posts are indicated by the red links. Days with out posts, gray links. If you hover over a link, it will tell you how many posts were on that day.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tracblogplugin/0.10/blog/htdocs/css/blog.css

    r628 r632  
    6565 
    6666div.blog-calendar table { 
     67/* 
    6768 border-collapse: collapse; 
     69*/ 
    6870} 
    6971 
    7072div.blog-calendar td { 
    71  padding: 1px
     73 padding: .25em
    7274} 
    7375 
     
    7880td.blog-calendar-current a { 
    7981 color: #000000; 
     82 font-weight: bold; 
    8083} 
     84 
     85a.blog-calendar-title { 
     86 font-size: 130%; 
     87 color: black; 
     88} 
     89 
     90caption.blog-calendar-caption { 
     91 padding-bottom: 4px; 
     92} 
  • tracblogplugin/0.10/blog/templates/blog_calendar.cs

    r629 r632  
    33<?cs def:day_link(year, month, day) ?><?cs var:blog.path_info ?>?year=<?cs var:year ?>&month=<?cs var:month ?>&day=<?cs var:day ?><?cs /def ?> 
    44<?cs def:mon_link(year, month) ?><?cs var:blog.path_info ?>?year=<?cs var:year ?>&month=<?cs var:month ?><?cs /def ?> 
     5<?cs def:year_link(year) ?><?cs var:blog.path_info ?>?year=<?cs var:year ?><?cs /def ?> 
    56<div class="blog-calendar"> 
    6     <table> 
    7         <tr> 
    8             <td><a href="<?cs call:mon_link(blog.date.lastyear,blog.date.month) ?>">&lt;&lt;</a></td> 
    9             <td><a href="<?cs call:mon_link(blog.date.lastmonth.year,blog.date.lastmonth.month) ?>">&lt;</a></td> 
    10             <td colspan="3" align="center"><a href="<?cs call:mon_link(blog.date.year,blog.date.month) ?>"><?cs var:blog.date.monthname ?></a> <?cs var:string.slice(blog.date.year,2,4)?></td> 
    11             <td><a href="<?cs call:mon_link(blog.date.nextmonth.year,blog.date.nextmonth.month)?>">&gt;</a></td> 
    12             <td><a href="<?cs call:mon_link(blog.date.nextyear,blog.date.month) ?>">&gt;&gt;</a></td> 
    13         </tr> 
    14         <tr> 
    15         <?cs each:name = blog.date.daynames ?> 
    16             <td><?cs var:name ?></td> 
    17         <?cs /each ?> 
    18         </tr> 
    19         <?cs each:week = blog.cal ?> 
    20         <tr <?cs if:name(week)==blog.date.week ?> 
    21             class="blog-calendar-current" <?cs /if ?>> 
    22             <?cs each:day = week ?> 
    23             <td <?cs if:day==blog.date.day ?>class="blog-calendar-current"<?cs /if ?>> 
    24             <?cs if:day ?> 
    25             <a href="<?cs call:day_link(blog.date.year, blog.date.month, day) ?>"><?cs var:day ?></a> 
    26             <?cs else ?>&nbsp;<?cs /if ?> 
    27             </td> 
     7    <table cellspacing="0" cellpadding="0"> 
     8        <caption class="blog-calendar-caption"> 
     9            <a href="<?cs call:mon_link(blog.date.lastyear,blog.date.month) ?>">&lt;&lt;</a>&nbsp; 
     10            <a href="<?cs call:mon_link(blog.date.lastmonth.year,blog.date.lastmonth.month) ?>">&lt;</a>&nbsp; 
     11            <a class="blog-calendar-title"  
     12            title="<?cs var:blog.date.monthcount ?> Post(s)" 
     13            href="<?cs call:mon_link(blog.date.year,blog.date.month) ?>"><?cs var:blog.date.monthname ?></a>&nbsp; 
     14            <a class="blog-calendar-title" 
     15            title="<?cs var:blog.date.yearcount ?> Post(s)" 
     16            href="<?cs call:year_link(blog.date.year) ?>"><?cs var:blog.date.year ?></a>&nbsp; 
     17            <a href="<?cs call:mon_link(blog.date.nextmonth.year,blog.date.nextmonth.month)?>">&gt;</a>&nbsp; 
     18            <a href="<?cs call:mon_link(blog.date.nextyear,blog.date.month) ?>">&gt;&gt;</a> 
     19        </caption> 
     20        <thead> 
     21            <tr align="center" class="blog-calendar-header"> 
     22            <?cs each:name = blog.date.daynames ?> 
     23                <th class="blog-calendar-header" scope="col"><b><?cs var:name ?></b></th> 
    2824            <?cs /each ?> 
    29         </tr> 
     25            </tr> 
     26        </thead> 
     27        <tbody> 
     28            <?cs each:week = blog.cal ?> 
     29            <tr align="right" <?cs if:week.num==blog.date.week ?> 
     30                class="blog-calendar-current" <?cs /if ?>> 
     31                <?cs each:day = week.days ?> 
     32                <td <?cs if:day.num==blog.date.day ?>class="blog-calendar-current"<?cs /if ?>> 
     33                <?cs if:day.num ?> 
     34                <a <?cs if:day.count <= 0 ?>class="missing"<?cs /if ?> 
     35                title="<?cs var:day.count ?> Post(s)" 
     36                href="<?cs call:day_link(blog.date.year, blog.date.month, day) ?>"><?cs var:day.num ?></a> 
     37                <?cs else ?>&nbsp;<?cs /if ?> 
     38                </td> 
     39                <?cs /each ?> 
     40            </tr> 
     41        </tbody> 
    3042        <?cs /each ?> 
    3143    </table> 
  • tracblogplugin/0.10/blog/web_ui.py

    r629 r632  
    177177        hidecal = self._choose_value('hidecal', req, kwargs) 
    178178        if not hidecal: 
    179             self._generate_calendar(req
     179            self._generate_calendar(req, tallies
    180180        req.hdf['blog.hidecal'] = hidecal 
    181181        pass 
    182182 
    183     def _generate_calendar(self, req): 
     183    def _generate_calendar(self, req, tallies): 
    184184        """Generate data necessary for the calendar 
    185185 
     
    197197        calendar.setfirstweekday(first_day) 
    198198        cal = calendar.monthcalendar(year, month) 
     199        statcal = {} 
     200        for week_num, week in enumerate(cal): 
     201            statcal[week_num] = { 
     202                                'num' : week_num, 
     203                                'days' : [] 
     204                               } 
     205            for day_num in week: 
     206                d = { 'num' : day_num, 
     207                      'count' : 0, } 
     208                if day_num: 
     209                    d['count'] = self._get_tally(tallies, year, month, day_num) 
     210                statcal[week_num]['days'].append(d) 
     211                continue 
     212            continue 
    199213        week = [week for week in xrange(0,len(cal)-1) if day in cal[week]][0] 
    200214        monthname = format_datetime(time.mktime(baseday.timetuple()),  
     
    217231        hdfdate = { 
    218232                    'year' : year, 
     233                    'yearcount' : self._get_tally(tallies, year), 
    219234                    'month' : month,  
     235                    'monthcount' : self._get_tally(tallies, year, month), 
    220236                    'day' : day, 
    221237                    'lastyear' : lastyear, 
     
    229245                                    'month' : nextmonth, 
    230246                                  }, 
    231                     'daynames' : calendar.weekheader(1).split(), 
     247                    'daynames' : calendar.weekheader(2).split(), 
    232248                    'week' : week, 
    233249                    'monthname' : monthname, 
    234250                  } 
    235251        req.hdf['blog.date'] = hdfdate 
    236         req.hdf['blog.cal'] = cal 
     252        req.hdf['blog.cal'] = statcal 
    237253        req.hdf['blog.path_info'] = self.env.href(req.path_info) 
    238254        pass 
    239255 
     256    def _get_tally(self, tallies, year, month=None, day=None): 
     257        """Return the tally for the given date 
     258 
     259        Returns 0 if no tally is present 
     260 
     261        """ 
     262        if day and month: 
     263            try:     
     264                tally = tallies[year][month][day]['total'] 
     265            except KeyError: 
     266                tally = 0 
     267        elif month: 
     268            try:     
     269                tally = tallies[year][month]['total'] 
     270            except KeyError: 
     271                tally = 0 
     272        else: 
     273            try:     
     274                tally = tallies[year]['total'] 
     275            except KeyError: 
     276                tally = 0 
     277        return tally 
     278 
    240279    def _add_to_tallies(self, tallies,  post_time, page_name): 
    241280        """Create a running tally of blog page data 
    242281 
    243282        """ 
     283        def _gen_blank_year_total(year): 
     284            blank_year = {} 
     285            for month in xrange(1, 13): 
     286                mrange = calendar.monthrange(year, month)[1]  
     287                blank_year[month] = { 'pages' : [], 
     288                                      'total' : 0, } 
     289                for day in xrange(1, mrange + 1): 
     290                    blank_year[month][day] = { 'total' : 0, 
     291                                               'pages' : [], } 
     292                    continue 
     293                continue 
     294            return blank_year 
    244295        d = datetime.datetime.fromtimestamp(post_time) 
    245296        try: 
     
    251302            tallies[d.year]['pages'].append(page_name) 
    252303        except (KeyError, AttributeError): 
    253             tallies[d.year] = {'total' : 1, 
    254                                'pages' : [page_name]} 
    255         try: 
    256             tallies[d.year][d.month]['total'] += 1 
    257             tallies[d.year][d.month]['pages'].append(page_name) 
    258         except (KeyError, AttributeError): 
    259             tallies[d.year][d.month] = {'total' : 1, 
    260                                         'pages' : [page_name]} 
    261         try: 
    262             tallies[d.year][d.month][d.day]['total'] += 1 
    263             tallies[d.year][d.month][d.day]['pages'].append(page_name) 
    264         except (KeyError, AttributeError): 
    265             tallies[d.year][d.month][d.day] = {'total' : 1, 
    266                                                'pages' : [page_name]} 
     304            tallies[d.year] = _gen_blank_year_total(d.year) 
     305            tallies[d.year]['total'] = 1 
     306            tallies[d.year]['pages'] = [page_name] 
     307        tallies[d.year][d.month]['total'] += 1 
     308        tallies[d.year][d.month]['pages'].append(page_name) 
     309        tallies[d.year][d.month][d.day]['total'] += 1 
     310        tallies[d.year][d.month][d.day]['pages'].append(page_name) 
    267311        pass 
    268312