# Path: apps/ot/util.py
# def vote_available(user):
#     if is_vote_period():
#         return is_freshman(user)
#     else:
#         return is_tester(user)
# 
# Path: apps/ot/models/user.py
# class Freshman(models.Model):
#     def __str__(self):
#         return self.user.username
# 
#     user = models.OneToOneField(User, related_name='freshman')
#     voted_clubs = models.ManyToManyField(Club, related_name='votes')
# 
#     sizes = (
#         ('S', 'S'),
#         ('M', 'M'),
#         ('L', 'L'),
#         ('XL', 'XL'),
#         ('2XL', '2XL'),
#         ('3XL', '3XL'),
#     )
#     tsize = models.CharField(null=False, max_length=5, choices=sizes)
# 
#     BAND_VOTE_LIMIT = 4
#     NON_BAND_VOTE_LIMIT = 3
# 
#     def vote_limit_exceeded(self, is_band):
#         return self.voted_clubs.filter(is_band=is_band).count() > 5


from django.views.generic import TemplateView
from ..util import vote_available
from ..models.user import Freshman


class MainView(TemplateView):
    template_name = 'main.html'

    def get_context_data(self, **kwargs):
        context = super(MainView, self).get_context_data(**kwargs)

        context['available'] = vote_available(self.request.user)

        if hasattr(self.request.user, 'freshman'):
            voted_clubs = self.request.user.freshman.voted_clubs
            context['voted_band'] = voted_clubs.filter(is_band=True)
            context['voted_non_band'] = voted_clubs.filter(is_band=False)
        else:
            context['voted_band'] = []
            context['voted_non_band'] = []

        context['band_limit'] = Freshman.BAND_VOTE_LIMIT
        context['non_band_limit'] = Freshman.NON_BAND_VOTE_LIMIT

# Path: apps/ot/util.py
# def vote_available(user):
#     if is_vote_period():
#         return is_freshman(user)
#     else:
#         return is_tester(user)
# 
# Path: apps/ot/models/user.py
# class Freshman(models.Model):
#     def __str__(self):
#         return self.user.username
# 
#     user = models.OneToOneField(User, related_name='freshman')
#     voted_clubs = models.ManyToManyField(Club, related_name='votes')
# 
#     sizes = (
#         ('S', 'S'),
#         ('M', 'M'),
#         ('L', 'L'),
#         ('XL', 'XL'),
#         ('2XL', '2XL'),
#         ('3XL', '3XL'),
#     )
#     tsize = models.CharField(null=False, max_length=5, choices=sizes)
# 
#     BAND_VOTE_LIMIT = 4
#     NON_BAND_VOTE_LIMIT = 3
# 
#     def vote_limit_exceeded(self, is_band):
#         return self.voted_clubs.filter(is_band=is_band).count() > 5


# Path: apps/ot/views/main.py
from django.views.generic import TemplateView
from ..util import vote_available
from ..models.user import Freshman



class MainView(TemplateView):
    template_name = 'main.html'

    def get_context_data(self, **kwargs):
        context = super(MainView, self).get_context_data(**kwargs)

        context['available'] = vote_available(self.request.user)

        if hasattr(self.request.user, 'freshman'):
            voted_clubs = self.request.user.freshman.voted_clubs
            context['voted_band'] = voted_clubs.filter(is_band=True)
            context['voted_non_band'] = voted_clubs.filter(is_band=False)
        else:
            context['voted_band'] = []
            context['voted_non_band'] = []

        context['band_limit'] = Freshman.BAND_VOTE_LIMIT
        context['non_band_limit'] = Freshman.NON_BAND_VOTE_LIMIT

        context['total_limit'] = Freshman.BAND_VOTE_LIMIT + Freshman.NON_BAND_VOTE_LIMIT