From 48a517121955b52b6c6770a53d9e653a9aada44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Sun, 13 Nov 2011 11:38:47 +0100 Subject: [PATCH] Error-Handling im Client --- .../LegacyCustomerRelationsManagement.java | 7 +++++++ webapp/frontend/static/screen.css | 12 +++++++++++ webapp/frontend/templates/base.html | 9 ++++++++ webapp/frontend/templates/index.html | 1 + webapp/frontend/views.py | 21 +++++++++++++++---- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/at/ac/tuwien/infosys/aic11/legacy/LegacyCustomerRelationsManagement.java b/src/at/ac/tuwien/infosys/aic11/legacy/LegacyCustomerRelationsManagement.java index 68510c9..1310a09 100644 --- a/src/at/ac/tuwien/infosys/aic11/legacy/LegacyCustomerRelationsManagement.java +++ b/src/at/ac/tuwien/infosys/aic11/legacy/LegacyCustomerRelationsManagement.java @@ -45,6 +45,13 @@ private LegacyCustomerRelationsManagement() public Customer getCustomerByName(String name) throws LegacyException { + name = name.trim(); + + if(name.isEmpty()) + { + throw new LegacyException("Can't search for Customer without name (getCustomerByName)"); + } + for(Customer customer : customers.values()) { String fullname = customer.getFirstName() + " " + customer.getMiddleName() + " " + customer.getLastName(); diff --git a/webapp/frontend/static/screen.css b/webapp/frontend/static/screen.css index 7341909..75fafb6 100644 --- a/webapp/frontend/static/screen.css +++ b/webapp/frontend/static/screen.css @@ -52,3 +52,15 @@ th[colspan="2"] padding-top: 1em; font-size: 1.2em; } + + + +div.error +{ + margin-top: 3em; + border: thin solid #8B3130; + background-color: #B97F82; +width: 30%; + padding: .5em; + color: #523B51; +} diff --git a/webapp/frontend/templates/base.html b/webapp/frontend/templates/base.html index 5174619..10827a4 100644 --- a/webapp/frontend/templates/base.html +++ b/webapp/frontend/templates/base.html @@ -14,6 +14,15 @@

Credit Approval Client

{% block content %} {% endblock %} + +{% if messages %} + {% for message in messages %} + + {{ message }} + + {% endfor %} +{% endif %} + diff --git a/webapp/frontend/templates/index.html b/webapp/frontend/templates/index.html index 080eddf..4927131 100644 --- a/webapp/frontend/templates/index.html +++ b/webapp/frontend/templates/index.html @@ -16,5 +16,6 @@

Select Customer

+ {% endblock %} diff --git a/webapp/frontend/views.py b/webapp/frontend/views.py index c1de184..79d2a49 100644 --- a/webapp/frontend/views.py +++ b/webapp/frontend/views.py @@ -2,6 +2,7 @@ from django.template import RequestContext from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse +from django.contrib import messages from webapp.backend import creditapprovalclient, ratingclient from webapp.frontend import sessionstore @@ -23,9 +24,15 @@ def index(request): def enter_request(request): name = request.POST['name'] - customer = creditapprovalclient.getCustomerByName(name) - customer = ratingclient.setRating(customer) - sessionstore.set_customer(request, customer) + + try: + customer = creditapprovalclient.getCustomerByName(name) + customer = ratingclient.setRating(customer) + sessionstore.set_customer(request, customer) + + except Exception as e: + messages.error(request, e) + return HttpResponseRedirect(request.META['HTTP_REFERER']) return render_to_response('enter-request.html', { 'customer': customer, @@ -54,7 +61,13 @@ def show_warrantor(request): credit_req = sessionstore.get_request(request) - warrantor = creditapprovalclient.getCustomerByName(name) + try: + warrantor = creditapprovalclient.getCustomerByName(name) + except: + messages.error(request, 'Customer with name "{name}" not found'.format( + name=name)) + warrantor = None + if warrantor: warrantor = ratingclient.setRating(warrantor) credit_req.warrantors.append(warrantor)