-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from hackupc/add_volunteers
Add script to add volunteers
- Loading branch information
Showing
7 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ insert_missing.sh | |
check_invites.sh | ||
app/prod_settings.py | ||
tmp/ | ||
*.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import csv | ||
import sys | ||
|
||
from django.contrib.auth import authenticate | ||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.models import Permission | ||
from django.core.management.base import BaseCommand | ||
|
||
EXPORT_CSV_FIELDS = ['username', 'email', 'password', ] | ||
|
||
User = get_user_model() | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Shows applications filtered by state as CSV' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('-f', | ||
dest='csv_filename', | ||
default=False, | ||
help='csv filename') | ||
|
||
def handle(self, *args, **options): | ||
|
||
with open(options['csv_filename']) as csv_f: | ||
for row in csv.reader(csv_f): | ||
username = row[0] | ||
email = row[1] | ||
password = row[2] | ||
try: | ||
user = User.objects.filter(email=email).first() | ||
|
||
if not user: | ||
print 'Creating user {0}.'.format(email) | ||
user = User.objects.create_user(username=username, email=email) | ||
user.set_password(password) | ||
else: | ||
print 'Updating permissions for user {0}.'.format(email) | ||
|
||
checkin_perm = Permission.objects.get(codename='check_in') | ||
user.user_permissions.add(checkin_perm) | ||
user.save() | ||
assert authenticate(username=username, password=password) | ||
|
||
print 'User {0} successfully created.'.format(email) | ||
|
||
except: | ||
print 'There was a problem creating the user: {0}. Error: {1}.' \ | ||
.format(email, sys.exc_info()[1]) |