mirror of
https://github.com/etnguyen03/tjdests.git
synced 2025-04-21 02:00:16 -04:00
feat(profile): make nickname optional
This commit is contained in:
parent
6a743c1144
commit
cf7923f62a
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -14,6 +14,11 @@ class User(AbstractUser):
|
||||||
is_student = models.BooleanField(default=False)
|
is_student = models.BooleanField(default=False)
|
||||||
|
|
||||||
nickname = models.CharField(max_length=30, blank=True)
|
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
|
# The rest are used only if a senior
|
||||||
publish_data = models.BooleanField(
|
publish_data = models.BooleanField(
|
||||||
|
@ -37,7 +42,7 @@ class User(AbstractUser):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def preferred_name(self):
|
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):
|
def __str__(self):
|
||||||
return f"{self.preferred_name} {self.last_name}"
|
return f"{self.preferred_name} {self.last_name}"
|
||||||
|
|
|
@ -36,7 +36,7 @@ class ProfilePublishForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ["publish_data", "GPA", "biography", "attending_decision"]
|
fields = ["use_nickname", "publish_data", "GPA", "biography", "attending_decision"]
|
||||||
|
|
||||||
help_texts = {
|
help_texts = {
|
||||||
"biography": "ECs, intended major, advice, etc. Markdown is supported.",
|
"biography": "ECs, intended major, advice, etc. Markdown is supported.",
|
||||||
|
|
|
@ -15,4 +15,11 @@ $(document).ready(function(){
|
||||||
$(this).prop("checked", confirmreturn)
|
$(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();
|
||||||
|
}
|
||||||
})
|
})
|
|
@ -4,8 +4,11 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Profile</h2>
|
<h2>Profile</h2>
|
||||||
<p>You are {{ request.user.username }}, {{ request.user.preferred_name }} {{ request.user.last_name }}.</p>
|
{% if request.user.nickname %}
|
||||||
|
<p id="with-nickname">You are {{ request.user.username }}, {{ request.user.first_name }} {{ request.user.last_name }} ({{ request.user.nickname }}).</p>
|
||||||
|
{% else %}
|
||||||
|
<p id="without-nickname">You are {{ request.user.username }}, {{ request.user.preferred_name }} {{ request.user.last_name }}.</p>
|
||||||
|
{% endif %}
|
||||||
<h4>Data Publication, College Attending, Biography</h4>
|
<h4>Data Publication, College Attending, Biography</h4>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{% if request.user.is_senior %}
|
{% if request.user.is_senior %}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user