Skip to content

Commit

Permalink
New user wizard (#954)
Browse files Browse the repository at this point in the history
* Format base css file

* Add button to study details page

* CSS for active navigation

* Store next value in session on sign up

* Add buttons to my account page

* Conditionally disable study links on account view

* Update conditional copy in demographics view

* Add child view conditional copy

* Add 'has_study_child' to demo template

* Remove study from session when study is attempted

* Redirect to demo view when save button is clicked

If there is no child, demo view will be redirect to child list view.

* Fix existing tests

* Added has_study_child to all my account views

* Update account navigation
  • Loading branch information
okaycj authored Apr 5, 2022
1 parent 709c230 commit 77c74c0
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 78 deletions.
26 changes: 24 additions & 2 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from django.contrib.postgres.fields.array import ArrayField
from django.core.mail.message import EmailMultiAlternatives
from django.db import models
from django.http import HttpRequest
from django.template.loader import get_template
from django.utils.html import mark_safe
from django.utils.text import slugify
Expand All @@ -28,7 +29,8 @@
from qrcode import make as make_qrcode
from qrcode.image.svg import SvgPathImage

from accounts.queries import BitfieldQuerySet
import studies
from accounts.queries import BitfieldQuerySet, get_child_eligibility_for_study
from studies.fields import CONDITIONS, GESTATIONAL_AGE_CHOICES, LANGUAGES
from studies.helpers import send_mail
from studies.permissions import (
Expand Down Expand Up @@ -163,7 +165,7 @@ def __init__(self, *args, **kwargs):
@property
def identicon(self):
if not self._identicon:
rbw = self._make_rainbow()
rbw = self._make_rainbow
generator = pydenticon.Generator(
5, 5, digest=hashlib.sha512, foreground=rbw, background="rgba(0,0,0,0)"
)
Expand Down Expand Up @@ -194,6 +196,26 @@ def slug(self):
"""Temporary workaround."""
return f"{slugify(self.nickname or 'anonymous')}-{str(self.uuid).split('-')[0]}"

@property
def has_any_child(self):
return self.children.filter(deleted=False).exists()

def has_study_child(self, request: HttpRequest) -> bool:
study_uuid = request.session.get("study_uuid", None)
if study_uuid:
study = studies.models.Study.objects.get(uuid=study_uuid)
children = self.children.filter(deleted=False)
return any(
get_child_eligibility_for_study(child, study) for child in children
)
else:
return False

@property
def has_demographics(self):
return self.demographics.exists()

@property
def _make_rainbow(self):
rbw = []
for i in range(0, 255, 10):
Expand Down
4 changes: 4 additions & 0 deletions accounts/templates/accounts/_account-navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
<a class="{% if current_page == 'manage-account' %} active {% endif %} btn btn-default btn-md btn-block" href="{% url 'accounts:manage-account' %}"><strong>{% trans "Account Information" %}</strong><br>{% trans "Change your login credentials and/or nickname." %}</a>
<a class="{% if current_page == 'demographic-update' %} active {% endif %} btn btn-default btn-md btn-block" href="{% url 'web:demographic-data-update' %}"><strong>{% trans "Demographic Survey" %}</strong><br>{% trans "Tell us more about yourself." %}</a>
<a class="{% if current_page == 'children-list' %} active {% endif %} btn btn-default btn-md btn-block" href="{% url 'web:children-list' %}"><strong>{% trans "Children Information" %}</strong><br>{% trans "Add or edit participant information." %}</a>
{% if request.session.study_name %}
<a class="btn btn-default btn-md btn-block btn-primary{% if not has_study_child or not user.has_demographics %} disabled{% endif %}" href="{% url 'web:study-detail' uuid=request.session.study_uuid %}"><strong>{% trans "Continue to Study" %}</strong><br>{% trans "Go on to" %} "{{ request.session.study_name|truncatechars:40 }}".</a>
{% endif %}
<a class="btn btn-default btn-md btn-block {% if not request.session.study_name %}btn-primary{% endif %}{% if not user.has_any_child or not user.has_demographics %} disabled{% endif %}" href="{% url 'web:studies-list' %}"><strong>{% if request.session.study_name %}{% trans "Find Another Study" %}{% else %}{% trans "Find a Study Now" %}{% endif %}</strong><br>{% trans "See all available studies." %}</a>
<a class="{% if current_page == 'email-preferences' %} active {% endif %} btn btn-default btn-md btn-block" href="{% url 'web:email-preferences' %}"><strong>{% trans "Email Preferences" %}</strong><br>{% trans "Edit when you can be contacted." %}</a>
3 changes: 2 additions & 1 deletion accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def get_context_data(self, **kwargs):
"otp_check_form": otp_check_form,
"user": user,
"otp": otp,
"has_study_child": user.has_study_child(self.request),
}
)

Expand All @@ -250,7 +251,7 @@ def _get_user_and_otp(self) -> Tuple[User, Union[GoogleAuthenticatorTOTP, None]]

def _get_forms(
self,
) -> (forms.AccountUpdateForm, forms.PasswordChangeForm, forms.TOTPCheckForm):
) -> Tuple[forms.AccountUpdateForm, forms.PasswordChangeForm, forms.TOTPCheckForm]:
"""Bind forms appropriately for method."""
request = self.request
# TODO: switch to normal attribute access after this is fixed
Expand Down
Loading

0 comments on commit 77c74c0

Please sign in to comment.