# Path: cms/models.py
# class Member(models.Model):
#     GROUP_CHOICES = (
#         (u'graduate', u'Graduate'),
#         (u'undergraduate', u'Undergraduate'),
#         (u'faculty', u'Faculty')
#     )
# 
#     CLASS_CHOICES = (
#         (u'freshman', u'Freshman'),
#         (u'sophomore', u'Sophomore'),
#         (u'junior', u'Junior'),
#         (u'senior', u'Senior')
#     )
# 
#     STATUS_EMPTY    = 0 # this member is pending "creation" by its owner
#     STATUS_ACTIVE   = 1 # this member has been created
#     STATUS_ARCHIVED = 2 # this member has been archived and is frozen
# 
#     STATUS_CHOICES  = (
#         (STATUS_EMPTY, u'Empty'),
#         (STATUS_ACTIVE, u'Active'),
#         (STATUS_ARCHIVED, u'Archived')
#     )
# 
#     user            = models.ForeignKey(User, related_name='profile', unique=True)
#     group           = models.CharField(max_length=255, choices=GROUP_CHOICES)
#     classification  = models.CharField(max_length=255, choices=CLASS_CHOICES, blank=True)
#     hometown        = models.CharField(max_length=255, blank=True)
#     interests       = models.TextField(blank=True)
#     homepage        = models.URLField(blank=True)
#     blurb           = models.TextField(blank=True)
#     image           = models.ImageField(upload_to=make_member_image_name, storage=OverwriteStorage(), blank=True)
#     status          = models.IntegerField(choices=STATUS_CHOICES)
#     #activation_key  = models.CharField(max_length=255, blank=True)
# 
#     def __unicode__(self):
#         return unicode(self.user.get_full_name())
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('cms:profile_url', (self.pk,), {})
# 
#     def generate_hashed_email(self):
#         return hashlib.md5(self.user.email).hexdigest()
# 
#     def get_coordinated_projects(self):
#         return Project.objects.filter(pk__in=ProjectMember.objects.filter(member__pk=self.pk, is_coordinator=True).values_list('project__pk', flat=True))
# 
#     @staticmethod
#     def get_possible_project_members():
# 	    # need to allow member one year old as well since activity status is predicated on project membership
# 	    # but you can't create a project for a new year without a project coordinator
#         # hence, the one year offset avoids the chicken-and-the-egg problem
#         #return Member.objects.filter(Q(status=Member.STATUS_ACTIVE) | Q(pk__in=ProjectMember.objects.filter(project__year__gte= \
#         #    settings.CURRENT_YEAR-1).distinct().values_list('member'))).order_by('user__first_name', 'user__last_name')
#         return Member.objects.exclude(status=Member.STATUS_ARCHIVED).order_by('user__first_name', 'user__last_name')
# 
#     class Meta:
#         verbose_name        = 'member'
#         verbose_name_plural = 'members'
#         ordering            = ['user__first_name']
# 
# class BlogPost(models.Model):
#     author          = models.ForeignKey(Member)
#     title           = models.CharField(max_length=255)
#     date            = models.DateTimeField(auto_now_add=True)
#     edit_date       = models.DateTimeField(auto_now=True)
#     post            = models.TextField(help_text='HTML is allowed')
#     tags            = models.ManyToManyField(Tag, blank=True, related_name='blogposts')
# 
#     objects         = BlogPostManager()
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('cms:blog_post_url', (), {'pk': self.author.pk, 'blog_pk': self.pk})
# 
#     def __unicode__(self):
#         return unicode('%s by %s' % (self.title, self.author))
# 
#     class Meta:
#         verbose_name        = 'blog post'
#         verbose_name_plural = 'blog posts'
#         ordering            = ['-date']


from django.contrib.syndication.views import Feed, FeedDoesNotExist
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from cms.models import Member, BlogPost

class UserBlogFeed(Feed):

    description_template = "blogs/blog_rss.html"

    def get_object(self, request, **kwargs):

