diff --git a/uncc_gameday/gameday/urls.py b/uncc_gameday/gameday/urls.py index 07f36e6..d02f4a9 100644 --- a/uncc_gameday/gameday/urls.py +++ b/uncc_gameday/gameday/urls.py @@ -9,5 +9,7 @@ urlpatterns = patterns('gameday.views', 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/(?P\w+)/(?P\w+)/$', views.ListRegisteredUserByName.as_view(), + name='get-registered-user-by-name'), url('^register/$', views.RegisterUser.as_view(), name='register-user'), ) diff --git a/uncc_gameday/gameday/views.py b/uncc_gameday/gameday/views.py index d5afa51..318e60d 100755 --- a/uncc_gameday/gameday/views.py +++ b/uncc_gameday/gameday/views.py @@ -89,3 +89,19 @@ class ListRegisteredUsers(APIView): 'Get the information for a registered user' user = get_object_or_404(RegisteredUser, id=id) return Response(UserSerializer(user).data) + +class ListRegisteredUserByName(APIView): + """ + Get a registered user by looking up their first and last name. + This isn't a PK lookup, so we get the one registered most recently. + """ + + def get(self, request, fname, lname): + 'Get the information for a specified user' + user = RegisteredUser.objects.filter(first_name=fname, last_name=lname)\ + .order_by("-id")[0] + if user is None: + return Response("User not found with first_name '%s' and last_name '%s'", + status=status.HTTP_404_NOT_FOUND) + else: + return Response(SingleUserSerializer(user).data)