Ejemplo n.º 1
0
    def post(request):
        form = HomeForm(request.POST)
        if form.is_valid():
            rfid = form.cleaned_data['rfid']

            try:
                Gear.objects.get(rfid=rfid)
                return redirect('kiosk:gear', rfid)
            except Gear.DoesNotExist:
                pass

            try:
                Member.objects.get(rfid=rfid)
                return redirect('kiosk:check_out', rfid)
            except Member.DoesNotExist:
                pass

            if rfid.isdigit() and len(rfid) == 10:
                alert_message = f'The RFID {rfid} is not registered'
                messages.add_message(request, messages.WARNING, alert_message)
            else:
                alert_message = f'{rfid} is not a valid RFID'
                messages.add_message(request, messages.WARNING, alert_message)

            return redirect('kiosk:home')
Ejemplo n.º 2
0
    def post(request, rfid):
        form = HomeForm(request.POST)
        if form.is_valid():
            gear_rfid = form.cleaned_data['rfid']
            staffer_rfid = request.user.rfid
            member_rfid = rfid

            try:
                gear = Gear.objects.get(rfid=gear_rfid)
            except Gear.DoesNotExist:
                gear = None

            if gear:
                if gear.is_available():
                    do_checkout(staffer_rfid, member_rfid, gear_rfid)
                    alert_message = f'{gear.name} was checked out successfully'
                    messages.add_message(request, messages.INFO, alert_message)
                else:
                    do_checkin(staffer_rfid, gear_rfid)
                    alert_message = f'{gear.name} was checked in successfully'
                    messages.add_message(request, messages.WARNING,
                                         alert_message)
            else:
                alert_message = 'The RFID tag is not registered to a piece of gear'
                messages.add_message(request, messages.WARNING, alert_message)

            return redirect('kiosk:check_out', member_rfid)
Ejemplo n.º 3
0
    def post(self, request):
        form = HomeForm(request.POST)
        if form.is_valid():
            rfid = form.cleaned_data['rfid']
            staffer_rfid = request.user.rfid
            gear = Gear.objects.filter(rfid=rfid)
            member = Member.objects.filter(rfid=rfid)

            if member and member.get():
                return redirect('check_out', rfid)
            elif gear:
                gear = gear.get()
                if gear.is_rented_out():
                    do_checkin(staffer_rfid, rfid)
                    alert_message = gear.name + " was checked in successfully"
                    messages.add_message(request, messages.INFO, alert_message)
                else:
                    alert_message = gear.name + " is already checked in"
                    messages.add_message(request, messages.INFO, alert_message)
                    return redirect('home')
            else:
                alert_message = "The RFID tag is not registered to a user or gear"
                messages.add_message(request, messages.WARNING, alert_message)

            return redirect('home')
Ejemplo n.º 4
0
    def post_member_or_gear_rfid(request, rfid: str):
        """Check in item or check it out to a member"""
        form = HomeForm(request.POST)
        if form.is_valid():
            form_rfid = form.cleaned_data['rfid']
            staffer_rfid = request.user.rfid

            try:
                gear_rfid = form_rfid
                gear = Gear.objects.get(rfid=gear_rfid)
            except Gear.DoesNotExist:
                try:
                    gear_rfid = rfid
                    gear = Gear.objects.get(rfid=gear_rfid)
                except Gear.DoesNotExist:
                    gear = None
                    gear_rfid = None

            try:
                member_rfid = form_rfid
                member = Member.objects.get(rfid=member_rfid)
            except Member.DoesNotExist:
                try:
                    member_rfid = form_rfid
                    member = Member.objects.get(rfid=member_rfid)
                except Member.DoesNotExist:
                    member = None
                    member_rfid = None

            if gear:
                if gear_rfid == form_rfid:
                    if gear.is_rented_out():
                        do_checkin(staffer_rfid, gear.rfid)
                        alert_message = f'{gear.name} was checked in successfully'
                        messages.add_message(request, messages.INFO,
                                             alert_message)
                    else:
                        alert_message = 'Gear is already checked in'
                        messages.add_message(request, messages.WARNING,
                                             alert_message)
                elif member and member_rfid == form_rfid:
                    if gear.is_rented_out():
                        do_checkin(staffer_rfid, gear_rfid)
                    do_checkout(staffer_rfid, member_rfid, gear_rfid)
                    alert_message = 'Gear checked out!'
                    messages.add_message(request, messages.WARNING,
                                         alert_message)
                else:
                    alert_message = 'The RFID is not registered to any gear'
                    messages.add_message(request, messages.WARNING,
                                         alert_message)
            else:
                alert_message = 'The RFID is not registered to any gear'
                messages.add_message(request, messages.WARNING, alert_message)

            return redirect('kiosk:gear', gear_rfid)
Ejemplo n.º 5
0
    def post(self, request, rfid):
        form = HomeForm(request.POST)
        if form.is_valid():
            gear_rfid = form.cleaned_data['rfid']
            staffer_rfid = request.user.rfid
            member_rfid = rfid
            gear = Gear.objects.filter(rfid=gear_rfid)
            if gear:
                gear = gear.get()
                if gear.is_available():
                    do_checkout(staffer_rfid, member_rfid, gear.rfid)
                    alert_message = gear.name + " was checked out successfully"
                    messages.add_message(request, messages.INFO, alert_message)
                else:
                    alert_message = "Gear is already rented out"
                    messages.add_message(request, messages.WARNING,
                                         alert_message)
            else:
                alert_message = "The RFID tag is not registered to a piece of gear"
                messages.add_message(request, messages.WARNING, alert_message)

            return redirect('check_out', member_rfid)
Ejemplo n.º 6
0
 def test_valid_home_form(self):
     data = {'rfid': '1234567890'}
     form = HomeForm(data=data)
     self.assertTrue(form.is_valid())
Ejemplo n.º 7
0
 def test_blank_home_form(self):
     data = {'rfid': ''}
     form = HomeForm(data=data)
     self.assertFalse(form.is_valid())
Ejemplo n.º 8
0
 def test_valid_home_form(self):
     data = {"rfid": "1234567890"}
     form = HomeForm(data=data)
     self.assertTrue(form.is_valid())
Ejemplo n.º 9
0
 def test_starting_zero_home_form(self):
     data = {"rfid": "0123456789"}
     form = HomeForm(data=data)
     self.assertTrue(form.is_valid())