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

Add back-end support for custom translations of labels for user metadata fields #4527

Merged
merged 8 commits into from
Jul 27, 2023
2 changes: 1 addition & 1 deletion jsapp/scss/stylesheets/partials/_registration.scss
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
}

.sector,
.name {
.full_name {
width: 48%;
float: left;
margin-top: 0px;
Expand Down
25 changes: 17 additions & 8 deletions kobo/apps/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from allauth.socialaccount.forms import SignupForm as BaseSocialSignupForm
from django import forms
from django.conf import settings
from django.utils.translation import get_language
from django.utils.translation import gettext_lazy as t

from kobo.static_lists import COUNTRIES


# Only these fields can be controlled by constance.config.USER_METADATA_FIELDS
CONFIGURABLE_METADATA_FIELDS = (
'full_name',
'organization',
'gender',
'sector',
Expand All @@ -29,7 +31,7 @@ def __init__(self, *args, **kwargs):


class KoboSignupMixin(forms.Form):
name = forms.CharField(
full_name = forms.CharField(
label=t('Full name'),
required=False,
)
Expand Down Expand Up @@ -87,13 +89,20 @@ def __init__(self, *args, **kwargs):
for field_name in list(self.fields.keys()):
if field_name not in CONFIGURABLE_METADATA_FIELDS:
continue
if field_name not in desired_metadata_fields:
try:
desired_field = desired_metadata_fields[field_name]
if 'label' in desired_field.keys():
try:
self.fields[field_name].label = desired_field['label'][get_language()]
except KeyError:
self.fields[field_name].label = desired_field['label']['default']
JacquelineMorrissette marked this conversation as resolved.
Show resolved Hide resolved
else:
continue
except KeyError:
self.fields.pop(field_name)
continue
else:
self.fields[field_name].required = desired_metadata_fields[
field_name
].get('required', False)
field = self.fields[field_name]
field.required = desired_field.get('required', False)

def clean_email(self):
email = self.cleaned_data['email']
Expand All @@ -117,7 +126,7 @@ class SocialSignupForm(KoboSignupMixin, BaseSocialSignupForm):
field_order = [
'username',
'email',
'name',
'full_name',
'gender',
'sector',
'country',
Expand All @@ -133,7 +142,7 @@ def __init__(self, *args, **kwargs):

class SignupForm(KoboSignupMixin, BaseSignupForm):
field_order = [
'name',
'full_name',
'organization',
'username',
'email',
Expand Down