NicholasStudt

Changeset 346


Ignore:
Timestamp:
06/30/10 22:21:37 (2 months ago)
Author:
nicholas
Message:

First attempts and calendar template tag and fixing the tags rss feed.
Testing still needed.

Location:
Python/blog/trunk/blog
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • Python/blog/trunk/blog/feeds.py

    r108 r346  
    33from django.contrib.comments.feeds import LatestCommentFeed 
    44from django.core.urlresolvers import reverse 
     5from django.shortcuts import get_object_or_404 
     6 
    57from blog.models import Entry 
    68 
     
    1921        return Entry.objects.published()[:10] 
    2022 
    21  
    2223class LatestEntriesByTag(Feed): 
    2324    _site = Site.objects.get_current() 
    24     title = '%s feed' % _site.name 
    25     description = '%s posts feed.' % _site.name 
    2625 
    27     def link(self): 
    28         return reverse('entry_index') 
     26    def get_object(self, request, tag): 
     27        return get_object_or_404(Tag, slug=tag) 
     28 
     29    def title(self, obj): 
     30        return '%s feed: %s' % [_site.name, obj.tag] 
     31 
     32    def description(self, obj): 
     33        return '%s posts feed for %s' % [_site.name, obj.tag] 
     34 
     35    def link(self, obj): 
     36        return reverse('tag_list', ident=obj.tag) 
    2937 
    3038    def item_pubdate(self, obj): 
    3139        return obj.pub_date 
    3240 
    33     def items(self): 
     41    def items(self, obj): 
    3442        return Entry.objects.published()[:10] 
    3543 
  • Python/blog/trunk/blog/templatetags/blog.py

    r325 r346  
     1import calendar 
     2import datetime 
     3 
    14from django import template 
    25from django.core.exceptions import ObjectDoesNotExist 
     
    108111    return EntryList(bits[1], type, limit, author) 
    109112entry_archive = register.tag(entry_archive) 
     113 
     114def month_cal(year=datetime.date.today().year, month=datetime.date.today().month):  
     115 
     116    # Fix this to just use calendar.* for all math. 
     117 
     118    first_day_of_month = datetime.date(year, month, 1) 
     119    last_day_of_month = calendar.monthrange(year, month) 
     120    first_day_of_calendar = first_day_of_month - datetime.timedelta(first_day_of_month.weekday()) 
     121 
     122    last_day_of_calendar = datetime.date(year,month,last_day_of_month[1]) + datetime.timedelta(7 - calendar.weekday(year,month,last_day_of_month[1])) 
     123 
     124    event_list = Entry.objects.published(pub_date__gte=first_day_of_calendar, pub_date__lte=last_day_of_calendar) 
     125 
     126    month_cal = [] 
     127    week = [] 
     128    week_headers = [] 
     129 
     130    i = 0 
     131    day = first_day_of_calendar 
     132    while day <= last_day_of_calendar: 
     133        if i < 7: 
     134            week_headers.append(day) 
     135        cal_day = {} 
     136        cal_day['day'] = day 
     137        cal_day['event'] = False 
     138        for event in event_list: 
     139            if day >= event.start_date.date() and day <= event.end_date.date(): 
     140                cal_day['event'] = True 
     141        if day.month == month: 
     142            cal_day['in_month'] = True 
     143        else: 
     144            cal_day['in_month'] = False   
     145        week.append(cal_day) 
     146        if day.weekday() == 6: 
     147            month_cal.append(week) 
     148            week = [] 
     149        i += 1 
     150        day += datetime.timedelta(1) 
     151 
     152    return {'calendar': month_cal, 'headers': week_headers} 
     153 
     154register.inclusion_tag('blog/tags/calendar.html')(month_cal) 
Note: See TracChangeset for help on using the changeset viewer.