from .models import School, User
import re


def get_school_list():
    schools = School.objects.all()
    school_list = []
    for s in schools:
        school = {}
        school['id'] = s.id
        school['name'] = s.name
        school['site'] = s.site
        school['university'] = s.university.name
        school['city'] = s.university.city.name
        school['country'] = s.university.city.country.name
        school_list.append(school)
    return school_list


def get_school_by_email(email):
    for school in School.objects.all():
        if re.match(school.mailRegex, email):
            return school
    return None


def create_user(email, school):
    password = User.objects.make_random_password()
    user_obj = User.objects.create_user(email=email, school=school, password=password)
    user_obj.interestedInSchools.set(School.objects.all().values_list('id', flat=True))
    user_obj.save()
    # TODO: Send signup mail to user

@@ -36,16 +36,44 @@
 port re%0A
+import string%0Aimport random%0A
 %0A%0Adef ge
@@ -740,16 +740,125 @@
 sword()%0A
+    token = ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.digits) for _ in range(40))%0A
     user
@@ -934,16 +934,29 @@
 password
+, token=token
 )%0A    us
@@ -1037,16 +1037,16 @@
 =True))%0A
-
     user
@@ -1057,16 +1057,82 @@
 .save()%0A
+    print 'Email:', email, 'Password:', password, 'Token:', token%0A
     # TO

Create random auth token on user signup