# 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 ProfilePictureForm(forms.Form):
    profile_picture = forms.ImageField()

    def clean_profile_picture(self):
        profile_picture = self.cleaned_data['profile_picture']
        content_type = profile_picture.content_type.split('/')[0]
        if content_type in ['image']:
            if profile_picture.size > 5242880:
                raise forms.ValidationError(_('Please keep filesize under %s. Current filesize %s') % (
                    filesizeformat(5242880), filesizeformat(profile_picture.size)))
        else:
            raise forms.ValidationError(_('File type is not supported'))
        return profile_picture


class SexUpdateForm(forms.Form):
    sex = forms.ChoiceField(choices=get_choices_with_blank_dash(SEXES), required=False,
                            widget=forms.Select(
                                attrs={'class': 'form-control', },
                            ))


class InstituteAddressForm(forms.ModelForm):
    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 ProfilePictureForm(forms.Form):
    profile_picture = forms.ImageField()

    def clean_profile_picture(self):
        profile_picture = self.cleaned_data['profile_picture']
        content_type = profile_picture.content_type.split('/')[0]
        if content_type in ['image']:
            if profile_picture.size > 5242880:
                raise forms.ValidationError(_('Please keep filesize under %s. Current filesize %s') % (
                    filesizeformat(5242880), filesizeformat(profile_picture.size)))
        else:
            raise forms.ValidationError(_('File type is not supported'))
        return profile_picture


class SexUpdateForm(forms.Form):
    sex = forms.ChoiceField(choices=get_choices_with_blank_dash(SEXES), required=False,
                            widget=forms.Select(
                                attrs={'class': 'form-control', },
                            ))


class InstituteAddressForm(forms.ModelForm):
    class Meta:

        model = InstituteAddress