Skip to content

Commit 401d4a5

Browse files
Added wing validation for selected hostels
1 parent ca4210d commit 401d4a5

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

core/models.py

Whitespace-only changes.

core/utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import collections
2+
import re
23

34
import django.utils.six as six
45
from django.conf import settings
@@ -167,6 +168,10 @@ def get_choices_with_blank_dash(choices):
167168
['qip', 'QIP'],
168169
]
169170

171+
HOSTELS_WITH_WINGS = ['10', '12', '13', '14', '15', '16']
172+
173+
ROOM_VALIDATION_REGEX = re.compile(r'[A-Z]-\d+')
174+
170175

171176
class TabNav(object):
172177
def __init__(self, tab, name=None, template_name=None, base_url=None, is_default=False):

resources/views.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from oauth2_provider.ext.rest_framework.permissions import TokenHasScope
22
from rest_framework import viewsets
3+
from rest_framework.decorators import list_route
34

45
from core.pagination import DefaultLimitOffsetPagination
56
from user_resource.models import InstituteAddress
7+
68
from .serializers import UserRoomSerializer
7-
from rest_framework.decorators import list_route
89

910

1011
class ResourcesViewset(viewsets.GenericViewSet):
@@ -18,4 +19,4 @@ def rooms(self, request):
1819
queryset = InstituteAddress.objects.all().order_by('id').prefetch_related('user__userprofile')
1920
queryset = self.paginate_queryset(queryset)
2021
serialized_queryset = self.serializer_class(queryset, many=True)
21-
return self.get_paginated_response(serialized_queryset.data)
22+
return self.get_paginated_response(serialized_queryset.data)

user_resource/models.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from simple_history.models import HistoricalRecords
88

99
from application.models import Application
10-
from core.utils import DEGREES, HOSTELS, SORTED_DISCIPLINES
10+
from core.utils import DEGREES, HOSTELS, HOSTELS_WITH_WINGS, ROOM_VALIDATION_REGEX, SORTED_DISCIPLINES
1111

1212

1313
def validate_join_year(value):
@@ -33,6 +33,12 @@ class InstituteAddress(models.Model):
3333
hostel = models.CharField(max_length=8, choices=HOSTELS, null=True, blank=True)
3434
_history_ = HistoricalRecords()
3535

36+
def clean(self):
37+
if self.room:
38+
if self.hostel in HOSTELS_WITH_WINGS:
39+
if not ROOM_VALIDATION_REGEX.match(self.room):
40+
raise ValidationError(_('Room number must have wing name like A-123'))
41+
3642
def __str__(self):
3743
if self.hostel:
3844
if self.room:

0 commit comments

Comments
 (0)