From 3a97f992fbfbcf8b0480875b257e5d541a4b8315 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 22 Mar 2014 21:30:49 +0100 Subject: Fixed #22313 -- Removed 'u' prefixes from documentation --- docs/topics/db/models.txt | 8 +- docs/topics/files.txt | 8 +- docs/topics/forms/formsets.txt | 166 +++++++++++++++++++-------------------- docs/topics/forms/modelforms.txt | 6 +- docs/topics/i18n/formatting.txt | 4 +- docs/topics/i18n/translation.txt | 4 +- docs/topics/signing.txt | 8 +- docs/topics/testing/tools.txt | 6 +- 8 files changed, 106 insertions(+), 104 deletions(-) (limited to 'docs/topics') diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt index d5a700f62e..17ac9f1571 100644 --- a/docs/topics/db/models.txt +++ b/docs/topics/db/models.txt @@ -190,9 +190,9 @@ ones: >>> p = Person(name="Fred Flintstone", shirt_size="L") >>> p.save() >>> p.shirt_size - u'L' + 'L' >>> p.get_shirt_size_display() - u'Large' + 'Large' :attr:`~Field.default` The default value for the field. This can be a value or a callable @@ -541,7 +541,7 @@ querying the ``Membership`` model:: >>> ringos_membership.date_joined datetime.date(1962, 8, 16) >>> ringos_membership.invite_reason - u'Needed a new drummer.' + 'Needed a new drummer.' Another way to access the same information is by querying the :ref:`many-to-many reverse relationship` from a @@ -551,7 +551,7 @@ Another way to access the same information is by querying the >>> ringos_membership.date_joined datetime.date(1962, 8, 16) >>> ringos_membership.invite_reason - u'Needed a new drummer.' + 'Needed a new drummer.' One-to-one relationships diff --git a/docs/topics/files.txt b/docs/topics/files.txt index 45f83d8746..154d5c8ebb 100644 --- a/docs/topics/files.txt +++ b/docs/topics/files.txt @@ -41,11 +41,11 @@ the details of the attached photo:: >>> car.photo >>> car.photo.name - u'cars/chevy.jpg' + 'cars/chevy.jpg' >>> car.photo.path - u'/media/cars/chevy.jpg' + '/media/cars/chevy.jpg' >>> car.photo.url - u'http://media.example.com/cars/chevy.jpg' + 'http://media.example.com/cars/chevy.jpg' This object -- ``car.photo`` in the example -- is a ``File`` object, which means it has all the methods and attributes described below. @@ -131,7 +131,7 @@ useful -- you can use the global default storage system:: >>> path = default_storage.save('/path/to/file', ContentFile('new content')) >>> path - u'/path/to/file' + '/path/to/file' >>> default_storage.size(path) 11 diff --git a/docs/topics/forms/formsets.txt b/docs/topics/forms/formsets.txt index a1e30b341b..0e32d6131f 100644 --- a/docs/topics/forms/formsets.txt +++ b/docs/topics/forms/formsets.txt @@ -64,7 +64,7 @@ example:: >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory(ArticleForm, extra=2) >>> formset = ArticleFormSet(initial=[ - ... {'title': u'Django is now open source', + ... {'title': 'Django is now open source', ... 'pub_date': datetime.date.today(),} ... ]) @@ -136,9 +136,9 @@ all forms in the formset:: >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory(ArticleForm) >>> data = { - ... 'form-TOTAL_FORMS': u'1', - ... 'form-INITIAL_FORMS': u'0', - ... 'form-MAX_NUM_FORMS': u'', + ... 'form-TOTAL_FORMS': '1', + ... 'form-INITIAL_FORMS': '0', + ... 'form-MAX_NUM_FORMS': '', ... } >>> formset = ArticleFormSet(data) >>> formset.is_valid() @@ -149,19 +149,19 @@ formset is smart enough to ignore extra forms that were not changed. If we provide an invalid article:: >>> data = { - ... 'form-TOTAL_FORMS': u'2', - ... 'form-INITIAL_FORMS': u'0', - ... 'form-MAX_NUM_FORMS': u'', - ... 'form-0-title': u'Test', - ... 'form-0-pub_date': u'1904-06-16', - ... 'form-1-title': u'Test', - ... 'form-1-pub_date': u'', # <-- this date is missing but required + ... 'form-TOTAL_FORMS': '2', + ... 'form-INITIAL_FORMS': '0', + ... 'form-MAX_NUM_FORMS': '', + ... 'form-0-title': 'Test', + ... 'form-0-pub_date': '1904-06-16', + ... 'form-1-title': 'Test', + ... 'form-1-pub_date': '', # <-- this date is missing but required ... } >>> formset = ArticleFormSet(data) >>> formset.is_valid() False >>> formset.errors - [{}, {'pub_date': [u'This field is required.']}] + [{}, {'pub_date': ['This field is required.']}] As we can see, ``formset.errors`` is a list whose entries correspond to the forms in the formset. Validation was performed for each of the two forms, and @@ -176,7 +176,7 @@ To check how many errors there are in the formset, we can use the >>> # Using the previous example >>> formset.errors - [{}, {'pub_date': [u'This field is required.']}] + [{}, {'pub_date': ['This field is required.']}] >>> len(formset.errors) 2 >>> formset.total_error_count() @@ -186,11 +186,11 @@ We can also check if form data differs from the initial data (i.e. the form was sent without any data):: >>> data = { - ... 'form-TOTAL_FORMS': u'1', - ... 'form-INITIAL_FORMS': u'0', - ... 'form-MAX_NUM_FORMS': u'', - ... 'form-0-title': u'', - ... 'form-0-pub_date': u'', + ... 'form-TOTAL_FORMS': '1', + ... 'form-INITIAL_FORMS': '0', + ... 'form-MAX_NUM_FORMS': '', + ... 'form-0-title': '', + ... 'form-0-pub_date': '', ... } >>> formset = ArticleFormSet(data) >>> formset.has_changed() @@ -209,13 +209,13 @@ collection of forms contained in the formset. If you don't provide this management data, an exception will be raised:: >>> data = { - ... 'form-0-title': u'Test', - ... 'form-0-pub_date': u'', + ... 'form-0-title': 'Test', + ... 'form-0-pub_date': '', ... } >>> formset = ArticleFormSet(data) Traceback (most recent call last): ... - django.forms.utils.ValidationError: [u'ManagementForm data is missing or has been tampered with'] + django.forms.utils.ValidationError: ['ManagementForm data is missing or has been tampered with'] It is used to keep track of how many form instances are being displayed. If you are adding new forms via JavaScript, you should increment the count fields @@ -273,13 +273,13 @@ is where you define your own validation that works at the formset level:: >>> ArticleFormSet = formset_factory(ArticleForm, formset=BaseArticleFormSet) >>> data = { - ... 'form-TOTAL_FORMS': u'2', - ... 'form-INITIAL_FORMS': u'0', - ... 'form-MAX_NUM_FORMS': u'', - ... 'form-0-title': u'Test', - ... 'form-0-pub_date': u'1904-06-16', - ... 'form-1-title': u'Test', - ... 'form-1-pub_date': u'1912-06-23', + ... 'form-TOTAL_FORMS': '2', + ... 'form-INITIAL_FORMS': '0', + ... 'form-MAX_NUM_FORMS': '', + ... 'form-0-title': 'Test', + ... 'form-0-pub_date': '1904-06-16', + ... 'form-1-title': 'Test', + ... 'form-1-pub_date': '1912-06-23', ... } >>> formset = ArticleFormSet(data) >>> formset.is_valid() @@ -287,7 +287,7 @@ is where you define your own validation that works at the formset level:: >>> formset.errors [{}, {}] >>> formset.non_form_errors() - [u'Articles in a set must have distinct titles.'] + ['Articles in a set must have distinct titles.'] The formset ``clean`` method is called after all the ``Form.clean`` methods have been called. The errors will be found using the ``non_form_errors()`` @@ -314,14 +314,14 @@ deletion, is less than or equal to ``max_num``. >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory(ArticleForm, max_num=1, validate_max=True) >>> data = { - ... 'form-TOTAL_FORMS': u'2', - ... 'form-INITIAL_FORMS': u'0', - ... 'form-MIN_NUM_FORMS': u'', - ... 'form-MAX_NUM_FORMS': u'', - ... 'form-0-title': u'Test', - ... 'form-0-pub_date': u'1904-06-16', - ... 'form-1-title': u'Test 2', - ... 'form-1-pub_date': u'1912-06-23', + ... 'form-TOTAL_FORMS': '2', + ... 'form-INITIAL_FORMS': '0', + ... 'form-MIN_NUM_FORMS': '', + ... 'form-MAX_NUM_FORMS': '', + ... 'form-0-title': 'Test', + ... 'form-0-pub_date': '1904-06-16', + ... 'form-1-title': 'Test 2', + ... 'form-1-pub_date': '1912-06-23', ... } >>> formset = ArticleFormSet(data) >>> formset.is_valid() @@ -329,7 +329,7 @@ deletion, is less than or equal to ``max_num``. >>> formset.errors [{}, {}] >>> formset.non_form_errors() - [u'Please submit 1 or fewer forms.'] + ['Please submit 1 or fewer forms.'] ``validate_max=True`` validates against ``max_num`` strictly even if ``max_num`` was exceeded because the amount of initial data supplied was @@ -363,14 +363,14 @@ deletion, is greater than or equal to ``min_num``. >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory(ArticleForm, min_num=3, validate_min=True) >>> data = { - ... 'form-TOTAL_FORMS': u'2', - ... 'form-INITIAL_FORMS': u'0', - ... 'form-MIN_NUM_FORMS': u'', - ... 'form-MAX_NUM_FORMS': u'', - ... 'form-0-title': u'Test', - ... 'form-0-pub_date': u'1904-06-16', - ... 'form-1-title': u'Test 2', - ... 'form-1-pub_date': u'1912-06-23', + ... 'form-TOTAL_FORMS': '2', + ... 'form-INITIAL_FORMS': '0', + ... 'form-MIN_NUM_FORMS': '', + ... 'form-MAX_NUM_FORMS': '', + ... 'form-0-title': 'Test', + ... 'form-0-pub_date': '1904-06-16', + ... 'form-1-title': 'Test 2', + ... 'form-1-pub_date': '1912-06-23', ... } >>> formset = ArticleFormSet(data) >>> formset.is_valid() @@ -378,7 +378,7 @@ deletion, is greater than or equal to ``min_num``. >>> formset.errors [{}, {}] >>> formset.non_form_errors() - [u'Please submit 3 or more forms.'] + ['Please submit 3 or more forms.'] .. versionchanged:: 1.7 @@ -405,8 +405,8 @@ Lets you create a formset with the ability to order:: >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory(ArticleForm, can_order=True) >>> formset = ArticleFormSet(initial=[ - ... {'title': u'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, - ... {'title': u'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, + ... {'title': 'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, + ... {'title': 'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, ... ]) >>> for form in formset: ... print(form.as_table()) @@ -426,31 +426,31 @@ data it automatically assigned them a numeric value. Let's look at what will happen when the user changes these values:: >>> data = { - ... 'form-TOTAL_FORMS': u'3', - ... 'form-INITIAL_FORMS': u'2', - ... 'form-MAX_NUM_FORMS': u'', - ... 'form-0-title': u'Article #1', - ... 'form-0-pub_date': u'2008-05-10', - ... 'form-0-ORDER': u'2', - ... 'form-1-title': u'Article #2', - ... 'form-1-pub_date': u'2008-05-11', - ... 'form-1-ORDER': u'1', - ... 'form-2-title': u'Article #3', - ... 'form-2-pub_date': u'2008-05-01', - ... 'form-2-ORDER': u'0', + ... 'form-TOTAL_FORMS': '3', + ... 'form-INITIAL_FORMS': '2', + ... 'form-MAX_NUM_FORMS': '', + ... 'form-0-title': 'Article #1', + ... 'form-0-pub_date': '2008-05-10', + ... 'form-0-ORDER': '2', + ... 'form-1-title': 'Article #2', + ... 'form-1-pub_date': '2008-05-11', + ... 'form-1-ORDER': '1', + ... 'form-2-title': 'Article #3', + ... 'form-2-pub_date': '2008-05-01', + ... 'form-2-ORDER': '0', ... } >>> formset = ArticleFormSet(data, initial=[ - ... {'title': u'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, - ... {'title': u'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, + ... {'title': 'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, + ... {'title': 'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, ... ]) >>> formset.is_valid() True >>> for form in formset.ordered_forms: ... print(form.cleaned_data) - {'pub_date': datetime.date(2008, 5, 1), 'ORDER': 0, 'title': u'Article #3'} - {'pub_date': datetime.date(2008, 5, 11), 'ORDER': 1, 'title': u'Article #2'} - {'pub_date': datetime.date(2008, 5, 10), 'ORDER': 2, 'title': u'Article #1'} + {'pub_date': datetime.date(2008, 5, 1), 'ORDER': 0, 'title': 'Article #3'} + {'pub_date': datetime.date(2008, 5, 11), 'ORDER': 1, 'title': 'Article #2'} + {'pub_date': datetime.date(2008, 5, 10), 'ORDER': 2, 'title': 'Article #1'} ``can_delete`` ~~~~~~~~~~~~~~ @@ -465,8 +465,8 @@ Lets you create a formset with the ability to select forms for deletion:: >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory(ArticleForm, can_delete=True) >>> formset = ArticleFormSet(initial=[ - ... {'title': u'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, - ... {'title': u'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, + ... {'title': 'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, + ... {'title': 'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, ... ]) >>> for form in formset: .... print(form.as_table()) @@ -486,26 +486,26 @@ and is a ``forms.BooleanField``. When data comes through marking any of the delete fields you can access them with ``deleted_forms``:: >>> data = { - ... 'form-TOTAL_FORMS': u'3', - ... 'form-INITIAL_FORMS': u'2', - ... 'form-MAX_NUM_FORMS': u'', - ... 'form-0-title': u'Article #1', - ... 'form-0-pub_date': u'2008-05-10', - ... 'form-0-DELETE': u'on', - ... 'form-1-title': u'Article #2', - ... 'form-1-pub_date': u'2008-05-11', - ... 'form-1-DELETE': u'', - ... 'form-2-title': u'', - ... 'form-2-pub_date': u'', - ... 'form-2-DELETE': u'', + ... 'form-TOTAL_FORMS': '3', + ... 'form-INITIAL_FORMS': '2', + ... 'form-MAX_NUM_FORMS': '', + ... 'form-0-title': 'Article #1', + ... 'form-0-pub_date': '2008-05-10', + ... 'form-0-DELETE': 'on', + ... 'form-1-title': 'Article #2', + ... 'form-1-pub_date': '2008-05-11', + ... 'form-1-DELETE': '', + ... 'form-2-title': '', + ... 'form-2-pub_date': '', + ... 'form-2-DELETE': '', ... } >>> formset = ArticleFormSet(data, initial=[ - ... {'title': u'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, - ... {'title': u'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, + ... {'title': 'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, + ... {'title': 'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, ... ]) >>> [form.cleaned_data for form in formset.deleted_forms] - [{'DELETE': True, 'pub_date': datetime.date(2008, 5, 10), 'title': u'Article #1'}] + [{'DELETE': True, 'pub_date': datetime.date(2008, 5, 10), 'title': 'Article #1'}] If you are using a :class:`ModelFormSet`, model instances for deleted forms will be deleted when you call diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index a55e7a5ced..d01fc64cb2 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -913,7 +913,7 @@ extra forms displayed. >>> AuthorFormSet = modelformset_factory(Author, max_num=1) >>> formset = AuthorFormSet(queryset=Author.objects.order_by('name')) >>> [x.name for x in formset.get_queryset()] - [u'Charles Baudelaire', u'Paul Verlaine', u'Walt Whitman'] + ['Charles Baudelaire', 'Paul Verlaine', 'Walt Whitman'] If the value of ``max_num`` is greater than the number of existing related objects, up to ``extra`` additional blank forms will be added to the formset, @@ -1111,7 +1111,7 @@ a particular author, you could do this:: >>> from django.forms.models import inlineformset_factory >>> BookFormSet = inlineformset_factory(Author, Book) - >>> author = Author.objects.get(name=u'Mike Royko') + >>> author = Author.objects.get(name='Mike Royko') >>> formset = BookFormSet(instance=author) .. note:: @@ -1150,7 +1150,7 @@ Then when you create your inline formset, pass in the optional argument >>> from django.forms.models import inlineformset_factory >>> BookFormSet = inlineformset_factory(Author, Book, formset=CustomInlineFormSet) - >>> author = Author.objects.get(name=u'Mike Royko') + >>> author = Author.objects.get(name='Mike Royko') >>> formset = BookFormSet(instance=author) More than one foreign key to the same model diff --git a/docs/topics/i18n/formatting.txt b/docs/topics/i18n/formatting.txt index e306d4ab44..04b36e2767 100644 --- a/docs/topics/i18n/formatting.txt +++ b/docs/topics/i18n/formatting.txt @@ -174,7 +174,9 @@ To customize the English formats, a structure like this would be needed:: where :file:`formats.py` contains custom format definitions. For example:: - THOUSAND_SEPARATOR = u'\xa0' + from __future__ import unicode_literals + + THOUSAND_SEPARATOR = '\xa0' to use a non-breaking space (Unicode ``00A0``) as a thousand separator, instead of the default for English, a comma. diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt index a54fe118be..6dae9f691f 100644 --- a/docs/topics/i18n/translation.txt +++ b/docs/topics/i18n/translation.txt @@ -402,11 +402,11 @@ itself to a bytestring. You can't use a unicode string inside a bytestring, either, so this is consistent with normal Python behavior. For example:: # This is fine: putting a unicode proxy into a unicode string. - u"Hello %s" % ugettext_lazy("people") + "Hello %s" % ugettext_lazy("people") # This will not work, since you cannot insert a unicode object # into a bytestring (nor can you insert our unicode proxy there) - "Hello %s" % ugettext_lazy("people") + b"Hello %s" % ugettext_lazy("people") If you ever see output that looks like ``"hello "``, you have tried to insert the result of diff --git a/docs/topics/signing.txt b/docs/topics/signing.txt index af787b5adb..3092f297f0 100644 --- a/docs/topics/signing.txt +++ b/docs/topics/signing.txt @@ -51,7 +51,7 @@ You can retrieve the original value using the ``unsign`` method:: >>> original = signer.unsign(value) >>> original - u'My string' + 'My string' If the signature or value have been altered in any way, a ``django.core.signing.BadSignature`` exception will be raised:: @@ -94,7 +94,7 @@ your :setting:`SECRET_KEY`:: >>> signer.sign('My string') 'My string:Ee7vGi-ING6n02gkcJ-QLHg6vFw' >>> signer.unsign('My string:Ee7vGi-ING6n02gkcJ-QLHg6vFw') - u'My string' + 'My string' Using salt in this way puts the different signatures into different namespaces. A signature that comes from one namespace (a particular salt @@ -120,12 +120,12 @@ created within a specified period of time:: >>> value 'hello:1NMg5H:oPVuCqlJWmChm1rA2lyTUtelC-c' >>> signer.unsign(value) - u'hello' + 'hello' >>> signer.unsign(value, max_age=10) ... SignatureExpired: Signature age 15.5289158821 > 10 seconds >>> signer.unsign(value, max_age=20) - u'hello' + 'hello' .. class:: TimestampSigner(key=None, sep=':', salt=None) diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index d6e60458f3..a67675b268 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -187,7 +187,7 @@ Use the ``django.test.Client`` class to make requests. >>> response = c.get('/redirect_me/', follow=True) >>> response.redirect_chain - [(u'http://testserver/next/', 302), (u'http://testserver/final/', 302)] + [('http://testserver/next/', 302), ('http://testserver/final/', 302)] If you set ``secure`` to ``True`` the client will emulate an HTTPS request. @@ -1245,7 +1245,7 @@ your test suite. failure. Similar to unittest's :meth:`~unittest.TestCase.assertRaisesRegexp` with the difference that ``expected_message`` isn't a regular expression. -.. method:: SimpleTestCase.assertFieldOutput(fieldclass, valid, invalid, field_args=None, field_kwargs=None, empty_value=u'') +.. method:: SimpleTestCase.assertFieldOutput(fieldclass, valid, invalid, field_args=None, field_kwargs=None, empty_value='') Asserts that a form field behaves correctly with various inputs. @@ -1262,7 +1262,7 @@ your test suite. ``a@a.com`` as a valid email address, but rejects ``aaa`` with a reasonable error message:: - self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': [u'Enter a valid email address.']}) + self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': ['Enter a valid email address.']}) .. method:: SimpleTestCase.assertFormError(response, form, field, errors, msg_prefix='') -- cgit v1.3