Changeset 632
- Timestamp:
- 04/07/06 17:58:19 (3 years ago)
- Files:
-
- tracblogplugin/0.10/blog/htdocs/css/blog.css (modified) (2 diffs)
- tracblogplugin/0.10/blog/templates/blog_calendar.cs (modified) (1 diff)
- tracblogplugin/0.10/blog/web_ui.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tracblogplugin/0.10/blog/htdocs/css/blog.css
r628 r632 65 65 66 66 div.blog-calendar table { 67 /* 67 68 border-collapse: collapse; 69 */ 68 70 } 69 71 70 72 div.blog-calendar td { 71 padding: 1px;73 padding: .25em; 72 74 } 73 75 … … 78 80 td.blog-calendar-current a { 79 81 color: #000000; 82 font-weight: bold; 80 83 } 84 85 a.blog-calendar-title { 86 font-size: 130%; 87 color: black; 88 } 89 90 caption.blog-calendar-caption { 91 padding-bottom: 4px; 92 } tracblogplugin/0.10/blog/templates/blog_calendar.cs
r629 r632 3 3 <?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 ?> 4 4 <?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 ?> 5 6 <div class="blog-calendar"> 6 <table> 7 <tr> 8 <td><a href="<?cs call:mon_link(blog.date.lastyear,blog.date.month) ?>"><<</a></td> 9 <td><a href="<?cs call:mon_link(blog.date.lastmonth.year,blog.date.lastmonth.month) ?>"><</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)?>">></a></td> 12 <td><a href="<?cs call:mon_link(blog.date.nextyear,blog.date.month) ?>">>></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 ?> <?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) ?>"><<</a> 10 <a href="<?cs call:mon_link(blog.date.lastmonth.year,blog.date.lastmonth.month) ?>"><</a> 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> 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> 17 <a href="<?cs call:mon_link(blog.date.nextmonth.year,blog.date.nextmonth.month)?>">></a> 18 <a href="<?cs call:mon_link(blog.date.nextyear,blog.date.month) ?>">>></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> 28 24 <?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 ?> <?cs /if ?> 38 </td> 39 <?cs /each ?> 40 </tr> 41 </tbody> 30 42 <?cs /each ?> 31 43 </table> tracblogplugin/0.10/blog/web_ui.py
r629 r632 177 177 hidecal = self._choose_value('hidecal', req, kwargs) 178 178 if not hidecal: 179 self._generate_calendar(req )179 self._generate_calendar(req, tallies) 180 180 req.hdf['blog.hidecal'] = hidecal 181 181 pass 182 182 183 def _generate_calendar(self, req ):183 def _generate_calendar(self, req, tallies): 184 184 """Generate data necessary for the calendar 185 185 … … 197 197 calendar.setfirstweekday(first_day) 198 198 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 199 213 week = [week for week in xrange(0,len(cal)-1) if day in cal[week]][0] 200 214 monthname = format_datetime(time.mktime(baseday.timetuple()), … … 217 231 hdfdate = { 218 232 'year' : year, 233 'yearcount' : self._get_tally(tallies, year), 219 234 'month' : month, 235 'monthcount' : self._get_tally(tallies, year, month), 220 236 'day' : day, 221 237 'lastyear' : lastyear, … … 229 245 'month' : nextmonth, 230 246 }, 231 'daynames' : calendar.weekheader( 1).split(),247 'daynames' : calendar.weekheader(2).split(), 232 248 'week' : week, 233 249 'monthname' : monthname, 234 250 } 235 251 req.hdf['blog.date'] = hdfdate 236 req.hdf['blog.cal'] = cal252 req.hdf['blog.cal'] = statcal 237 253 req.hdf['blog.path_info'] = self.env.href(req.path_info) 238 254 pass 239 255 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 240 279 def _add_to_tallies(self, tallies, post_time, page_name): 241 280 """Create a running tally of blog page data 242 281 243 282 """ 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 244 295 d = datetime.datetime.fromtimestamp(post_time) 245 296 try: … … 251 302 tallies[d.year]['pages'].append(page_name) 252 303 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) 267 311 pass 268 312
