From 7d43f41e4aa50c4258ec1d7b63dd62a01440fa9d Mon Sep 17 00:00:00 2001 From: Andy Freeland Date: Thu, 4 Jul 2013 01:51:24 -0400 Subject: Remove 'Hold down "Control" ...' message from help_text When getting the help_text from a field where `many=True`, Django appends 'Hold down "Control", or "Command" on a Mac, to select more than one.' to the help_text. This makes some sense in Django's ModelForms, but no sense in the API. --- rest_framework/fields.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'rest_framework/fields.py') diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 35848b4c..1a0ad3b9 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -100,6 +100,19 @@ def humanize_strptime(format_string): return format_string +def strip_multiple_choice_msg(help_text): + """ + Remove the 'Hold down "control" ...' message that is enforced in select + multiple fields. + + See https://code.djangoproject.com/ticket/9321 + """ + multiple_choice_msg = _(' Hold down "Control", or "Command" on a Mac, to select more than one.') + multiple_choice_msg = unicode(multiple_choice_msg) + + return help_text.replace(multiple_choice_msg, '') + + class Field(object): read_only = True creation_counter = 0 @@ -122,7 +135,7 @@ class Field(object): self.label = smart_text(label) if help_text is not None: - self.help_text = smart_text(help_text) + self.help_text = strip_multiple_choice_msg(smart_text(help_text)) def initialize(self, parent, field_name): """ -- cgit v1.2.3 From 8f79caf9d1bd4a3de8371c61f24dcf513454f06b Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 5 Jul 2013 09:07:18 +0100 Subject: Use 'force_text', not 'unicode', for compat across python version --- rest_framework/fields.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'rest_framework/fields.py') diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 1a0ad3b9..6e5ee470 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -102,13 +102,13 @@ def humanize_strptime(format_string): def strip_multiple_choice_msg(help_text): """ - Remove the 'Hold down "control" ...' message that is enforced in select - multiple fields. + Remove the 'Hold down "control" ...' message that is Django enforces in + select multiple fields on ModelForms. (Required for 1.5 and earlier) See https://code.djangoproject.com/ticket/9321 """ multiple_choice_msg = _(' Hold down "Control", or "Command" on a Mac, to select more than one.') - multiple_choice_msg = unicode(multiple_choice_msg) + multiple_choice_msg = force_text(multiple_choice_msg) return help_text.replace(multiple_choice_msg, '') -- cgit v1.2.3 From 2e18fbe373b3216b451ac163ec822e04b1e76120 Mon Sep 17 00:00:00 2001 From: Pavel Zinovkin Date: Sun, 21 Jul 2013 17:03:58 +0400 Subject: Updated EmailField error message. This one already available in django translations. https://github.com/django/django/blob/master/django/conf/locale/ru/LC_MESSAGES/django.po#L343--- rest_framework/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rest_framework/fields.py') diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 6e5ee470..f9931887 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -512,7 +512,7 @@ class EmailField(CharField): form_field_class = forms.EmailField default_error_messages = { - 'invalid': _('Enter a valid e-mail address.'), + 'invalid': _('Enter a valid email address.'), } default_validators = [validators.validate_email] -- cgit v1.2.3