From b5839eb01d5298d638124ea95f60b950579e7e53 Mon Sep 17 00:00:00 2001 From: Art Rhyno Date: Tue, 5 Jul 2011 21:50:23 -0400 Subject: [PATCH] Fixing up situation where name values are null instead of blanks. Signed-off-by: Art Rhyno --- conifer/libsystems/evergreen/opensrf.py | 20 +++++++++++++++----- conifer/syrup/models.py | 17 ++++++++++++++--- conifer/syrup/views/admin.py | 5 ----- conifer/syrup/views/sites.py | 3 ++- conifer/templates/edit_site.xhtml | 7 +++++++ 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/conifer/libsystems/evergreen/opensrf.py b/conifer/libsystems/evergreen/opensrf.py index a6a29bf..833e7df 100644 --- a/conifer/libsystems/evergreen/opensrf.py +++ b/conifer/libsystems/evergreen/opensrf.py @@ -267,11 +267,21 @@ def ils_patron_lookup(name, is_staff=True, is_usrname=False, is_everyone=False): authtoken, patron, ["first_given_name","family_name","email","usrname"]) patron_info = req.send() - display = ('%s %s, ' - '<%s>. [%s]') % (patron_info.first_given_name(), - patron_info.family_name(), - patron_info.email(), patron_info.usrname()) - out.append((patron_info.usrname(), display)) + if patron_info.usrname(): + first_name = "" + family_name = "" + email = "" + if patron_info.first_given_name(): + first_name = patron_info.first_given_name() + if patron_info.family_name(): + family_name = patron_info.family_name() + if patron_info.email(): + email = patron_info.email() + display = ('%s %s, ' + '<%s>. [%s]') % (first_name, + family_name, + email, patron_info.usrname()) + out.append((patron_info.usrname(), display)) #clean up session session_cleanup(authtoken) diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 064bb22..3e048f6 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -125,9 +125,20 @@ class UserExtensionMixin(object): if dir_entry is None: return - self.first_name = dir_entry['given_name'] - self.last_name = dir_entry['surname'] - self.email = dir_entry.get('email', self.email) + first_name = "" + last_name = "" + email = "" + + if dir_entry['given_name']: + first_name = dir_entry['given_name'] + if dir_entry['surname']: + last_name = dir_entry['surname'] + if dir_entry.get('email', self.email): + email = dir_entry.get('email', self.email) + + self.first_name = first_name + self.last_name = last_name + self.email = email self.save() if 'patron_id' in dir_entry: diff --git a/conifer/syrup/views/admin.py b/conifer/syrup/views/admin.py index 993e775..457a8a4 100644 --- a/conifer/syrup/views/admin.py +++ b/conifer/syrup/views/admin.py @@ -156,18 +156,13 @@ def admin_staff_add(request): return g.render('admin/staff_add.xhtml', **locals()) else: userid = request.POST.get('userid','').strip() - print "userid", userid message_continue = True try: user = User.objects.get(username=userid) except User.DoesNotExist: - print "about to create" user = User.objects.create(username=userid) - print "created", user - print "1" user.maybe_decorate() - print "2" user.is_staff = True user.is_superuser = True # TODO: are we sure they should be superuser? diff --git a/conifer/syrup/views/sites.py b/conifer/syrup/views/sites.py index ad342c8..2523a13 100644 --- a/conifer/syrup/views/sites.py +++ b/conifer/syrup/views/sites.py @@ -69,7 +69,8 @@ def _add_or_edit_site(request, instance=None, basis=None): # then the owner may be a username instead of an ID, and # the user may not exist in the local database. userid = POST.get('owner', '').strip() - if userid and not userid.isdigit(): + is_barcode = re.search('\d{14}', userid) + if userid and (not userid.isdigit() or is_barcode): try: user = User.objects.get(username=userid) except User.DoesNotExist: diff --git a/conifer/templates/edit_site.xhtml b/conifer/templates/edit_site.xhtml index 8e96f77..3f2d8bb 100644 --- a/conifer/templates/edit_site.xhtml +++ b/conifer/templates/edit_site.xhtml @@ -54,6 +54,13 @@ owner = instance.owner if instance.owner_id else None style="display: ${'none' if owner else 'block'}">
Type a partial name or userid into the box; then select one of the matches.
+ + +
-- 2.11.0