# Path: application/models.py
# class Application(AbstractApplication):
#     """
#     Extended oauth2_provider.models.AbstractApplication to include application description and logo
#     """
#     description = models.TextField()
#     logo = models.ImageField(upload_to=application_logo, blank=True, null=True)
#     is_anonymous = models.BooleanField(default=False,
#                                        help_text='Valid for complete anonymous apps. Requires admin permission')
#     required_scopes = models.CharField(max_length=256,
#                                        help_text='Default non-tracking permissions. '
#                                                  'Valid only if application is anonymous', null=True, blank=True)
#     private_scopes = models.CharField(max_length=256, help_text='Private API scopes', null=True, blank=True)
#     website = models.URLField(null=True, blank=True)
#     privacy_policy = models.URLField(null=True, blank=True, help_text='Link of privacy policy of application')
#     created_on = models.DateTimeField(auto_now_add=True)
#     modified_on = models.DateTimeField(auto_now=True)
#     _history_ = HistoricalRecords()
# 
#     def get_logo_url(self):
#         try:
#             url = self.logo.url
#             url = urljoin(settings.MEDIA_URL, url)
#         except ValueError:
#             url = None
#         return url
# 
#     def get_absolute_url(self):
#         return reverse('oauth2_provider:detail', args=[str(self.id)])
# 
#     def clean(self):
#         super(Application, self).clean()
#         if self.authorization_grant_type == AbstractApplication.GRANT_PASSWORD:
#             error = _("Resource owner password based grants are not allowed for now")
#             raise ValidationError(error)
# 
#     def get_user_count(self):
#         return AccessToken.objects.all().filter(application=self).values_list('user', flat=True).distinct().count()
# 
#     def __str__(self):
#         if self.name:
#             return self.name
#         else:
#             return self.client_id
# 
# Path: core/utils.py
# DEGREES = [
#     ['BTECH', 'Bachelor of Technology'],
#     ['MTECH', 'Master of Technology'],
#     ['DD', 'B.Tech. + M.Tech. Dual Degree'],
#     ['MSC', 'Master of Science'],
#     ['PHD', 'Doctor of Philosophy'],
#     ['BDES', 'Bachelor of Design'],
#     ['MDES', 'Master of Design'],
#     ['MPHIL', 'Master of Philosophy'],
#     ['MMG', 'Master of Management'],
#     ['MSEx', 'M.S. (Exit Degree)'],
#     ['MtechEx', 'Master of Technology (Exit Degree)'],
#     ['MtechPhDDD', 'M.Tech. + Ph.D. Dual Degree'],
#     ['PC', 'Preparatory Course'],
#     ['VS', 'Visiting Student'],
#     ['MPhilEx', 'Master of Philosophy (Exit Degree)'],
#     ['MScEx', 'Master of Science (Exit Degree)'],
#     ['MScMTechDD', 'M.Sc. + M.Tech. Dual Degree'],
#     ['MScPhDDD', 'M.Sc. + Ph.D. Dual Degree'],
#     ['MPhilPhDDD', 'M.Phil. + Ph.D. Dual Degree'],
#     ['EMBA', 'Executive MBA'],
#     ['FYBS', 'Four Year BS'],
#     ['IMTECH', 'Integrated M.Tech.'],
#     ['MSCBR', 'Master of Science By Research'],
#     ['TYMSC', 'Two Year M.Sc.'],
#     ['FYIMSC', 'Five Year Integrated M.Sc.'],
#     ['DIIT', 'D.I.I.T.'],
#     ['DIITEx', 'D.I.T.T. (Exit Degree)'],
# ]
# 
# HOSTELS = [
#     ['1', 'Hostel 1'],
#     ['2', 'Hostel 2'],
#     ['3', 'Hostel 3'],
#     ['4', 'Hostel 4'],
#     ['5', 'Hostel 5'],
#     ['6', 'Hostel 6'],
#     ['7', 'Hostel 7'],
#     ['8', 'Hostel 8'],
#     ['9', 'Hostel 9'],
#     ['10', 'Hostel 10'],
#     ['11', 'Hostel 11'],
#     ['12', 'Hostel 12'],
#     ['13', 'Hostel 13'],
#     ['14', 'Hostel 14'],
#     ['15', 'Hostel 15'],
#     ['16', 'Hostel 16'],
#     ['tansa', 'Tansa'],
#     ['qip', 'QIP'],
# ]
# 
# HOSTELS_WITH_WINGS = ['10', '11', '12', '13', '14', '15', '16']
# 
# ROOM_VALIDATION_REGEX = re.compile(r'[A-Z]-\d+')
# 
# SORTED_DISCIPLINES = sorted(DISCIPLINES, key=lambda x: x[1])


from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from simple_history.models import HistoricalRecords
from application.models import Application
from core.utils import DEGREES, HOSTELS, HOSTELS_WITH_WINGS, ROOM_VALIDATION_REGEX, SORTED_DISCIPLINES
    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())


@python_2_unicode_compatible
class ContactNumber(models.Model):
    user = models.ForeignKey(User, related_name='contacts')
    number = models.CharField(max_length=16)
    _history_ = HistoricalRecords()

    def __str__(self):
        return self.number


@python_2_unicode_compatible
class SecondaryEmail(models.Model):
    user = models.ForeignKey(User, related_name='secondary_emails')
    email = models.EmailField()
    _history_ = HistoricalRecords()

    def __str__(self):
        return self.email


@python_2_unicode_compatible
class SentMessage(models.Model):
    message_id = models.CharField(max_length=256)

