-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delegate Account Creation #631
Merged
m-j-mcdonald
merged 6 commits into
bmun:master
from
m-j-mcdonald:delegate_account_creation
Oct 12, 2017
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9a8aa7a
Delegate Account Creation
m-j-mcdonald 9ff5ca8
Ran autoformatter
m-j-mcdonald 6ec2975
Reduce calls on database
m-j-mcdonald e1f54bb
Ran autoformatter
m-j-mcdonald 3b89df5
Fixed reassigning bug
m-j-mcdonald 2bd63b0
Ran autoformatter
m-j-mcdonald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,11 +1,17 @@ | ||
# Copyright (c) 2011-2015 Berkeley Model United Nations. All rights reserved. | ||
# Use of this source code is governed by a BSD License (see LICENSE). | ||
|
||
from datetime import datetime | ||
|
||
from django.contrib.auth.base_user import BaseUserManager | ||
from django.core.mail import send_mail | ||
|
||
from rest_framework import serializers | ||
|
||
from huxley.accounts.models import User | ||
from huxley.api.serializers.assignment import AssignmentNestedSerializer | ||
from huxley.api.serializers.school import SchoolSerializer | ||
from huxley.core.models import Delegate | ||
from huxley.core.models import Assignment, Delegate | ||
|
||
|
||
class DelegateSerializer(serializers.ModelSerializer): | ||
|
@@ -25,6 +31,35 @@ class Meta: | |
'session_three', | ||
'session_four', ) | ||
|
||
def update(self, instance, validated_data): | ||
if ('assignment' in validated_data and | ||
validated_data['assignment'] != None and | ||
not instance.assignment and | ||
not User.objects.filter(delegate__id=instance.id).exists()): | ||
|
||
names = instance.name.split(' ') | ||
username = names[0] + '_' + str(instance.id) | ||
password = BaseUserManager().make_random_password(10) | ||
user = User.objects.create_user( | ||
username=username, | ||
password=password, | ||
delegate=instance, | ||
user_type=User.TYPE_DELEGATE, | ||
first_name=names[0], | ||
last_name=names[-1], | ||
email=instance.email) | ||
|
||
send_mail('A new account has been created for {0}!\n'.format(instance.name), | ||
'Username: {0}\n'.format(username) \ | ||
+ 'Password: {0}\n'.format(password) \ | ||
+ 'Please save this information! You will need it for ' | ||
+ 'important information and actions. You can access ' | ||
+ 'this account at huxley.bmun.org.', | ||
'[email protected]', | ||
[instance.email], fail_silently=False) | ||
|
||
return super(DelegateSerializer, self).update(instance, validated_data) | ||
|
||
|
||
class DelegateNestedSerializer(serializers.ModelSerializer): | ||
assignment = AssignmentNestedSerializer(read_only=True) | ||
|
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,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.7 on 2017-09-27 20:10 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [('core', '0023_auto_20170809_1436'), ] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='delegate', | ||
name='email', | ||
field=models.EmailField( | ||
default='', max_length=254), | ||
preserve_default=False, ), | ||
] |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remind me why this was disabled in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was done in #576, I assume to disable some functionality before conference. This ties into why I opened #632