From cf7923f62ae4b4c47aa29d56c82efc906413e487 Mon Sep 17 00:00:00 2001 From: Shreyas Mayya <2022smayya@tjhsst.edu> Date: Sun, 30 Jan 2022 12:51:49 -0500 Subject: [PATCH] feat(profile): make nickname optional --- .../migrations/0011_user_use_nickname.py | 18 ++++++++++++++++++ tjdests/apps/authentication/models.py | 7 ++++++- tjdests/apps/profile/forms.py | 2 +- tjdests/static/main.js | 7 +++++++ tjdests/templates/profile/profile.html | 7 +++++-- 5 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 tjdests/apps/authentication/migrations/0011_user_use_nickname.py diff --git a/tjdests/apps/authentication/migrations/0011_user_use_nickname.py b/tjdests/apps/authentication/migrations/0011_user_use_nickname.py new file mode 100644 index 0000000..cba0438 --- /dev/null +++ b/tjdests/apps/authentication/migrations/0011_user_use_nickname.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.11 on 2022-01-30 17:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0010_user_nickname'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='use_nickname', + field=models.BooleanField(default=False, help_text='If this is set, your nickname will be used to identify you across the site.', verbose_name='Use nickname instead of first name'), + ), + ] diff --git a/tjdests/apps/authentication/models.py b/tjdests/apps/authentication/models.py index 585fa45..02ec2a3 100644 --- a/tjdests/apps/authentication/models.py +++ b/tjdests/apps/authentication/models.py @@ -14,6 +14,11 @@ class User(AbstractUser): is_student = models.BooleanField(default=False) nickname = models.CharField(max_length=30, blank=True) + use_nickname = models.BooleanField( + default=(nickname is not None), + verbose_name="Use nickname instead of first name", + help_text="If this is set, your nickname will be used to identify you across the site.", + ) # The rest are used only if a senior publish_data = models.BooleanField( @@ -37,7 +42,7 @@ class User(AbstractUser): @property def preferred_name(self): - return self.nickname if self.nickname else self.first_name + return self.nickname if self.nickname and self.use_nickname else self.first_name def __str__(self): return f"{self.preferred_name} {self.last_name}" diff --git a/tjdests/apps/profile/forms.py b/tjdests/apps/profile/forms.py index afc5175..351ee72 100644 --- a/tjdests/apps/profile/forms.py +++ b/tjdests/apps/profile/forms.py @@ -36,7 +36,7 @@ class ProfilePublishForm(forms.ModelForm): class Meta: model = User - fields = ["publish_data", "GPA", "biography", "attending_decision"] + fields = ["use_nickname", "publish_data", "GPA", "biography", "attending_decision"] help_texts = { "biography": "ECs, intended major, advice, etc. Markdown is supported.", diff --git a/tjdests/static/main.js b/tjdests/static/main.js index 9048241..90791a9 100644 --- a/tjdests/static/main.js +++ b/tjdests/static/main.js @@ -15,4 +15,11 @@ $(document).ready(function(){ $(this).prop("checked", confirmreturn) } }) + + /* Hide "Use nickname" checkbox if person doesn't have a nickname + The box won't do anything if they don't have a nickname, + but it's nice to just get it out of the way, you know? */ + if ($("#without-nickname").length) { + $("#div_id_use_nickname").hide(); + } }) \ No newline at end of file diff --git a/tjdests/templates/profile/profile.html b/tjdests/templates/profile/profile.html index a83aeda..bff4c46 100644 --- a/tjdests/templates/profile/profile.html +++ b/tjdests/templates/profile/profile.html @@ -4,8 +4,11 @@ {% block content %}

Profile

-

You are {{ request.user.username }}, {{ request.user.preferred_name }} {{ request.user.last_name }}.

- + {% if request.user.nickname %} +

You are {{ request.user.username }}, {{ request.user.first_name }} {{ request.user.last_name }} ({{ request.user.nickname }}).

+ {% else %} +

You are {{ request.user.username }}, {{ request.user.preferred_name }} {{ request.user.last_name }}.

+ {% endif %}

Data Publication, College Attending, Biography

{% if request.user.is_senior %}