from .models import School, User
import re
import string
import random
from mail import send_mail


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()
    token = ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.digits) for _ in range(40))
    user_obj = User.objects.create_user(email=email, school=school, password=password, token=token)
    user_obj.interestedInSchools.set(School.objects.all().values_list('id', flat=True))
    user_obj.save()
    send_mail(email, password, 'welcome')


def update_password(email):
    user = User.objects.get(email=email)  # Note: this raises an exception in no-match, so a non-user can deduct if an email has signed up for Unimeet

    password = User.objects.make_random_password()
    user.set_password(password)
    user.save()
    send_mail(email, password, 'forgot_password')

@@ -90,16 +90,58 @@
 end_mail
+, send_contact_form, send_contact_response
 %0A%0A%0Adef g
@@ -1499,8 +1499,134 @@
 sword')%0A
+%0A%0Adef handle_contact_form(name, email, message):%0A    send_contact_form(name, email, message)%0A    send_contact_response(email)%0A

Add handle_contact_form helper function