# Path: application/models.py
# class Application(AbstractApplication):
#     """
#     Extended oauth2_provider.models.AbstractApplication to include application description and logo
#     """
#     description = models.TextField()
#     logo = models.ImageField(upload_to=application_logo, blank=True, null=True)
#     is_anonymous = models.BooleanField(default=False,
#                                        help_text='Valid for complete anonymous apps. Requires admin permission')
#     required_scopes = models.CharField(max_length=256,
#                                        help_text='Default non-tracking permissions. '
#                                                  'Valid only if application is anonymous', null=True, blank=True)
#     private_scopes = models.CharField(max_length=256, help_text='Private API scopes', null=True, blank=True)
#     website = models.URLField(null=True, blank=True)
#     privacy_policy = models.URLField(null=True, blank=True, help_text='Link of privacy policy of application')
#     created_on = models.DateTimeField(auto_now_add=True)
#     modified_on = models.DateTimeField(auto_now=True)
#     _history_ = HistoricalRecords()
# 
#     def get_logo_url(self):
#         try:
#             url = self.logo.url
#             url = urljoin(settings.MEDIA_URL, url)
#         except ValueError:
#             url = None
#         return url
# 
#     def get_absolute_url(self):
#         return reverse('oauth2_provider:detail', args=[str(self.id)])
# 
#     def clean(self):
#         super(Application, self).clean()
#         if self.authorization_grant_type == AbstractApplication.GRANT_PASSWORD:
#             error = _("Resource owner password based grants are not allowed for now")
#             raise ValidationError(error)
# 
#     def get_user_count(self):
#         return AccessToken.objects.all().filter(application=self).values_list('user', flat=True).distinct().count()
# 
#     def __str__(self):
#         if self.name:
#             return self.name
#         else:
#             return self.client_id
# 
# Path: core/utils.py
# DEGREES = [
#     ['BTECH', 'Bachelor of Technology'],
#     ['MTECH', 'Master of Technology'],
#     ['DD', 'B.Tech. + M.Tech. Dual Degree'],
#     ['MSC', 'Master of Science'],
#     ['PHD', 'Doctor of Philosophy'],
#     ['BDES', 'Bachelor of Design'],
#     ['MDES', 'Master of Design'],
#     ['MPHIL', 'Master of Philosophy'],
#     ['MMG', 'Master of Management'],
#     ['MSEx', 'M.S. (Exit Degree)'],
#     ['MtechEx', 'Master of Technology (Exit Degree)'],
#     ['MtechPhDDD', 'M.Tech. + Ph.D. Dual Degree'],
#     ['PC', 'Preparatory Course'],
#     ['VS', 'Visiting Student'],
#     ['MPhilEx', 'Master of Philosophy (Exit Degree)'],
#     ['MScEx', 'Master of Science (Exit Degree)'],
#     ['MScMTechDD', 'M.Sc. + M.Tech. Dual Degree'],
#     ['MScPhDDD', 'M.Sc. + Ph.D. Dual Degree'],
#     ['MPhilPhDDD', 'M.Phil. + Ph.D. Dual Degree'],
#     ['EMBA', 'Executive MBA'],
#     ['FYBS', 'Four Year BS'],
#     ['IMTECH', 'Integrated M.Tech.'],
#     ['MSCBR', 'Master of Science By Research'],
#     ['TYMSC', 'Two Year M.Sc.'],
#     ['FYIMSC', 'Five Year Integrated M.Sc.'],
#     ['DIIT', 'D.I.I.T.'],
#     ['DIITEx', 'D.I.T.T. (Exit Degree)'],
# ]
# 
# HOSTELS = [
#     ['1', 'Hostel 1'],
#     ['2', 'Hostel 2'],
#     ['3', 'Hostel 3'],
#     ['4', 'Hostel 4'],
#     ['5', 'Hostel 5'],
#     ['6', 'Hostel 6'],
#     ['7', 'Hostel 7'],
#     ['8', 'Hostel 8'],
#     ['9', 'Hostel 9'],
#     ['10', 'Hostel 10'],
#     ['11', 'Hostel 11'],
#     ['12', 'Hostel 12'],
#     ['13', 'Hostel 13'],
#     ['14', 'Hostel 14'],
#     ['15', 'Hostel 15'],
#     ['16', 'Hostel 16'],
#     ['tansa', 'Tansa'],
#     ['qip', 'QIP'],
# ]
# 
# HOSTELS_WITH_WINGS = ['10', '11', '12', '13', '14', '15', '16']
# 
# ROOM_VALIDATION_REGEX = re.compile(r'[A-Z]-\d+')
# 
# SORTED_DISCIPLINES = sorted(DISCIPLINES, key=lambda x: x[1])


# Path: user_resource/models.py
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from simple_history.models import HistoricalRecords
from application.models import Application
from core.utils import DEGREES, HOSTELS, HOSTELS_WITH_WINGS, ROOM_VALIDATION_REGEX, SORTED_DISCIPLINES

    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())


@python_2_unicode_compatible
class ContactNumber(models.Model):
    user = models.ForeignKey(User, related_name='contacts')
    number = models.CharField(max_length=16)
    _history_ = HistoricalRecords()

    def __str__(self):
        return self.number


@python_2_unicode_compatible
class SecondaryEmail(models.Model):
    user = models.ForeignKey(User, related_name='secondary_emails')
    email = models.EmailField()
    _history_ = HistoricalRecords()

    def __str__(self):
        return self.email


@python_2_unicode_compatible
class SentMessage(models.Model):
    message_id = models.CharField(max_length=256)

    sender = models.ForeignKey(Application)