Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
ac2201a6
Commit
ac2201a6
authored
Oct 24, 2014
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add field from server to set custom error messages for logistration fields
parent
56d55608
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
80 deletions
+78
-80
common/djangoapps/user_api/helpers.py
+13
-2
common/djangoapps/user_api/tests/test_helpers.py
+6
-0
common/djangoapps/user_api/tests/test_views.py
+36
-62
common/djangoapps/user_api/views.py
+23
-16
No files found.
common/djangoapps/user_api/helpers.py
View file @
ac2201a6
...
@@ -125,7 +125,7 @@ class FormDescription(object):
...
@@ -125,7 +125,7 @@ class FormDescription(object):
def
add_field
(
def
add_field
(
self
,
name
,
label
=
u""
,
field_type
=
u"text"
,
default
=
u""
,
self
,
name
,
label
=
u""
,
field_type
=
u"text"
,
default
=
u""
,
placeholder
=
u""
,
instructions
=
u""
,
required
=
True
,
restrictions
=
None
,
placeholder
=
u""
,
instructions
=
u""
,
required
=
True
,
restrictions
=
None
,
options
=
None
options
=
None
,
error_messages
=
None
):
):
"""Add a field to the form description.
"""Add a field to the form description.
...
@@ -158,6 +158,11 @@ class FormDescription(object):
...
@@ -158,6 +158,11 @@ class FormDescription(object):
and `display_name` is the name to display to the user.
and `display_name` is the name to display to the user.
If the field type is "select", you *must* provide this kwarg.
If the field type is "select", you *must* provide this kwarg.
error_messages (dict): Custom validation error messages.
Currently, the only supported key is "required" indicating
that the messages should be displayed if the user does
not provide a value for a required field.
Raises:
Raises:
InvalidFieldError
InvalidFieldError
...
@@ -177,7 +182,8 @@ class FormDescription(object):
...
@@ -177,7 +182,8 @@ class FormDescription(object):
"placeholder"
:
placeholder
,
"placeholder"
:
placeholder
,
"instructions"
:
instructions
,
"instructions"
:
instructions
,
"required"
:
required
,
"required"
:
required
,
"restrictions"
:
{}
"restrictions"
:
{},
"errorMessages"
:
{},
}
}
if
field_type
==
"select"
:
if
field_type
==
"select"
:
...
@@ -201,6 +207,9 @@ class FormDescription(object):
...
@@ -201,6 +207,9 @@ class FormDescription(object):
)
)
raise
InvalidFieldError
(
msg
)
raise
InvalidFieldError
(
msg
)
if
error_messages
is
not
None
:
field_dict
[
"errorMessages"
]
=
error_messages
# If there are overrides for this field, apply them now.
# If there are overrides for this field, apply them now.
# Any field property can be overwritten (for example, the default value or placeholder)
# Any field property can be overwritten (for example, the default value or placeholder)
field_dict
.
update
(
self
.
_field_overrides
.
get
(
name
,
{}))
field_dict
.
update
(
self
.
_field_overrides
.
get
(
name
,
{}))
...
@@ -228,6 +237,7 @@ class FormDescription(object):
...
@@ -228,6 +237,7 @@ class FormDescription(object):
{"value": "wine", "name": "Wine"}
{"value": "wine", "name": "Wine"}
]
]
"restrictions": {},
"restrictions": {},
"errorMessages": {},
},
},
{
{
"name": "comments",
"name": "comments",
...
@@ -240,6 +250,7 @@ class FormDescription(object):
...
@@ -240,6 +250,7 @@ class FormDescription(object):
"restrictions": {
"restrictions": {
"max_length": 200
"max_length": 200
}
}
"errorMessages": {},
},
},
...
...
]
]
...
...
common/djangoapps/user_api/tests/test_helpers.py
View file @
ac2201a6
...
@@ -87,6 +87,9 @@ class FormDescriptionTest(TestCase):
...
@@ -87,6 +87,9 @@ class FormDescriptionTest(TestCase):
restrictions
=
{
restrictions
=
{
"min_length"
:
2
,
"min_length"
:
2
,
"max_length"
:
10
"max_length"
:
10
},
error_messages
=
{
"required"
:
"You must provide a value!"
}
}
)
)
...
@@ -105,6 +108,9 @@ class FormDescriptionTest(TestCase):
...
@@ -105,6 +108,9 @@ class FormDescriptionTest(TestCase):
"restrictions"
:
{
"restrictions"
:
{
"min_length"
:
2
,
"min_length"
:
2
,
"max_length"
:
10
,
"max_length"
:
10
,
},
"errorMessages"
:
{
"required"
:
"You must provide a value!"
}
}
}
}
]
]
...
...
common/djangoapps/user_api/tests/test_views.py
View file @
ac2201a6
This diff is collapsed.
Click to expand it.
common/djangoapps/user_api/views.py
View file @
ac2201a6
...
@@ -377,37 +377,41 @@ class RegistrationView(APIView):
...
@@ -377,37 +377,41 @@ class RegistrationView(APIView):
# Translators: This is a legal document users must agree to in order to register a new account.
# Translators: This is a legal document users must agree to in order to register a new account.
terms_text
=
_
(
u"Terms of Service and Honor Code"
)
terms_text
=
_
(
u"Terms of Service and Honor Code"
)
# Translators: "Terms of service" is a legal document users must agree to in order to register a new account.
terms_link
=
u"<a href=
\"
{url}
\"
>{terms_text}</a>"
.
format
(
label
=
_
(
url
=
marketing_link
(
"HONOR"
),
u"I agree to the {terms_of_service}"
terms_text
=
terms_text
)
.
format
(
terms_of_service
=
u"<a href=
\"
{url}
\"
>{terms_text}</a>"
.
format
(
url
=
marketing_link
(
"HONOR"
),
terms_text
=
terms_text
)
)
)
# Translators: "Terms of service" is a legal document users must agree to in order to register a new account.
label
=
_
(
u"I agree to the {terms_of_service}"
)
.
format
(
terms_of_service
=
terms_link
)
# Translators: "Terms of service" is a legal document users must agree to in order to register a new account.
error_msg
=
_
(
u"You must agree to the {terms_of_service}"
)
.
format
(
terms_of_service
=
terms_link
)
form_desc
.
add_field
(
form_desc
.
add_field
(
"honor_code"
,
"honor_code"
,
label
=
label
,
label
=
label
,
field_type
=
"checkbox"
,
field_type
=
"checkbox"
,
default
=
False
,
default
=
False
,
required
=
required
,
required
=
required
,
error_messages
=
{
"required"
:
error_msg
}
)
)
def
_add_terms_of_service_field
(
self
,
form_desc
,
required
=
True
):
def
_add_terms_of_service_field
(
self
,
form_desc
,
required
=
True
):
# Translators: This is a legal document users must agree to in order to register a new account.
# Translators: This is a legal document users must agree to in order to register a new account.
terms_text
=
_
(
u"Terms of Service"
)
terms_text
=
_
(
u"Terms of Service"
)
terms_link
=
u"<a href=
\"
{url}
\"
>{terms_text}</a>"
.
format
(
url
=
marketing_link
(
"TOS"
),
terms_text
=
terms_text
)
# Translators: "Terms of service" is a legal document users must agree to in order to register a new account.
# Translators: "Terms of service" is a legal document users must agree to in order to register a new account.
label
=
_
(
label
=
_
(
u"I agree to the {terms_of_service}"
)
.
format
(
terms_of_service
=
terms_link
)
u"I agree to the {terms_of_service}"
)
.
format
(
# Translators: "Terms of service" is a legal document users must agree to in order to register a new account.
terms_of_service
=
u"<a href=
\"
{url}
\"
>{terms_text}</a>"
.
format
(
error_msg
=
_
(
"You must agree to the {terms_of_service}"
)
.
format
(
terms_of_service
=
terms_link
)
url
=
marketing_link
(
"TOS"
),
terms_text
=
terms_text
)
)
form_desc
.
add_field
(
form_desc
.
add_field
(
"terms_of_service"
,
"terms_of_service"
,
...
@@ -415,6 +419,9 @@ class RegistrationView(APIView):
...
@@ -415,6 +419,9 @@ class RegistrationView(APIView):
field_type
=
"checkbox"
,
field_type
=
"checkbox"
,
default
=
False
,
default
=
False
,
required
=
required
,
required
=
required
,
error_messages
=
{
"required"
:
error_msg
}
)
)
def
_options_with_default
(
self
,
options
):
def
_options_with_default
(
self
,
options
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment