# Path: apps/ot/forms.py
# class TSizeForm(ModelForm):
#     class Meta:
#         model = Freshman
#         fields = ("tsize",)
# 
#     def __init__(self, *args, **kwargs):
#         super(TSizeForm, self).__init__(*args, **kwargs)
#         self.fields['tsize'].widget.attrs.update({'class': 'form-control'})
# 
# Path: apps/ot/util.py
# def vote_available(user):
#     if is_vote_period():
#         return is_freshman(user)
#     else:
#         return is_tester(user)
# 
# def is_tester(user):
#     if not user.is_authenticated or not hasattr(user, 'portal_info'):
#         return False
# 
#     return user.portal_info.ku_std_no in (
#         "20110208",
#         "20180379",
#         "20180419",
#         "20180058",
#         "20180634",
#         "20180154",
#     )
# 
# Path: apps/ot/models/club.py
# class Club(models.Model):
#     """
#     동아리 정보
#     """
# 
#     class Meta:
#         verbose_name = '동아리 정보'
#         verbose_name_plural = '동아리 정보(들)'
# 
#     def __str__(self):
#         return str(self.name)
# 
#     name = models.CharField(
#         max_length=63,
#         verbose_name='동아리 이름',
#     )
#     pages = models.TextField(
#         blank=True,
#         verbose_name='동아리 페이스북/유튜브 페이지 주소',
#     )
#     one_line_intro = models.TextField(
#         blank=True,
#         verbose_name='동아리 한 줄 소개(메인 화면)',
#     )
#     intro = models.TextField(
#         verbose_name='동아리 소개',
#     )
#     is_band = models.BooleanField(
#         default=False,
#         verbose_name='밴드 여부',
#     )
# 
#     video_url1 = models.CharField(
#         blank=True,
#         max_length=63,
#         verbose_name='동아리 소개 비디오 주소 #1',
#     )
#     video_url2 = models.CharField(
#         blank=True,
#         max_length=63,
#         verbose_name='동아리 소개 비디오 주소 #2',
#     )
# 
# 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 FormView, TemplateView
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required, user_passes_test
from django.db.models import Count
from ..forms import TSizeForm
from ..util import vote_available, is_tester
from ..models.club import Club
from ..models.user import Freshman
        else:
            freshman = form.save(commit=False)
            freshman.user = self.request.user
            freshman.save()

        return super(TSizeView, self).form_valid(form)

    def get_initial(self):
        initial = super(TSizeView, self).get_initial()

        if hasattr(self.request.user, 'freshman'):
            initial['tsize'] = self.request.user.freshman.tsize

        return initial


@method_decorator(user_passes_test(is_tester), name='dispatch')
class ResultView(TemplateView):
    template_name = 'result.html'

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

        context['clubs'] = Club.objects.all().annotate(cnt=Count('votes')).order_by('-cnt')
        context['bands'] = Club.objects.filter(is_band=True).annotate(cnt=Count('votes')).order_by('-cnt')
        context['non_bands'] = Club.objects.filter(is_band=False).annotate(cnt=Count('votes')).order_by('-cnt')

        context['cnt_voted'] = Freshman.objects.all().count()

        # Personal T shirts size

# Path: apps/ot/forms.py
# class TSizeForm(ModelForm):
#     class Meta:
#         model = Freshman
#         fields = ("tsize",)
# 
#     def __init__(self, *args, **kwargs):
#         super(TSizeForm, self).__init__(*args, **kwargs)
#         self.fields['tsize'].widget.attrs.update({'class': 'form-control'})
# 
# Path: apps/ot/util.py
# def vote_available(user):
#     if is_vote_period():
#         return is_freshman(user)
#     else:
#         return is_tester(user)
# 
# def is_tester(user):
#     if not user.is_authenticated or not hasattr(user, 'portal_info'):
#         return False
# 
#     return user.portal_info.ku_std_no in (
#         "20110208",
#         "20180379",
#         "20180419",
#         "20180058",
#         "20180634",
#         "20180154",
#     )
# 
# Path: apps/ot/models/club.py
# class Club(models.Model):
#     """
#     동아리 정보
#     """
# 
#     class Meta:
#         verbose_name = '동아리 정보'
#         verbose_name_plural = '동아리 정보(들)'
# 
#     def __str__(self):
#         return str(self.name)
# 
#     name = models.CharField(
#         max_length=63,
#         verbose_name='동아리 이름',
#     )
#     pages = models.TextField(
#         blank=True,
#         verbose_name='동아리 페이스북/유튜브 페이지 주소',
#     )
#     one_line_intro = models.TextField(
#         blank=True,
#         verbose_name='동아리 한 줄 소개(메인 화면)',
#     )
#     intro = models.TextField(
#         verbose_name='동아리 소개',
#     )
#     is_band = models.BooleanField(
#         default=False,
#         verbose_name='밴드 여부',
#     )
# 
#     video_url1 = models.CharField(
#         blank=True,
#         max_length=63,
#         verbose_name='동아리 소개 비디오 주소 #1',
#     )
#     video_url2 = models.CharField(
#         blank=True,
#         max_length=63,
#         verbose_name='동아리 소개 비디오 주소 #2',
#     )
# 
# 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/user.py
from django.views.generic import FormView, TemplateView
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required, user_passes_test
from django.db.models import Count
from ..forms import TSizeForm
from ..util import vote_available, is_tester
from ..models.club import Club
from ..models.user import Freshman

        else:
            freshman = form.save(commit=False)
            freshman.user = self.request.user
            freshman.save()

        return super(TSizeView, self).form_valid(form)

    def get_initial(self):
        initial = super(TSizeView, self).get_initial()

        if hasattr(self.request.user, 'freshman'):
            initial['tsize'] = self.request.user.freshman.tsize

        return initial


@method_decorator(user_passes_test(is_tester), name='dispatch')
class ResultView(TemplateView):
    template_name = 'result.html'

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

        context['clubs'] = Club.objects.all().annotate(cnt=Count('votes')).order_by('-cnt')
        context['bands'] = Club.objects.filter(is_band=True).annotate(cnt=Count('votes')).order_by('-cnt')
        context['non_bands'] = Club.objects.filter(is_band=False).annotate(cnt=Count('votes')).order_by('-cnt')

        context['cnt_voted'] = Freshman.objects.all().count()

        # Personal T shirts size

        freshmen = Freshman.objects.all()