Add door controller cards route to API

This commit is contained in:
Tanner Collin 2020-01-20 06:01:10 +00:00
parent 872a51f5f5
commit aa9045e49e
2 changed files with 29 additions and 1 deletions

View File

@ -249,6 +249,34 @@ class UserView(views.APIView):
return Response(serializer.data) return Response(serializer.data)
class DoorViewSet(Base, List):
serializer_class = serializers.CardSerializer
def list(self, request):
cards = models.Card.objects.filter(active_status='card_active')
active_member_cards = {}
# format cards to match Emrah's conversion script, fix later
for card in cards:
member = get_object_or_404(models.Member, id=card.member_id)
if member.paused_date: continue
active_member_cards[card.card_number] = dict(
name=member.first_name + ' ' + member.last_name[0],
id=member.id,
enabled=True,
)
return Response(active_member_cards)
@action(detail=True, methods=['post'])
def seen(self, request, pk=None):
card = get_object_or_404(models.Card, card_number=pk)
card.last_seen_at = datetime.date.today()
card.save()
return Response(200)
class RegistrationView(RegisterView): class RegistrationView(RegisterView):
serializer_class = serializers.RegistrationSerializer serializer_class = serializers.RegistrationSerializer

View File

@ -6,7 +6,7 @@ from rest_framework import routers
from .api import views from .api import views
router = routers.DefaultRouter() router = routers.DefaultRouter()
#router.register(r'users', views.UserViewSet) router.register(r'door', views.DoorViewSet, basename='door')
router.register(r'cards', views.CardViewSet, basename='card') router.register(r'cards', views.CardViewSet, basename='card')
router.register(r'search', views.SearchViewSet, basename='search') router.register(r'search', views.SearchViewSet, basename='search')
router.register(r'members', views.MemberViewSet, basename='members') router.register(r'members', views.MemberViewSet, basename='members')