def processMessage(arg_list): from dishes.models import ItemTracker from appliances.models import Appliance # 3 = Appliance Logout if arg_list[0] == '3': if len(arg_list) >= 2: appl = Appliance.objects.get(hwid=arg_list[1]) appl.logout() else: # bad arguments (only ApplID as argument) return '-10' # 4 = Appliance Login elif arg_list[0] == '4': if len(arg_list) >= 3: appl = Appliance.objects.get(hwid=arg_list[1]) appl.login(arg_list[2]) else: # bad arguments (arguments must consist of CardID + ApplID) return '-10' # 5 = Appliance Report elif arg_list[0] == '5': if len(arg_list) >= 2: appl = Appliance.objects.get(hwid=arg_list[1]) appl.report() else: # bad arguments (only ApplID as argument) return '-10' # 6 = take dishes out elif arg_list[0] == '6': if len(arg_list) >= 3: return ItemTracker.takeItemOut(arg_list[1:-1], arg_list[-1]) else: # bad arguments return '-10' # 7 - put dishes back elif arg_list[0] == '7': if len(arg_list) >= 3: return ItemTracker.putItemIn(arg_list[1:-1], arg_list[-1]) else: # bad arguments return '-10' else: # wrong command request return '-3'
def newHw(request): if request.POST: txt_hwid = request.POST.get('txt_hwid').strip() txt_psw = request.POST.get('txt_sn').strip() txt_title = request.POST.get('txt_title').strip() hwtype_radio = request.POST.get('hwtype') import re reg = re.compile(r'^[\w\s]+$') if reg.search(txt_hwid) is None: messages.info( request, 'Please use only alphanumeric symbols and whitespaces for hwid.' ) return render(request, 'hardware/newhw.html') if reg.search(txt_psw) is None: messages.info( request, 'Please use only alphanumeric symbols and whitespaces for serial number.' ) return render(request, 'hardware/newhw.html') if reg.search(txt_title) is None: messages.info( request, 'Please use only alphanumeric symbols and whitespaces for title.' ) return render(request, 'hardware/newhw.html') from django.db import IntegrityError if hwtype_radio is not None: if hwtype_radio == '0': from appliances.models import Appliance, ApplianceChore try: a = Appliance() a.hwid = txt_hwid a.password = txt_psw a.name = txt_title a.generatePad() a.save() ac = ApplianceChore() ac.appliance = a ac.name = a.name + " Chore" ac.save() except IntegrityError: messages.error(request, 'Appliance with this id already exists.') return render(request, 'hardware/newhw.html') else: messages.info(request, a.getName() + ' successfully registered.') return redirect('hardware:hwlist') elif hwtype_radio == '1': from dishes.models import ItemTracker try: h = ItemTracker() h.hwid = txt_hwid h.password = txt_psw h.name = txt_title h.generatePad() h.save() except IntegrityError: messages.error( request, 'Item tracker with this id already exists.') return render(request, 'hardware/newhw.html') else: messages.info(request, h.getName() + ' successfully registered.') return redirect('hardware:hwlist') else: messages.info(request, 'Please select hardware type') return render(request, 'hardware/newhw.html') return render(request, 'hardware/newhw.html')
def newHw(request): if request.POST: txt_hwid = request.POST.get('txt_hwid').strip() txt_psw = request.POST.get('txt_sn').strip() txt_title = request.POST.get('txt_title').strip() hwtype_radio = request.POST.get('hwtype') import re reg = re.compile(r'^[\w\s]+$') if reg.search(txt_hwid) is None: messages.info(request, 'Please use only alphanumeric symbols and whitespaces for hwid.') return render(request, 'hardware/newhw.html') if reg.search(txt_psw) is None: messages.info(request, 'Please use only alphanumeric symbols and whitespaces for serial number.') return render(request, 'hardware/newhw.html') if reg.search(txt_title) is None: messages.info(request, 'Please use only alphanumeric symbols and whitespaces for title.') return render(request, 'hardware/newhw.html') from django.db import IntegrityError if hwtype_radio is not None: if hwtype_radio == '0': from appliances.models import Appliance, ApplianceChore try: a = Appliance() a.hwid = txt_hwid a.password = txt_psw a.name = txt_title a.generatePad() a.save() ac = ApplianceChore() ac.appliance = a ac.name = a.name + " Chore" ac.save() except IntegrityError: messages.error(request, 'Appliance with this id already exists.') return render(request, 'hardware/newhw.html') else: messages.info(request, a.getName() + ' successfully registered.') return redirect('hardware:hwlist') elif hwtype_radio == '1': from dishes.models import ItemTracker try: h = ItemTracker() h.hwid = txt_hwid h.password = txt_psw h.name = txt_title h.generatePad() h.save() except IntegrityError: messages.error(request, 'Item tracker with this id already exists.') return render(request, 'hardware/newhw.html') else: messages.info(request, h.getName() + ' successfully registered.') return redirect('hardware:hwlist') else: messages.info(request, 'Please select hardware type') return render(request, 'hardware/newhw.html') return render(request, 'hardware/newhw.html')