Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CONCD-546 Allow users to add first/ last name data via profile page #2149

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions concordia/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def confirm_login_allowed(self, user):
raise forms.ValidationError(inactive_message, code="inactive")


class UserNameForm(forms.Form):
first_name = forms.CharField(label="", required=False)
last_name = forms.CharField(label="", required=False)


class UserProfileForm(forms.Form):
email = forms.EmailField(label="", required=True)

Expand Down
2 changes: 1 addition & 1 deletion concordia/static/scss/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ table.table thead.border-y {
cursor: default;
}

.email-address {
.user-fields {
margin-bottom: ($spacer * 1.5) !important;
max-width: 450px;
}
Expand Down
34 changes: 32 additions & 2 deletions concordia/templates/account/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ <h2>Account Settings</h2>
<div class="mb-2">
<span class="font-weight-bold">User Name</span>: {{ user.username }}
</div>
{% if user.first_name %}
<div class="mb-2">
<span class="font-weight-bold">First Name</span>: {{ user.first_name }}
</div>
{% endif %}
{% if user.last_name %}
<div class="mb-2">
<span class="font-weight-bold">Last Name</span>: {{ user.last_name }}
</div>
{% endif %}
</div>
<div class="col-12 col-md-10 py-3 change-options">
<form class="form" action="{% url 'user-profile' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="mb-3 user-fields">
<label>
<span class="visually-hidden">First Name</span>
</label>
<input name="first_name" placeholder="Enter your first name" class="form-control font-italic">
<label>
<span class="visually-hidden">Last Name</span>
</label>
<input name="last_name" placeholder="Enter your last name" class="form-control font-italic">
<div class="input-group-append">
{% bootstrap_button "Save Changes" button_type="submit" button_class="btn btn-primary rounded-0" name="submit_name" %}
</div>
</div>
</form>
</div>
<div class="col-12 col-md-10">
<div class="mt-1 mb-3">
<span class="font-weight-bold">Email address</span>: {{ user.email }}
</div>
Expand All @@ -49,11 +79,11 @@ <h2>Account Settings</h2>
<form class="form needs-validation" action="{% url 'user-profile' %}" method="POST" enctype="multipart/form-data" novalidate>
{% csrf_token %}

<div class="input-group mb-3 email-address">
<div class="input-group mb-3 user-fields">
<label for="id_email"><span class="visually-hidden">Email</span></label>
<input type="email" name="email" placeholder="Change your email address" class="form-control font-italic" title="" required="" id="id_email" required>
<div class="input-group-append">
{% bootstrap_button "Save Change" button_type="submit" button_class="btn btn-primary rounded-0" %}
{% bootstrap_button "Save Change" button_type="submit" button_class="btn btn-primary rounded-0" name="submit_email" %}
</div>
{% if valid is True %}
<div class="mt-1 text-success w-100" id="validation-confirmation"><i class="fa fa-check-circle"></i> Email changed successfully; <strong>Check email to confirm address</strong></div>
Expand Down
15 changes: 13 additions & 2 deletions concordia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
AllowInactivePasswordResetForm,
ContactUsForm,
UserLoginForm,
UserNameForm,
UserProfileForm,
UserRegistrationForm,
)
Expand Down Expand Up @@ -482,9 +483,18 @@ class AccountProfileView(LoginRequiredMixin, FormView, ListView):
allow_empty = True
paginate_by = 30

def post(self, *args, **kwargs):
def post(self, request, *args, **kwargs):
self.object_list = self.get_queryset()
return super().post(*args, **kwargs)
if "submit_name" in request.POST:
form = UserNameForm(request.POST)
if form.is_valid():
user = ConcordiaUser.objects.get(id=request.user.id)
user.first_name = form.cleaned_data["first_name"]
user.last_name = form.cleaned_data["last_name"]
user.save()
return redirect("user-profile")
else:
return super().post(request, *args, **kwargs)

def get_queryset(self):
return _get_pages(self.request)
Expand Down Expand Up @@ -539,6 +549,7 @@ def get_context_data(self, *args, **kwargs):
if ctx["totalReviews"] is not None:
ctx["totalCount"] = ctx["totalReviews"] + ctx["totalTranscriptions"]
ctx["unconfirmed_email"] = concordia_user.get_email_for_reconfirmation()
ctx["name_form"] = UserNameForm()
return ctx

def get_initial(self):
Expand Down