Skip to content

Commit

Permalink
Merge pull request #151 from hackupc/add_volunteers
Browse files Browse the repository at this point in the history
Add  script to add volunteers
  • Loading branch information
casassg authored Oct 12, 2017
2 parents 239fa43 + b29a2b0 commit fe955a7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ insert_missing.sh
check_invites.sh
app/prod_settings.py
tmp/
*.csv
2 changes: 1 addition & 1 deletion app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@

SITE_ID = 1
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_EMAIL_VERIFICATION = 'optional'
ACCOUNT_EMAIL_REQUIRED = True
SOCIALACCOUNT_ENABLED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
Expand Down
4 changes: 2 additions & 2 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
{% if perms.checkin.check_in %}
<li class="white-text"><a href="{% url 'check_in_list' %}">Check-in</a></li>
{% endif %}
{% if not perms.register.vote %}
{% if not perms.register.vote and not perms.checkin.check_in %}
<li class="white-text"><a href="{% url 'dashboard' %}">Dashboard</a></li>
<li class="white-text"><a href="{% url 'profile' %}">Profile</a></li>
{% endif %}
Expand All @@ -91,7 +91,7 @@
<ul class="dropdown-menu">
<li><a href="{% url 'account_change_password' %}">Change password</a></li>
<li><a href="{% url 'account_email' %}">Edit emails</a></li>
{% if perms.register.vote %}
{% if perms.register.vote or perms.checkin.check_in %}
<li><a href="{% url 'dashboard' %}">Dashboard</a></li>
<li><a href="{% url 'profile' %}">Profile</a></li>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def root_view(request):
if request.user.has_perm('register.vote'):
return HttpResponseRedirect(reverse('vote'))
elif request.user.has_perm('register.checkin'):
elif request.user.has_perm('checkin.check_in'):
return HttpResponseRedirect(reverse('check_in_list'))
try:
request.user.hacker
Expand Down
Empty file added checkin/management/__init__.py
Empty file.
Empty file.
49 changes: 49 additions & 0 deletions checkin/management/commands/add_volunteers.py
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])

0 comments on commit fe955a7

Please sign in to comment.