diff options
author | Filipp Lepalaan <filipp@mac.com> | 2015-11-16 11:49:07 +0200 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2015-11-16 11:49:07 +0200 |
commit | bda127bd38b496c64abeec6d5ba7c0a09eddcb3f (patch) | |
tree | 578f5ad8a4e4c62a363cfe280859f7dfd7a73e27 /servo | |
parent | ae51ca63fc46ae2375c6966d0ab24d5213f36315 (diff) | |
download | Servo-bda127bd38b496c64abeec6d5ba7c0a09eddcb3f.tar.gz Servo-bda127bd38b496c64abeec6d5ba7c0a09eddcb3f.tar.bz2 Servo-bda127bd38b496c64abeec6d5ba7c0a09eddcb3f.zip |
Move customer and device search to separate functions
Diffstat (limited to 'servo')
-rw-r--r-- | servo/views/checkin.py | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/servo/views/checkin.py b/servo/views/checkin.py index 66b83f8..4ef84e5 100644 --- a/servo/views/checkin.py +++ b/servo/views/checkin.py @@ -26,6 +26,38 @@ from servo.forms import (SerialNumberForm, AppleSerialNumberForm, QuestionForm, AttachmentForm, StatusCheckForm,) +def find_device(request): + device = Device(sn=request.GET['sn']) + device.description = _('Other Device') + device_form = DeviceForm(instance=device) + + try: + apple_sn_validator(device.sn) + except Exception as e: # not an Apple serial number + return render(request, "checkin/device_form.html", locals()) + + try: + device = get_device(request, device.sn) + device_form = DeviceForm(instance=device) + except GsxError as e: + error = e + + return render(request, "checkin/device_form.html", locals()) + + +def find_customer(request, phone): + if not request.user.is_authenticated(): + return + + results = [] + + for c in Customer.objects.filter(phone=phone): + title = '%s - %s' % (c.phone, c.name) + results.append({'id': c.pk, 'name': c.name, 'title': title}) + + return json_response(results) + + def init_locale(request): lc = settings.INSTALL_LOCALE.split('.') locale.setlocale(locale.LC_TIME, lc) @@ -80,7 +112,6 @@ def get_device(request, sn): def reset_session(request): - # initialize some basic vars if not request.user.is_authenticated(): request.session.flush() @@ -367,38 +398,10 @@ def index(request): # Checklists probably not configured pass - phone = request.GET.get('phone') - - if phone: - - if not request.user.is_authenticated(): - return - - results = [] - - for c in Customer.objects.filter(phone=phone): - title = '%s - %s' % (c.phone, c.name) - results.append({'id': c.pk, 'name': c.name, 'title': title}) - - return json_response(results) + if request.GET.get('phone'): + return find_customer(request, request.GET['phone']) if request.GET.get('sn'): - - device = Device(sn=request.GET['sn']) - device.description = _('Other Device') - device_form = DeviceForm(instance=device) - - try: - apple_sn_validator(device.sn) - except Exception as e: # not an Apple serial number - return render(request, "checkin/device_form.html", locals()) - - try: - device = get_device(request, device.sn) - device_form = DeviceForm(instance=device) - except GsxError as e: - error = e - - return render(request, "checkin/device_form.html", locals()) + return find_device(request) return render(request, "checkin/newindex.html", locals()) |