Skip to content

Commit

Permalink
Add github handle while registering
Browse files Browse the repository at this point in the history
  • Loading branch information
sounak98 committed Aug 15, 2019
1 parent afa856a commit acc3032
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
4 changes: 2 additions & 2 deletions gsoc/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,14 @@ class HiddenUserProfileAdmin(admin.ModelAdmin):
'hidden', 'reminder_disabled', 'current_blog_count')
list_filter = ('hidden', 'reminder_disabled')
readonly_fields = ('user', 'role', 'gsoc_year', 'accepted_proposal_pdf', 'blog_link',
'proposal_confirmed', 'current_blog_count')
'proposal_confirmed', 'current_blog_count', 'github_handle')
fieldsets = (
('Unhide', {
'fields': ('hidden', 'reminder_disabled')
}),
('User Profile Details', {
'fields': ('user', 'role', 'gsoc_year', 'accepted_proposal_pdf', 'proposal_confirmed',
'blog_link', 'current_blog_count')
'blog_link', 'current_blog_count', 'github_handle')
})
)

Expand Down
18 changes: 18 additions & 0 deletions gsoc/migrations/0052_userprofile_github_handle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.10 on 2019-08-15 10:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('gsoc', '0051_auto_20190814_1454'),
]

operations = [
migrations.AddField(
model_name='userprofile',
name='github_handle',
field=models.TextField(blank=True, max_length=100, null=True),
),
]
21 changes: 15 additions & 6 deletions gsoc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def save(self, *args, **kwargs):
'name': ' '.join((
self.owner.first_name,
self.owner.last_name,
)),
})[0]
)),
})[0]
# slug would be generated by TranslatedAutoSlugifyMixin
super(Article, self).save(*args, **kwargs)

Expand Down Expand Up @@ -384,6 +384,7 @@ class UserProfile(models.Model):
hidden = models.BooleanField(name='hidden', default=False)
reminder_disabled = models.BooleanField(default=False)
current_blog_count = models.IntegerField(default=0)
github_handle = models.TextField(null=True, blank=True, max_length=100)

objects = UserProfileManager()
all_objects = models.Manager()
Expand Down Expand Up @@ -766,16 +767,24 @@ def is_usable(self):
timenow = timezone.now()
return (not self.is_used) and self.created_at < timenow

def create_user(self, *args, is_staff=True, reminder_disabled=False, **kwargs):
def create_user(self, *args, is_staff=True, reminder_disabled=False,
github_handle=None, **kwargs):
namespace = str(uuid.uuid4())
email = kwargs.get('email', self.email)
user, status = User.objects.get_or_create(*args, is_staff=is_staff,
email=email, **kwargs)
if not status:
profiles = user.userprofile_set.all()
for _ in profiles:
github_handle = profile.github_handle

role = {k: v for v, k in UserProfile.ROLES}
profile = UserProfile.objects.create(user=user, role=self.user_role,
gsoc_year=self.user_gsoc_year,
suborg_full_name=self.user_suborg,
reminder_disabled=reminder_disabled)
reminder_disabled=reminder_disabled,
github_handle=github_handle
)
if self.user_role != role.get('Student', 3):
return user

Expand Down Expand Up @@ -928,7 +937,7 @@ class SendEmail(models.Model):
('suborg_admins', 'Suborg Admins'),
('admins', 'Admins'),
('all', 'All')
)
)

to = models.CharField(null=True, blank=True, max_length=255,
help_text='Separate email with a comma')
Expand Down Expand Up @@ -967,7 +976,7 @@ def save(self, *args, **kwargs):
subject=self.subject,
template_data={
'body': self.body
})
})
self.scheduler = Scheduler.objects.create(command='send_email',
data=scheduler_data,
activation_date=self.activation_date)
Expand Down
2 changes: 2 additions & 0 deletions gsoc/templates/registration/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ <h2>Sign up for a PSF GSoC account!</h2><br>
<input id='id_password2' type="password" name="password2"><br>
<label for="id_email">Your email address.</label>
<input id='id_email' type="email" value="{{ email }}" readonly="readonly"><br>
<label for="id_github_handle">Your github handle.</label>
<input id='id_github_handle' type="text" name="github_handle"><br>
<input id="check" name="checkbox" type="checkbox"> I accept the <a href="https://www.python.org/psf/codeofconduct/" target="_blank">Python Community Code of Conduct</a> for the duration of the program.<br>
<input id="check" name="email_opt_in" type="checkbox"> Opt me in for notifications via email<br>
<button type="submit" id="btncheck" class="pure-button pure-button-primary" >Submit</button>
Expand Down
4 changes: 3 additions & 1 deletion gsoc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def register_view(request):
username = request.POST.get('username', '')
password = request.POST.get('password', '')
password2 = request.POST.get('password2', '')
github_handle = request.POST.get('github_handle', '')
email_opt_in = request.POST.get('email_opt_in')
reminder_disabled = False if email_opt_in == 'on' else True
info_valid = True
Expand Down Expand Up @@ -249,7 +250,8 @@ def register_view(request):
info_valid = False

if info_valid:
user = reglink.create_user(username=username, reminder_disabled=reminder_disabled)
user = reglink.create_user(username=username, reminder_disabled=reminder_disabled,
github_handle=github_handle)
user.set_password(password)
user.save()
else:
Expand Down
Binary file modified project.db
Binary file not shown.

0 comments on commit acc3032

Please sign in to comment.