From acc30325a9e37c836c6acb1c19b402be4fb3328c Mon Sep 17 00:00:00 2001 From: Sounak Pradhan Date: Thu, 15 Aug 2019 16:19:28 +0530 Subject: [PATCH] Add github handle while registering --- gsoc/admin.py | 4 ++-- .../0052_userprofile_github_handle.py | 18 +++++++++++++++ gsoc/models.py | 21 +++++++++++++----- gsoc/templates/registration/register.html | 2 ++ gsoc/views.py | 4 +++- project.db | Bin 1552384 -> 1556480 bytes 6 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 gsoc/migrations/0052_userprofile_github_handle.py diff --git a/gsoc/admin.py b/gsoc/admin.py index d3762f77..347ea226 100644 --- a/gsoc/admin.py +++ b/gsoc/admin.py @@ -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') }) ) diff --git a/gsoc/migrations/0052_userprofile_github_handle.py b/gsoc/migrations/0052_userprofile_github_handle.py new file mode 100644 index 00000000..a355e43f --- /dev/null +++ b/gsoc/migrations/0052_userprofile_github_handle.py @@ -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), + ), + ] diff --git a/gsoc/models.py b/gsoc/models.py index dcdd6091..71dc813b 100644 --- a/gsoc/models.py +++ b/gsoc/models.py @@ -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) @@ -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() @@ -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 @@ -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') @@ -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) diff --git a/gsoc/templates/registration/register.html b/gsoc/templates/registration/register.html index 7d78b056..6af1aefb 100644 --- a/gsoc/templates/registration/register.html +++ b/gsoc/templates/registration/register.html @@ -24,6 +24,8 @@

Sign up for a PSF GSoC account!




+ +
I accept the Python Community Code of Conduct for the duration of the program.
Opt me in for notifications via email
diff --git a/gsoc/views.py b/gsoc/views.py index b6ccb3ae..93d0cfa5 100644 --- a/gsoc/views.py +++ b/gsoc/views.py @@ -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 @@ -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: diff --git a/project.db b/project.db index c72985726284129b6850f5a49100798052f65f74..efc5104bc46578537ed42a27f57f8eaad0082401 100644 GIT binary patch delta 955 zcmY+BZD>4I}s#=l;yc#B`#cx5q&`;D6#Ao$RB4-$XiF7A+H}TnHw*{{00&Tj2LwO_BtQlfKm|0w0XP92Z~<<> z!|HXLS>Wwb={4{b`2 z;ia~_-&k!wJ7{?9tpi38`{s~wkx<7Nmj$~SjvfEmo9^RQ(rH`VZR{a*8sr$=92tu8 z$lMm0Hy#dGRlILLy0^W%t*0s4*0`@F8LtSJ*M`D1q4FxLJiKOA^_t3>mEqco>Y7zd zsyF^F4r$Mj6W1d3hH^$Om41~h;i<5PkJ4|+1HH@n+}Q+|h&+I;A#w$NS23GTnrARu zpE68^!lHUX?ZT{SpE-dUO&hbja=R5L*5S$lRU^P@=DtH_^ofG&`bLgg=O}*5Bu&rh zqBe~boI$oLW(Ek(d>_%CF=t!YyagF-5*7 zRQpFOR%X#S6b`b14qqEg@zVT7BFM@`0<59k_W@?bv*z#3WiX10Rv^7a`$T2xBIUIF zQf`#0#FKmj$nOPP5%V{QEYsrqiL!X3PvPu8629^CE+q^m&Tr&g*Khjpm!bKF{0pRi zrMDGo5$`Lg76UO&-I5e!4LX!4{;z2;lL6E;y9gfZrBw_ J@;i-y_6DqD4~hT) delta 842 zcmYk)ZHP=!7y#gN&OP`0&b>3{-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