mirror of
https://github.com/etnguyen03/tjdests.git
synced 2025-04-20 09:40:16 -04:00
feat: add nickname field
This commit is contained in:
parent
a7e57d34a4
commit
d57d145bec
|
@ -4,8 +4,8 @@ from .models import User
|
||||||
|
|
||||||
|
|
||||||
class UserAdmin(admin.ModelAdmin):
|
class UserAdmin(admin.ModelAdmin):
|
||||||
search_fields = ["username", "first_name", "last_name"]
|
search_fields = ["username", "preferred_name", "last_name"]
|
||||||
list_display = ["username", "last_name", "first_name", "last_modified"]
|
list_display = ["username", "last_name", "preferred_name", "last_modified"]
|
||||||
list_filter = ["is_senior", "is_student", "accepted_terms", "publish_data"]
|
list_filter = ["is_senior", "is_student", "accepted_terms", "publish_data"]
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
|
@ -14,8 +14,9 @@ class UserAdmin(admin.ModelAdmin):
|
||||||
{
|
{
|
||||||
"fields": (
|
"fields": (
|
||||||
"username",
|
"username",
|
||||||
"first_name",
|
"preferred_name",
|
||||||
"last_name",
|
"last_name",
|
||||||
|
"nickname",
|
||||||
"email",
|
"email",
|
||||||
"password",
|
"password",
|
||||||
"accepted_terms",
|
"accepted_terms",
|
||||||
|
|
18
tjdests/apps/authentication/migrations/0010_user_nickname.py
Normal file
18
tjdests/apps/authentication/migrations/0010_user_nickname.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.5 on 2021-07-28 02:07
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("authentication", "0009_user_last_modified"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="user",
|
||||||
|
name="nickname",
|
||||||
|
field=models.CharField(blank=True, max_length=30),
|
||||||
|
),
|
||||||
|
]
|
|
@ -13,6 +13,8 @@ class User(AbstractUser):
|
||||||
is_senior = models.BooleanField(default=False)
|
is_senior = models.BooleanField(default=False)
|
||||||
is_student = models.BooleanField(default=False)
|
is_student = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
nickname = models.CharField(max_length=30, blank=True)
|
||||||
|
|
||||||
# The rest are used only if a senior
|
# The rest are used only if a senior
|
||||||
publish_data = models.BooleanField(
|
publish_data = models.BooleanField(
|
||||||
default=False,
|
default=False,
|
||||||
|
@ -33,5 +35,9 @@ class User(AbstractUser):
|
||||||
|
|
||||||
last_modified = models.DateTimeField(auto_now=True)
|
last_modified = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def preferred_name(self):
|
||||||
|
return self.nickname if self.nickname else self.first_name
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.first_name} {self.last_name}"
|
return f"{self.preferred_name} {self.last_name}"
|
||||||
|
|
|
@ -28,6 +28,7 @@ class IonOauth2(BaseOAuth2): # pylint: disable=abstract-method
|
||||||
"username": profile["ion_username"],
|
"username": profile["ion_username"],
|
||||||
"first_name": profile["first_name"],
|
"first_name": profile["first_name"],
|
||||||
"last_name": profile["last_name"],
|
"last_name": profile["last_name"],
|
||||||
|
"nickname": profile["nickname"] if profile["nickname"] else "",
|
||||||
"full_name": profile["full_name"],
|
"full_name": profile["full_name"],
|
||||||
"email": profile["tj_email"],
|
"email": profile["tj_email"],
|
||||||
"is_student": profile["is_student"],
|
"is_student": profile["is_student"],
|
||||||
|
|
|
@ -58,6 +58,7 @@ class DestinationsTest(TJDestsTestCase):
|
||||||
)
|
)
|
||||||
user2.first_name = "Adam"
|
user2.first_name = "Adam"
|
||||||
user2.last_name = "William"
|
user2.last_name = "William"
|
||||||
|
user2.nickname = "John"
|
||||||
user2.save()
|
user2.save()
|
||||||
|
|
||||||
college2 = College.objects.get_or_create(name="university of test")[0]
|
college2 = College.objects.get_or_create(name="university of test")[0]
|
||||||
|
@ -114,11 +115,18 @@ class DestinationsTest(TJDestsTestCase):
|
||||||
self.assertIn(user, response.context["object_list"])
|
self.assertIn(user, response.context["object_list"])
|
||||||
self.assertNotIn(user2, response.context["object_list"])
|
self.assertNotIn(user2, response.context["object_list"])
|
||||||
|
|
||||||
|
# Adam "John" William should show up when searching "Adam", his first name...
|
||||||
response = self.client.get(reverse("destinations:students"), data={"q": "Adam"})
|
response = self.client.get(reverse("destinations:students"), data={"q": "Adam"})
|
||||||
self.assertEqual(200, response.status_code)
|
self.assertEqual(200, response.status_code)
|
||||||
self.assertNotIn(user, response.context["object_list"])
|
self.assertNotIn(user, response.context["object_list"])
|
||||||
self.assertIn(user2, response.context["object_list"])
|
self.assertIn(user2, response.context["object_list"])
|
||||||
|
|
||||||
|
# ...and he should show up when searching "John", his middle name
|
||||||
|
response = self.client.get(reverse("destinations:students"), data={"q": "John"})
|
||||||
|
self.assertEqual(200, response.status_code)
|
||||||
|
self.assertNotIn(user, response.context["object_list"])
|
||||||
|
self.assertIn(user2, response.context["object_list"])
|
||||||
|
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
reverse("destinations:students"), data={"q": "William"}
|
reverse("destinations:students"), data={"q": "William"}
|
||||||
)
|
)
|
||||||
|
|
|
@ -42,6 +42,7 @@ class StudentDestinationListView(
|
||||||
queryset = queryset.filter(
|
queryset = queryset.filter(
|
||||||
Q(first_name__icontains=search_query)
|
Q(first_name__icontains=search_query)
|
||||||
| Q(last_name__icontains=search_query)
|
| Q(last_name__icontains=search_query)
|
||||||
|
| Q(nickname__icontains=search_query)
|
||||||
| Q(biography__icontains=search_query)
|
| Q(biography__icontains=search_query)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Profile</h2>
|
<h2>Profile</h2>
|
||||||
<p>You are {{ request.user.username }}, {{ request.user.first_name }} {{ request.user.last_name }}.</p>
|
<p>You are {{ request.user.username }}, {{ request.user.preferred_name }} {{ request.user.last_name }}.</p>
|
||||||
|
|
||||||
<h4>Data Publication, College Attending, Biography</h4>
|
<h4>Data Publication, College Attending, Biography</h4>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user