# Path: core/utils.py
# SEXES = [
#     ('male', 'Male'),
#     ('female', 'Female'),
#     ('other', 'Other'),
# ]
# 
# def get_choices_with_blank_dash(choices):
#     return BLANK_CHOICE_DASH + list(choices)
# 
# Path: user_resource/models.py
# class InstituteAddress(models.Model):
#     user = models.OneToOneField(User, related_name='insti_address')
#     room = models.CharField(max_length=8, null=True, blank=True)
#     hostel = models.CharField(max_length=8, choices=HOSTELS, null=True, blank=True)
#     _history_ = HistoricalRecords()
# 
#     def clean(self):
#         if self.room:
#             if self.hostel in HOSTELS_WITH_WINGS:
#                 if not ROOM_VALIDATION_REGEX.match(self.room):
#                     raise ValidationError(_('Room number must have wing name like A-123'))
# 
#     def __str__(self):
#         if self.hostel:
#             if self.room:
#                 return "%s-%s" % (self.hostel, self.room)
#             return self.hostel
#         return ''
# 
# class Program(models.Model):
#     user = models.OneToOneField(User, related_name='program')
#     department = models.CharField(max_length=16, choices=SORTED_DISCIPLINES, null=True, blank=True)
#     join_year = models.PositiveSmallIntegerField(null=True, blank=True, validators=[validate_join_year])
#     graduation_year = models.PositiveSmallIntegerField(null=True, blank=True, validators=[validate_graduation_year])
#     degree = models.CharField(max_length=16, choices=DEGREES, null=True, blank=True)
#     _history_ = HistoricalRecords()
# 
#     def __str__(self):
#         return "%s, %s" % (self.get_degree_display(), self.get_department_display())


from django import forms
from django.template.defaultfilters import filesizeformat
from django.utils.translation import ugettext_lazy as _
from core.utils import SEXES, get_choices_with_blank_dash
from .models import InstituteAddress, Program
    class Meta:
        model = InstituteAddress
        fields = ['hostel', 'room']
        widgets = {
            'hostel': forms.Select(
                attrs={'class': 'form-control', },
            ),
            'room': forms.TextInput(
                attrs={'class': 'form-control', },
            ),
        }


class ProgramForm(forms.ModelForm):
    def clean(self):
        cleaned_data = super(ProgramForm, self).clean()
        join_year = cleaned_data.get('join_year')
        graduation_year = cleaned_data.get('graduation_year')

        if join_year and graduation_year:
            if graduation_year <= join_year:
                validation_err = forms.ValidationError(_('How come you graduated before you joined?'), code='bad_input')
                self.add_error('graduation_year', validation_err)

            if join_year >= graduation_year:
                validation_err = forms.ValidationError(
                    _('How come you joined after you graduated? You must be in alternate timeline!'), code='bade_input')
                self.add_error('join_year', validation_err)

    class Meta:

# Path: core/utils.py
# SEXES = [
#     ('male', 'Male'),
#     ('female', 'Female'),
#     ('other', 'Other'),
# ]
# 
# def get_choices_with_blank_dash(choices):
#     return BLANK_CHOICE_DASH + list(choices)
# 
# Path: user_resource/models.py
# class InstituteAddress(models.Model):
#     user = models.OneToOneField(User, related_name='insti_address')
#     room = models.CharField(max_length=8, null=True, blank=True)
#     hostel = models.CharField(max_length=8, choices=HOSTELS, null=True, blank=True)
#     _history_ = HistoricalRecords()
# 
#     def clean(self):
#         if self.room:
#             if self.hostel in HOSTELS_WITH_WINGS:
#                 if not ROOM_VALIDATION_REGEX.match(self.room):
#                     raise ValidationError(_('Room number must have wing name like A-123'))
# 
#     def __str__(self):
#         if self.hostel:
#             if self.room:
#                 return "%s-%s" % (self.hostel, self.room)
#             return self.hostel
#         return ''
# 
# class Program(models.Model):
#     user = models.OneToOneField(User, related_name='program')
#     department = models.CharField(max_length=16, choices=SORTED_DISCIPLINES, null=True, blank=True)
#     join_year = models.PositiveSmallIntegerField(null=True, blank=True, validators=[validate_join_year])
#     graduation_year = models.PositiveSmallIntegerField(null=True, blank=True, validators=[validate_graduation_year])
#     degree = models.CharField(max_length=16, choices=DEGREES, null=True, blank=True)
#     _history_ = HistoricalRecords()
# 
#     def __str__(self):
#         return "%s, %s" % (self.get_degree_display(), self.get_department_display())


# Path: user_resource/forms.py
from django import forms
from django.template.defaultfilters import filesizeformat
from django.utils.translation import ugettext_lazy as _
from core.utils import SEXES, get_choices_with_blank_dash
from .models import InstituteAddress, Program

    class Meta:
        model = InstituteAddress
        fields = ['hostel', 'room']
        widgets = {
            'hostel': forms.Select(
                attrs={'class': 'form-control', },
            ),
            'room': forms.TextInput(
                attrs={'class': 'form-control', },
            ),
        }


class ProgramForm(forms.ModelForm):
    def clean(self):
        cleaned_data = super(ProgramForm, self).clean()
        join_year = cleaned_data.get('join_year')
        graduation_year = cleaned_data.get('graduation_year')

        if join_year and graduation_year:
            if graduation_year <= join_year:
                validation_err = forms.ValidationError(_('How come you graduated before you joined?'), code='bad_input')
                self.add_error('graduation_year', validation_err)

            if join_year >= graduation_year:
                validation_err = forms.ValidationError(
                    _('How come you joined after you graduated? You must be in alternate timeline!'), code='bade_input')
                self.add_error('join_year', validation_err)

    class Meta:

        model = Program