# Path: user_resource/models.py
# 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
# 
# 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())
# 
# class SecondaryEmail(models.Model):
#     user = models.ForeignKey(User, related_name='secondary_emails')
#     email = models.EmailField()
#     _history_ = HistoricalRecords()
# 
#     def __str__(self):
#         return self.email
# 
# class SentMessage(models.Model):
#     message_id = models.CharField(max_length=256)
#     sender = models.ForeignKey(Application)
#     user = models.ForeignKey(User)
#     status = models.BooleanField(default=True)
#     error_message = models.TextField(null=True, blank=True)
#     created = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return self.message_id


from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from .models import ContactNumber, InstituteAddress, Program, SecondaryEmail, SentMessage

class ProgramAdmin(SimpleHistoryAdmin):
    list_display = ['id', 'user', 'department', 'join_year', 'graduation_year', 'degree']
    list_filter = ['department', 'join_year', 'graduation_year', 'degree', ]
    search_fields = ['user__username', 'user__first_name', ]

    class Media:
        js = ['admin/js/list_filter_collapse.js', ]


class ContactNumberAdmin(SimpleHistoryAdmin):
    list_display = ['id', 'user', 'number']
    search_fields = ['user__username', 'user__first_name', 'number', ]


class SecondaryEmailAdmin(SimpleHistoryAdmin):
    list_display = ['id', 'user', 'email']
    search_fields = ['user__username', 'user__first_name', 'email', ]


class SentMessageAdmin(SimpleHistoryAdmin):
    list_display = ['id', 'message_id', 'sender', 'user', 'status', 'created', ]
    list_filter = ['status', 'sender', ]
    search_fields = ['sender__id', 'sender__name', 'user__username', 'user__first_name', 'message_id', ]

    class Media:
        js = ['admin/js/list_filter_collapse.js', ]


admin.site.register(InstituteAddress, InstituteAddressAdmin)

# Path: user_resource/models.py
# 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
# 
# 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())
# 
# class SecondaryEmail(models.Model):
#     user = models.ForeignKey(User, related_name='secondary_emails')
#     email = models.EmailField()
#     _history_ = HistoricalRecords()
# 
#     def __str__(self):
#         return self.email
# 
# class SentMessage(models.Model):
#     message_id = models.CharField(max_length=256)
#     sender = models.ForeignKey(Application)
#     user = models.ForeignKey(User)
#     status = models.BooleanField(default=True)
#     error_message = models.TextField(null=True, blank=True)
#     created = models.DateTimeField(auto_now_add=True)
# 
#     def __str__(self):
#         return self.message_id


# Path: user_resource/admin.py
from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from .models import ContactNumber, InstituteAddress, Program, SecondaryEmail, SentMessage


class ProgramAdmin(SimpleHistoryAdmin):
    list_display = ['id', 'user', 'department', 'join_year', 'graduation_year', 'degree']
    list_filter = ['department', 'join_year', 'graduation_year', 'degree', ]
    search_fields = ['user__username', 'user__first_name', ]

    class Media:
        js = ['admin/js/list_filter_collapse.js', ]


class ContactNumberAdmin(SimpleHistoryAdmin):
    list_display = ['id', 'user', 'number']
    search_fields = ['user__username', 'user__first_name', 'number', ]


class SecondaryEmailAdmin(SimpleHistoryAdmin):
    list_display = ['id', 'user', 'email']
    search_fields = ['user__username', 'user__first_name', 'email', ]


class SentMessageAdmin(SimpleHistoryAdmin):
    list_display = ['id', 'message_id', 'sender', 'user', 'status', 'created', ]
    list_filter = ['status', 'sender', ]
    search_fields = ['sender__id', 'sender__name', 'user__username', 'user__first_name', 'message_id', ]

    class Media:
        js = ['admin/js/list_filter_collapse.js', ]


admin.site.register(InstituteAddress, InstituteAddressAdmin)

admin.site.register(Program, ProgramAdmin)