#!/usr/bin/python
#
# run as:
#   ./manage.py shell < load_users.py
#
# requires users.csv in the current directory with a format like:
#   aavisual,andersam,Sam,Andrews,sam.andrews@gmail.com

import csv

from django.contrib.auth.models import User

with open('users.csv', 'r') as csvfile:
    reader = csv.reader(csvfile)
    for row in reader:
        pw,login,fname,lname,email = row
        print('creating user: {} {} ({}) {} - {}'.format(fname, lname, login, email, pw))
        user = User.objects.create_user(login, password=pw)
        user.first_name = fname
        user.last_name = lname
        user.email = email
        user.is_superuser = False
        user.is_staff = False
        user.save()