# Path: cms/models.py
# class Member(models.Model):
#     GROUP_CHOICES = (
#         (u'graduate', u'Graduate'),
#         (u'undergraduate', u'Undergraduate'),
#         (u'faculty', u'Faculty')
#     )
# 
#     CLASS_CHOICES = (
#         (u'freshman', u'Freshman'),
#         (u'sophomore', u'Sophomore'),
#         (u'junior', u'Junior'),
#         (u'senior', u'Senior')
#     )
# 
#     STATUS_EMPTY    = 0 # this member is pending "creation" by its owner
#     STATUS_ACTIVE   = 1 # this member has been created
#     STATUS_ARCHIVED = 2 # this member has been archived and is frozen
# 
#     STATUS_CHOICES  = (
#         (STATUS_EMPTY, u'Empty'),
#         (STATUS_ACTIVE, u'Active'),
#         (STATUS_ARCHIVED, u'Archived')
#     )
# 
#     user            = models.ForeignKey(User, related_name='profile', unique=True)
#     group           = models.CharField(max_length=255, choices=GROUP_CHOICES)
#     classification  = models.CharField(max_length=255, choices=CLASS_CHOICES, blank=True)
#     hometown        = models.CharField(max_length=255, blank=True)
#     interests       = models.TextField(blank=True)
#     homepage        = models.URLField(blank=True)
#     blurb           = models.TextField(blank=True)
#     image           = models.ImageField(upload_to=make_member_image_name, storage=OverwriteStorage(), blank=True)
#     status          = models.IntegerField(choices=STATUS_CHOICES)
#     #activation_key  = models.CharField(max_length=255, blank=True)
# 
#     def __unicode__(self):
#         return unicode(self.user.get_full_name())
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('cms:profile_url', (self.pk,), {})
# 
#     def generate_hashed_email(self):
#         return hashlib.md5(self.user.email).hexdigest()
# 
#     def get_coordinated_projects(self):
#         return Project.objects.filter(pk__in=ProjectMember.objects.filter(member__pk=self.pk, is_coordinator=True).values_list('project__pk', flat=True))
# 
#     @staticmethod
#     def get_possible_project_members():
# 	    # need to allow member one year old as well since activity status is predicated on project membership
# 	    # but you can't create a project for a new year without a project coordinator
#         # hence, the one year offset avoids the chicken-and-the-egg problem
#         #return Member.objects.filter(Q(status=Member.STATUS_ACTIVE) | Q(pk__in=ProjectMember.objects.filter(project__year__gte= \
#         #    settings.CURRENT_YEAR-1).distinct().values_list('member'))).order_by('user__first_name', 'user__last_name')
#         return Member.objects.exclude(status=Member.STATUS_ARCHIVED).order_by('user__first_name', 'user__last_name')
# 
#     class Meta:
#         verbose_name        = 'member'
#         verbose_name_plural = 'members'
#         ordering            = ['user__first_name']
# 
# class BlogPost(models.Model):
#     author          = models.ForeignKey(Member)
#     title           = models.CharField(max_length=255)
#     date            = models.DateTimeField(auto_now_add=True)
#     edit_date       = models.DateTimeField(auto_now=True)
#     post            = models.TextField(help_text='HTML is allowed')
#     tags            = models.ManyToManyField(Tag, blank=True, related_name='blogposts')
# 
#     objects         = BlogPostManager()
# 
#     @models.permalink
#     def get_absolute_url(self):
#         return ('cms:blog_post_url', (), {'pk': self.author.pk, 'blog_pk': self.pk})
# 
#     def __unicode__(self):
#         return unicode('%s by %s' % (self.title, self.author))
# 
#     class Meta:
#         verbose_name        = 'blog post'
#         verbose_name_plural = 'blog posts'
#         ordering            = ['-date']


# Path: cms/feeds.py
from django.contrib.syndication.views import Feed, FeedDoesNotExist
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from cms.models import Member, BlogPost


class UserBlogFeed(Feed):

    description_template = "blogs/blog_rss.html"

    def get_object(self, request, **kwargs):

        return get_object_or_404(Member, pk=kwargs.get('pk', None))