Skip to content

Commit

Permalink
Merge pull request #556 from llewelld/iss543_userprofile_changes
Browse files Browse the repository at this point in the history
Update user profile fields
  • Loading branch information
llewelld authored Jul 31, 2023
2 parents 6eb4214 + d4c9f77 commit 8d891a4
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 61 deletions.
11 changes: 8 additions & 3 deletions server/apps/main/templatetags/custom_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# from django.contrib.auth.models import Group
from ..views import is_moderator
from django.template.defaultfilters import register
from urllib.parse import unquote
from urllib.parse import unquote


register = template.Library()
Expand All @@ -17,8 +17,8 @@ def toggle_story(val):
return 'story'
else:
return 'stories'
register.simple_tag(is_moderator)

register.simple_tag(is_moderator)

@register.filter
def unquote_html(value):
Expand All @@ -32,3 +32,8 @@ def url_replace(request, field, value):
query = request.GET.copy()
query[field] = value
return '?{}'.format(query.urlencode())

@register.filter
def field_type(field):
return field.__class__.__name__

7 changes: 5 additions & 2 deletions server/apps/main/tests/test_moderate_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ def setUp(self):
# User profile for user moderator_user_with_profile
user_profile = {
"profile_submitted": False,
"autistic_identification": "unspecified",
"age_bracket": "18-25",
"age_public": False,
"gender": "see_description",
"autistic_identification": "unspecified",
"gender_self_identification": "",
"gender_public": False,
"description": "Timelord",
"location": "Gallifrey",
"description_public": False,
"comms_review": False,
"abuse": False,
"violence": False,
Expand Down
7 changes: 5 additions & 2 deletions server/apps/main/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,14 @@ def setUp(self):
# User profile for user C
user_profile = {
"profile_submitted": False,
"autistic_identification": "unspecified",
"age_bracket": "18-25",
"age_public": False,
"gender": "see_description",
"autistic_identification": "unspecified",
"gender_self_identification": "",
"gender_public": False,
"description": "Timelord",
"location": "Gallifrey",
"description_public": False,
"comms_review": False,
"abuse": True,
"violence": False,
Expand Down
70 changes: 46 additions & 24 deletions server/apps/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@

class UserProfileForm(forms.Form):

autistic_identifications = [
("", "-----------"),
("yes", "Yes"),
("no", "No"),
("unspecified", "Prefer not to say"),
]
autistic_identification = forms.ChoiceField(choices = autistic_identifications, widget = forms.Select(),
label="Do you identify as autistic?",
help_text="AutSPACEs is focusing on collecting and sharing the voices and lived experiences of autistic people, which is why this is a mandatory question. If you select <i>prefer not to say</i> your answers will be considered as coming from a non-autistic person, labeled as such and e.g. not used for research.",
required=True)
autistic_identification.group = 1
autistic_identification.gap = True

age_brackets = [
("under 18", "Under 18"),
("18-25", "18-25"),
("26-35", "26-35"),
("36-45", "36-45"),
Expand All @@ -12,47 +24,57 @@ class UserProfileForm(forms.Form):
("unspecified", "Prefer not to say"),
]
age_bracket = forms.ChoiceField(choices = age_brackets, widget = forms.Select(), required=False,
label="What is your age?",
label="What is your age group?",
help_text="Providing your age will help researchers understand potential trends across age groups. It will also help readers to better understand your perspective if this data is made public.",
initial="unspecified")
age_bracket.group = 1

age_public = forms.BooleanField(label = "Make age public",
required=False,
widget=forms.CheckboxInput(attrs={"class": "custom-control-input"}))
age_public.group = 1
age_public.gap = True

genders = [
("nonbinary", "Non-binary"),
("female", "Female"),
("male", "Male"),
("see_description", "See description"),
("self_identify", "Self identify"),
("unspecified", "Prefer not to say"),
]
gender = forms.ChoiceField(choices = genders, widget = forms.Select(), required=False,
label="Which gender do you identify as?",
label="What gender do you identify with?",
help_text="Providing your gender identity will help researchers understand potential trends across this demographic. It will also help readers to better understand your perspective if this data is made public.",
initial="unspecified")
gender.group = 1

# Not intended as final
autistic_identifications = [
("yes", "Yes"),
("no", "No"),
("not_sure", "Not sure"),
("self_describe", "Prefer to self-describe"),
("unspecified", "Prefer not to say"),
]
autistic_identification = forms.ChoiceField(choices = autistic_identifications, widget = forms.Select(),
label="Do you identify as autistic?",
required=False, initial="unspecified")
autistic_identification.group = 1

description = forms.CharField(label="Description", max_length=2048, strip=True, required=False,
widget=forms.Textarea(attrs={"placeholder":"An optional description of yourself",
gender_self_identification = forms.CharField(label="Self identification",
max_length=150, strip=True, required=False,
widget=forms.TextInput())

gender_self_identification.group = 1
gender_self_identification.layout_horizontal = True

gender_public = forms.BooleanField(label = "Make gender public",
required=False,
widget=forms.CheckboxInput(attrs={"class": "custom-control-input"}))

gender_public.group = 1
gender_public.gap = True

description = forms.CharField(label="What else would you like researchers (or readers) to know about yourself?",
max_length=2048, strip=True, required=False,
help_text="You can provide any additional context about yourself here that you deem relevant to understanding your perspective and experiences. The AutSPACEs team will potential use your information to refine the structured demographic questions above. You can also make this information publicly accessible &mdash; which will be linked to your public experiences.",
widget=forms.Textarea(attrs={"placeholder":"Potential things you could talk about here include your ethnicity, whether you grew up/are living in a rural or urban environment, your educational background or really anything else that comes to your mind.",
"rows":"4",
"class":"form-control"}))
description.group = 1

location = forms.CharField(label="Location", max_length=500, initial="Earth", strip=True,
required=False,
widget=forms.TextInput(attrs={"placeholder":"Where do you live (town/city)",
"rows":"1",
"class":"form-control"}))
location.group = 1
description_public = forms.BooleanField(label = "Make description public",
required=False,
widget=forms.CheckboxInput(attrs={"class": "custom-control-input"}))
description_public.group = 1

# Add triggering here
abuse = forms.BooleanField(label = "Abuse (physical, sexual, emotional and verbal)",
Expand Down
37 changes: 37 additions & 0 deletions server/apps/users/migrations/0002_userprofile_refine_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.2.3 on 2023-07-26 16:01

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='userprofile',
name='age_public',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='userprofile',
name='description_public',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='userprofile',
name='gender_public',
field=models.BooleanField(default=False),
),
migrations.RemoveField(
model_name='userprofile',
name='location',
),
migrations.AddField(
model_name='userprofile',
name='gender_self_identification',
field=models.TextField(default=''),
),
]
7 changes: 5 additions & 2 deletions server/apps/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ class UserProfile(models.Model):
"""
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
profile_submitted = models.BooleanField(default=False)
autistic_identification = models.TextField(default="")
age_bracket = models.TextField(default="unspecified")
age_public = models.BooleanField(default=False)
gender = models.TextField(default="unspecified")
autistic_identification = models.TextField(default="unspecified")
gender_self_identification = models.TextField(default="")
gender_public = models.BooleanField(default=False)
description = models.TextField(default="")
location = models.TextField(default="")
description_public = models.BooleanField(default=False)
comms_review = models.BooleanField(default=False)

abuse = models.BooleanField(default=False)
Expand Down
37 changes: 26 additions & 11 deletions server/apps/users/templates/users/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

{% block content %}

<script src="{% static 'js/activate-profile.js' %}"></script>

{% if first_visit == True %}
<div class="container alert-container">
<div class="alert alert-info" role="alert">
Expand Down Expand Up @@ -41,13 +43,15 @@ <h3><label>Account</label></h3>
{% regroup form by field.group as field_groups %}

{% for group in field_groups %}
{% define "col-lg-12" as columns %}
{% if group.grouper == 1 %}
{% define "User Profile" as header %}
{% define "Please provide details you are comfortable sharing. All fields are optional." as subheader %}
{% endif %}
{% if group.grouper == 2 %}
{% define "Sensitive topics" as header %}
{% define "Select the trigger labels that you are comfortable viewing in the story list by default" as subheader %}
{% define "col-lg-6" as columns %}
{% endif %}
{% if group.grouper == 3 %}
{% define "Communication preferences" as header %}
Expand All @@ -65,20 +69,31 @@ <h5>{{ subheader }}</h5>
<br/>
<div class="row">
{% for field in group.list %}
{% if group.grouper >= 2 %}
<div class="form-check col-lg-6">
<div class="custom-control custom-switch">
{{ field }}
<label class="custom-control-label" for="{{ field.auto_id}}">{{ field.label }}</label>
</div>
</div>
<div class="form-check {{ columns }}">
{% if field.field.widget|field_type == "CheckboxInput" %}
<div class="custom-control custom-switch">
{{ field }}
<label class="custom-control-label" for="{{ field.auto_id }}">{{ field.label }}</label>
</div>
{% else %}
<div class="form-check col-lg-12">
<p/><label for="{{ field.auto_id}}">{{ field.label }}</label>
<br/>
{{ field }}
<p/><label for="{{ field.auto_id }}">{{ field.label }}</label>
{% if field.help_text %}
<a tabindex="0" role="button" class="btn btn-link" data-toggle="popover" data-trigger="focus"
data-html="true" title="{{ field.label }}" data-content="{{ field.help_text|safe }}">
<i class="bi bi-info-circle-fill"></i>
</a>
{% endif %}
{% if not field.field.layout_horizontal %}
<br/>
{% endif %}
{{ field }}
{% endif %}
</div>

{% if field.field.gap %}
<div class="form-check {{ columns }} mb-5"></div>
{% endif %}

{% endfor %}
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions server/apps/users/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ def setUp(self):
# Create a user profile
up_a_data = {
"profile_submitted": False,
"autistic_identification": "unspecified",
"age_bracket": "18-25",
"age_public": False,
"gender": "see_description",
"autistic_identification": "unspecified",
"gender_self_identification": "",
"gender_public": False,
"description": "Timelord",
"location": "Gallifrey",
"description_public": False,
"comms_review": False,
"abuse": False,
"violence": False,
Expand Down
17 changes: 12 additions & 5 deletions server/apps/users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ def setUp(self):
# Create a user profile
up_a_data = {
"profile_submitted": False,
"autistic_identification": "unspecified",
"age_bracket": "18-25",
"age_public": False,
"gender": "see_description",
"autistic_identification": "unspecified",
"gender_self_identification": "",
"gender_public": False,
"description": "Timelord",
"location": "Gallifrey",
"description_public": False,
"comms_review": False,
"abuse": False,
"violence": False,
Expand All @@ -65,11 +68,14 @@ def setUp(self):
# Create a user profile
up_b_data = {
"profile_submitted": False,
"autistic_identification": "childhood",
"age_bracket": "26-35",
"age_public": False,
"gender": "Female",
"autistic_identification": "childhood",
"gender_self_identification": "abcdabcd",
"gender_public": False,
"description": "Companion",
"location": "Earth",
"description_public": False,
"comms_review": True,
"abuse": False,
"violence": True,
Expand Down Expand Up @@ -164,6 +170,7 @@ def test_profile_submit(self):
response = c.post(
"/users/profile/",
{
"autistic_identification": "yes",
"description": "Described",
"comms_review": True,
},
Expand All @@ -186,6 +193,6 @@ def test_profile_rendering(self):
response = c.get("/users/profile/")
assert response.status_code == 200
self.assertContains(response, "Companion")
self.assertContains(response, "Earth")
self.assertContains(response, "abcdabcd")
self.assertContains(response, "26-35")

1 change: 0 additions & 1 deletion server/apps/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

logger = logging.getLogger(__name__)


def user_profile(request, first_visit=False):
"""
User profile page.
Expand Down
Loading

0 comments on commit 8d891a4

Please sign in to comment.