# Path: core/pagination.py
# class DefaultLimitOffsetPagination(pagination.LimitOffsetPagination):
# 
#     default_limit = 20
#     max_limit = 500
# 
# 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 ''
# 
# Path: resources/serializers.py
# class UserRoomSerializer(serializers.ModelSerializer):
#     roll_number = serializers.CharField(source='user.userprofile.roll_number')
# 
#     class Meta:
#         model = InstituteAddress
#         exclude = ['id', 'user']


from oauth2_provider.ext.rest_framework.permissions import TokenHasScope
from rest_framework import viewsets
from rest_framework.decorators import list_route
from core.pagination import DefaultLimitOffsetPagination
from user_resource.models import InstituteAddress
from .serializers import UserRoomSerializer




class ResourcesViewset(viewsets.GenericViewSet):

    pagination_class = DefaultLimitOffsetPagination
    permission_classes = [TokenHasScope]
    required_scopes = ['priv_rooms']


# Path: core/pagination.py
# class DefaultLimitOffsetPagination(pagination.LimitOffsetPagination):
# 
#     default_limit = 20
#     max_limit = 500
# 
# 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 ''
# 
# Path: resources/serializers.py
# class UserRoomSerializer(serializers.ModelSerializer):
#     roll_number = serializers.CharField(source='user.userprofile.roll_number')
# 
#     class Meta:
#         model = InstituteAddress
#         exclude = ['id', 'user']


# Path: resources/views.py
from oauth2_provider.ext.rest_framework.permissions import TokenHasScope
from rest_framework import viewsets
from rest_framework.decorators import list_route
from core.pagination import DefaultLimitOffsetPagination
from user_resource.models import InstituteAddress
from .serializers import UserRoomSerializer





class ResourcesViewset(viewsets.GenericViewSet):

    pagination_class = DefaultLimitOffsetPagination
    permission_classes = [TokenHasScope]
    required_scopes = ['priv_rooms']


    @list_route(methods=['GET'], serializer_class=UserRoomSerializer)