Example #1
0
 def test_parses_student_id(self):
     form_data = {
         'swipe': '%B7989142181070636^LAST/FIRST M         ^'
                  '014546611094120       000      ?;'
                  '3095193769558739=54960723825369019715?'
     }
     form = CardSwipeForm(data=form_data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data['swipe'], 'First M Last')
Example #2
0
 def test_parses_fl_driver_license(self):
     form_data = {
         'swipe': '%FLORLANDO^LAST$FIRST$MIDDLE^123 COOL ST?;'
                  '9562020272902437403=7597808483877=?+! 32816  '
                  'E               2188'
                  '                                   ECCECC00000?'
     }
     form = CardSwipeForm(data=form_data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.cleaned_data['swipe'], 'First Middle Last')
Example #3
0
def attend(request, id):
    event = get_object_or_404(Event, id=id)
    form = CardSwipeForm(request.POST)
    if not form.is_valid():
        return JSONErrorResponse({"errors": form.errors})

    name = form.cleaned_data["swipe"]
    attendee, _ = Attendee.objects.get_or_create(name=name)
    attendee.save()
    if event.attendees.filter(id=attendee.id).exists():
        return JSONErrorResponse({"errors": {"swipe": ["Attendee already swiped into event"]}})

    attendance = Attendance.objects.create(event=event, attendee=attendee)
    jresponse = GENERIC_SUCCESS.copy()
    jresponse["log"] = {"message": "Scanned {}".format(name), "timestamp": attendance.timestamp.timestamp()}
    return JSONResponse(jresponse)
Example #4
0
def attend(request, id):
    event = get_object_or_404(Event, id=id)
    form = CardSwipeForm(request.POST)
    if not form.is_valid():
        return JSONErrorResponse({'errors': form.errors})

    name = form.cleaned_data['swipe']
    attendee, _ = Attendee.objects.get_or_create(name=name)
    attendee.save()
    if event.attendees.filter(id=attendee.id).exists():
        return JSONErrorResponse(
            {'errors': {
                'swipe': ['Attendee already swiped into event']
            }})

    attendance = Attendance.objects.create(event=event, attendee=attendee)
    jresponse = GENERIC_SUCCESS.copy()
    jresponse['log'] = {
        'message': 'Scanned {}'.format(name),
        'timestamp': attendance.timestamp.timestamp()
    }
    return JSONResponse(jresponse)