Commit 4494c307 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

initial cas callback configuration per bookshare

parent c6be4767
......@@ -8,7 +8,7 @@ from .models import Student
def pfinfo(uname):
base_url = "http://peoplefinder.b1.akshaykarthik.com/"
base_url = settings.PF_URL
url = base_url + "basic/all/" + str(uname)
try:
metadata = requests.get(url)
......@@ -17,25 +17,48 @@ def pfinfo(uname):
print e
else:
pfjson = metadata.json()
name = pfjson['results'][0]['name']
return name.split(',')
try:
name = pfjson['results'][0]['name']
return name.split(',')
# if the name is not in peoplefinder, return empty first and last name
except IndexError:
return ['', '']
def create_user(tree):
print 'hello'
print tree
username = tree[0][0].text
print username
user, user_created = User.objects.get_or_create(username=username)
print user_created, 'User Created!'
if user_created:
print user_created
user.email = "%s@%s" % (username, settings.ORGANIZATION_EMAIL_DOMAIN)
name_list = pfinfo(username)
user.first_name = name_list[1].rstrip()
user.last_name = name_list[0]
print user.email
user.save()
# name_list = pfinfo(str(username))
# print name_list
# list of empty strings is false
# first_name = name_list[1].rstrip().split(' ')
# if it's only a character long
# if len(first_name) > 1:
# # no middle initial
# no_mi = first_name[:-1]
# user.first_name = ' '.join(no_mi)
# else:
# user.first_name = ' '.join(first_name)
# last_name = name_list[0]
# user.last_name = last_name
#
# user.save()
print user
new_student = Student.objects.create(user=user)
new_student.save()
print new_student
print("Created user %s!" % username)
print "Created user %s!" % username
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment