diff --git a/uncc_gameday/gameday/models.py b/uncc_gameday/gameday/models.py index cdab57c..b646c83 100755 --- a/uncc_gameday/gameday/models.py +++ b/uncc_gameday/gameday/models.py @@ -8,8 +8,8 @@ class RegisteredUser(models.Model): date_registered = models.DateTimeField(default=datetime.now) first_name = models.CharField(max_length=64) last_name = models.CharField(max_length=64) - section = models.CharField(max_length=8) - row = models.IntegerField() + section = models.CharField(max_length=8, null=True, blank=True) + row = models.IntegerField(null=True, blank=True) class ParkingLot(models.Model): diff --git a/uncc_gameday/gameday/serializers.py b/uncc_gameday/gameday/serializers.py index 058aaf8..850df1d 100644 --- a/uncc_gameday/gameday/serializers.py +++ b/uncc_gameday/gameday/serializers.py @@ -13,3 +13,13 @@ class ParkingRatingSerializer(serializers.ModelSerializer): class Meta: model = ParkingRating fields = ('rating', 'parking_lot',) + +class UserSerializer(serializers.ModelSerializer): + class Meta: + model = RegisteredUser + fields = ('first_name', 'last_name', 'section', 'row') + +class SingleUserSerializer(serializers.ModelSerializer): + class Meta: + model = RegisteredUser + fields = ('id', 'first_name', 'last_name') diff --git a/uncc_gameday/gameday/urls.py b/uncc_gameday/gameday/urls.py index aa1ff92..07f36e6 100644 --- a/uncc_gameday/gameday/urls.py +++ b/uncc_gameday/gameday/urls.py @@ -8,4 +8,6 @@ urlpatterns = patterns('gameday.views', url('^lots/$', views.ParkingLotList.as_view(), name='parking-lots'), url('^lots/(?P\w+)/$', views.SingleParkingLotList.as_view(), name='parking-lot'), url('^rate/$', views.RateLot.as_view(), name='parking-rating'), + url('^register/(?P\d+)/$', views.ListRegisteredUsers.as_view(), name='get-registered-user'), + url('^register/$', views.RegisterUser.as_view(), name='register-user'), ) diff --git a/uncc_gameday/gameday/views.py b/uncc_gameday/gameday/views.py index ee6f774..d5afa51 100755 --- a/uncc_gameday/gameday/views.py +++ b/uncc_gameday/gameday/views.py @@ -56,3 +56,36 @@ class RateLot(APIView): def get(self, request): 'Get the rating choice options' return Response(ParkingRating.RATING_CHOICES) + +class RegisterUser(APIView): + """ + Handle Registration of users + **GET**: Get the current information of a registered user by ID + **POST**: Register a new user + """ + def get(self, request): + 'Get the first and last names of all registered users' + users = RegisteredUser.objects.all() + users_s = SingleUserSerializer(users, many=True) + return Response(users_s.data) + + def post(self, request): + 'Register a new user' + user = UserSerializer(data=request.DATA) + if user.is_valid(): + user.save() + return Response(user.data) + return Response(user.errors, status=status.HTTP_400_BAD_REQUEST) + +class ListRegisteredUsers(APIView): + """ + List all registered users. + We have a separate view set up so we can list all information about one + user at a time (this one), and one view to get just id, first_name, + and last_name of all users. + """ + + def get(self, request, id): + 'Get the information for a registered user' + user = get_object_or_404(RegisteredUser, id=id) + return Response(UserSerializer(user).data)