Ticket #26021: indent.diff

File indent.diff, 5.3 KB (added by Tim Graham, 9 years ago)
  • docs/ref/models/querysets.txt

    diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
    index af307fa..ec9a9e6 100644
    a b For example, suppose you have these models::  
    891891        toppings = models.ManyToManyField(Topping)
    892892
    893893        def __str__(self):              # __unicode__ on Python 2
    894             return "%s (%s)" % (self.name, ", ".join(topping.name
    895                                                      for topping in self.toppings.all()))
     894            return "%s (%s)" % (
     895                self.name,
     896                ", ".join(topping.name or topping in self.toppings.all()),
     897            )
    896898
    897899and run::
    898900
    This is meant as a shortcut to boilerplatish code. For example::  
    16361638This pattern gets quite unwieldy as the number of fields in a model goes up.
    16371639The above example can be rewritten using ``get_or_create()`` like so::
    16381640
    1639     obj, created = Person.objects.get_or_create(first_name='John', last_name='Lennon',
    1640                       defaults={'birthday': date(1940, 10, 9)})
     1641    obj, created = Person.objects.get_or_create(
     1642        first_name='John',
     1643        last_name='Lennon',
     1644        defaults={'birthday': date(1940, 10, 9)},
     1645    )
    16411646
    16421647Any keyword arguments passed to ``get_or_create()`` — *except* an optional one
    16431648called ``defaults`` — will be used in a :meth:`get()` call. If an object is
  • docs/ref/utils.txt

    diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
    index 43d082e..71404d7 100644
    a b Sample usage::  
    318318    >>> feed.add_item(
    319319    ...     title="Hello",
    320320    ...     link="http://www.holovaty.com/test/",
    321     ...     description="Testing."
     321    ...     description="Testing.",
    322322    ... )
    323323    >>> with open('test.rss', 'w') as fp:
    324324    ...     feed.write(fp, 'utf-8')
    escaping HTML.  
    630630
    631631    So, instead of writing::
    632632
    633         mark_safe("%s <b>%s</b> %s" % (some_html,
    634                                         escape(some_text),
    635                                         escape(some_other_text),
    636                                         ))
     633        mark_safe("%s <b>%s</b> %s" % (
     634            some_html,
     635            escape(some_text),
     636            escape(some_other_text),
     637        ))
    637638
    638639    You should instead use::
    639640
    640641        format_html("{} <b>{}</b> {}",
    641                     mark_safe(some_html), some_text, some_other_text)
     642            mark_safe(some_html),
     643            some_text,
     644            some_other_text,
     645        )
    642646
    643647    This has the advantage that you don't need to apply :func:`escape` to each
    644648    argument and risk a bug and an XSS vulnerability if you forget one.
    escaping HTML.  
    661665    ``args_generator`` should be an iterator that returns the sequence of
    662666    ``args`` that will be passed to :func:`format_html`. For example::
    663667
    664         format_html_join('\n', "<li>{} {}</li>", ((u.first_name, u.last_name)
    665                                                     for u in users))
     668        format_html_join(
     669            '\n', "<li>{} {}</li>",
     670            ((u.first_name, u.last_name) for u in users)
     671        )
    666672
    667673.. function:: strip_tags(value)
    668674
  • docs/topics/db/queries.txt

    diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt
    index ba026c8..12e1750 100644
    a b will return ``Blog`` objects that have an empty ``name`` on the ``author`` and  
    522522also those which have an empty ``author`` on the ``entry``. If you don't want
    523523those latter objects, you could write::
    524524
    525     Blog.objects.filter(entry__authors__isnull=False,
    526             entry__authors__name__isnull=True)
     525    Blog.objects.filter(entry__authors__isnull=False, entry__authors__name__isnull=True)
    527526
    528527Spanning multi-valued relationships
    529528~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    select all blogs that contain entries with both *"Lennon"* in the headline  
    559558and that were published in 2008 (the same entry satisfying both conditions),
    560559we would write::
    561560
    562     Blog.objects.filter(entry__headline__contains='Lennon',
    563             entry__pub_date__year=2008)
     561    Blog.objects.filter(entry__headline__contains='Lennon', entry__pub_date__year=2008)
    564562
    565563To select all blogs that contain an entry with *"Lennon"* in the headline
    566564**as well as** an entry that was published in 2008, we would write::
    567565
    568     Blog.objects.filter(entry__headline__contains='Lennon').filter(
    569             entry__pub_date__year=2008)
     566    Blog.objects.filter(entry__headline__contains='Lennon').filter(entry__pub_date__year=2008)
    570567
    571568Suppose there is only one blog that had both entries containing *"Lennon"* and
    572569entries from 2008, but that none of the entries from 2008 contained *"Lennon"*.
  • docs/topics/testing/tools.txt

    diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
    index f9e302a..cc1a7e6 100644
    a b and contents::  
    16521652    class EmailTest(TestCase):
    16531653        def test_send_email(self):
    16541654            # Send message.
    1655             mail.send_mail('Subject here', 'Here is the message.',
     1655            mail.send_mail(
     1656                'Subject here', 'Here is the message.',
    16561657                'from@example.com', ['to@example.com'],
    1657                 fail_silently=False)
     1658                fail_silently=False,
     1659            )
    16581660
    16591661            # Test that one message has been sent.
    16601662            self.assertEqual(len(mail.outbox), 1)
Back to Top