# Path: cms/managers.py
# class BlogPostManager(models.Manager):
#     def by_academic_year(self, year):
#         if isinstance(year, list):
#             return reduce(lambda a,b: a|b, [ self.by_academic_year(x) for x in year ])
#         else:
#             if isinstance(year, str) or isinstance(year, unicode):
#                 year = int(year)
# 
#             lower_limit = datetime.datetime(year, 7, 1)
#             upper_limit = datetime.datetime(year+1, 6, 30)
# 
#             return self.get_query_set().filter(date__gte=lower_limit, date__lte=upper_limit)
# 
# Path: cms/storage.py
# class OverwriteStorage(FileSystemStorage):
# 
#     def get_available_name(self, name):
#         """
#         Returns a filename that's free on the target storage system, and
#         available for new content to be written to.
#         """
#         # If the filename already exists, remove it as if it was a true file system
#         if self.exists(name):
#             os.remove(os.path.join(settings.MEDIA_ROOT, name))
#         return name


import hashlib
import os
from django.db import models
from django.conf import settings
from django.db.models import signals
from django.contrib.auth.models import User
from django.db.models import Q
from cms.managers import BlogPostManager
from cms.storage import OverwriteStorage
    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)

# Path: cms/managers.py
# class BlogPostManager(models.Manager):
#     def by_academic_year(self, year):
#         if isinstance(year, list):
#             return reduce(lambda a,b: a|b, [ self.by_academic_year(x) for x in year ])
#         else:
#             if isinstance(year, str) or isinstance(year, unicode):
#                 year = int(year)
# 
#             lower_limit = datetime.datetime(year, 7, 1)
#             upper_limit = datetime.datetime(year+1, 6, 30)
# 
#             return self.get_query_set().filter(date__gte=lower_limit, date__lte=upper_limit)
# 
# Path: cms/storage.py
# class OverwriteStorage(FileSystemStorage):
# 
#     def get_available_name(self, name):
#         """
#         Returns a filename that's free on the target storage system, and
#         available for new content to be written to.
#         """
#         # If the filename already exists, remove it as if it was a true file system
#         if self.exists(name):
#             os.remove(os.path.join(settings.MEDIA_ROOT, name))
#         return name


# Path: cms/models.py
import hashlib
import os
from django.db import models
from django.conf import settings
from django.db.models import signals
from django.contrib.auth.models import User
from django.db.models import Q
from cms.managers import BlogPostManager
from cms.storage import OverwriteStorage

    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)