cas_callbacks.py 1.1 KB
Newer Older
1
2
3
from django.contrib.auth.models import User
from django.conf import settings

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from .models import Student

import requests

def pfinfo(u_name):
    pf_url = "http://peoplefinder.b1.akshaykarthik.com/"
    url = str(pf_url) + "basic/all/" + str(u_name)
    try:
        metadata = requests.get(url)
        metadata.raise_for_status()
    except requests.exceptions.RequestException as e:
        print e
    else:
        pf_json = metadata.json()
        name = pf_json['results'][0]['name']
        return name.split(',')

21
22
23
def create_user(tree):

    username = tree[0][0].text
24
    print username
25
26
27
28
    user, user_created = User.objects.get_or_create(username=username)

    if user_created:
        user.email = "%s@%s" % (username, settings.ORGANIZATION_EMAIL_DOMAIN)
29
30
31
32
33
34
#        print "hello"
#        name_list = pfinfo(str(username))
#        print "world"
#        user.first_name = name_list[1].rstrip()
#        print "something"
#        user.last_name = name_list[0]
35
        user.save()
Daniel W Bond's avatar
Daniel W Bond committed
36
37
        new_student = Student.objects.create(user=user)
        new_student.save()
38
39

        print("Created user %s!" % username)