1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

[1.10.x] Fixed #26021 -- Applied hanging indentation to docs.

Backport of 4a4d7f980e from master
This commit is contained in:
Ed Henderson
2016-06-02 12:56:13 -07:00
committed by Tim Graham
parent 971adb9e9c
commit 521772ff07
21 changed files with 185 additions and 107 deletions

View File

@@ -971,9 +971,10 @@ authentication app::
Creates and saves a superuser with the given email, date of
birth and password.
"""
user = self.create_user(email,
user = self.create_user(
email,
password=password,
date_of_birth=date_of_birth
date_of_birth=date_of_birth,
)
user.is_admin = True
user.save(using=self._db)

View File

@@ -249,9 +249,11 @@ in ``myapp``::
from django.contrib.contenttypes.models import ContentType
content_type = ContentType.objects.get_for_model(BlogPost)
permission = Permission.objects.create(codename='can_publish',
name='Can Publish Posts',
content_type=content_type)
permission = Permission.objects.create(
codename='can_publish',
name='Can Publish Posts',
content_type=content_type,
)
The permission can then be assigned to a
:class:`~django.contrib.auth.models.User` via its ``user_permissions``

View File

@@ -849,14 +849,16 @@ precede the definition of any keyword arguments. For example::
Poll.objects.get(
Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6)),
question__startswith='Who')
question__startswith='Who',
)
... would be a valid query, equivalent to the previous example; but::
# INVALID QUERY
Poll.objects.get(
question__startswith='Who',
Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6)))
Q(pub_date=date(2005, 5, 2)) | Q(pub_date=date(2005, 5, 6))
)
... would not be valid.

View File

@@ -20,8 +20,13 @@ In two lines::
from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', 'from@example.com',
['to@example.com'], fail_silently=False)
send_mail(
'Subject here',
'Here is the message.',
'from@example.com',
['to@example.com'],
fail_silently=False,
)
Mail is sent using the SMTP host and port specified in the
:setting:`EMAIL_HOST` and :setting:`EMAIL_PORT` settings. The
@@ -149,8 +154,12 @@ Examples
This sends a single email to john@example.com and jane@example.com, with them
both appearing in the "To:"::
send_mail('Subject', 'Message.', 'from@example.com',
['john@example.com', 'jane@example.com'])
send_mail(
'Subject',
'Message.',
'from@example.com',
['john@example.com', 'jane@example.com'],
)
This sends a message to john@example.com and jane@example.com, with them both
receiving a separate email::
@@ -281,9 +290,15 @@ For example::
from django.core.mail import EmailMessage
email = EmailMessage('Hello', 'Body goes here', 'from@example.com',
['to1@example.com', 'to2@example.com'], ['bcc@example.com'],
reply_to=['another@example.com'], headers={'Message-ID': 'foo'})
email = EmailMessage(
'Hello',
'Body goes here',
'from@example.com',
['to1@example.com', 'to2@example.com'],
['bcc@example.com'],
reply_to=['another@example.com'],
headers={'Message-ID': 'foo'},
)
The class has the following methods:
@@ -405,10 +420,14 @@ It can also be used as a context manager, which will automatically call
from django.core import mail
with mail.get_connection() as connection:
mail.EmailMessage(subject1, body1, from1, [to1],
connection=connection).send()
mail.EmailMessage(subject2, body2, from2, [to2],
connection=connection).send()
mail.EmailMessage(
subject1, body1, from1, [to1],
connection=connection,
).send()
mail.EmailMessage(
subject2, body2, from2, [to2],
connection=connection,
).send()
Obtaining an instance of an email backend
-----------------------------------------
@@ -592,15 +611,28 @@ manually open the connection, you can control when it is closed. For example::
connection.open()
# Construct an email message that uses the connection
email1 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
['to1@example.com'], connection=connection)
email1 = mail.EmailMessage(
'Hello',
'Body goes here',
'from@example.com',
['to1@example.com'],
connection=connection,
)
email1.send() # Send the email
# Construct two more messages
email2 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
['to2@example.com'])
email3 = mail.EmailMessage('Hello', 'Body goes here', 'from@example.com',
['to3@example.com'])
email2 = mail.EmailMessage(
'Hello',
'Body goes here',
'from@example.com',
['to2@example.com'],
)
email3 = mail.EmailMessage(
'Hello',
'Body goes here',
'from@example.com',
['to3@example.com'],
)
# Send the two emails in a single call -
connection.send_messages([email2, email3])

View File

@@ -195,8 +195,10 @@ we'll discuss in a moment.)::
class AuthorForm(forms.Form):
name = forms.CharField(max_length=100)
title = forms.CharField(max_length=3,
widget=forms.Select(choices=TITLE_CHOICES))
title = forms.CharField(
max_length=3,
widget=forms.Select(choices=TITLE_CHOICES),
)
birth_date = forms.DateField(required=False)
class BookForm(forms.Form):
@@ -589,8 +591,12 @@ the field declaratively and setting its ``validators`` parameter::
For example, if the ``Article`` model looks like this::
class Article(models.Model):
headline = models.CharField(max_length=200, null=True, blank=True,
help_text="Use puns liberally")
headline = models.CharField(
max_length=200,
null=True,
blank=True,
help_text='Use puns liberally',
)
content = models.TextField()
and you want to do some custom validation for ``headline``, while keeping
@@ -598,8 +604,11 @@ the field declaratively and setting its ``validators`` parameter::
``ArticleForm`` like this::
class ArticleForm(ModelForm):
headline = MyFormField(max_length=200, required=False,
help_text="Use puns liberally")
headline = MyFormField(
max_length=200,
required=False,
help_text='Use puns liberally',
)
class Meta:
model = Article
@@ -1022,8 +1031,10 @@ formset::
def manage_authors(request):
AuthorFormSet = modelformset_factory(Author, fields=('name', 'title'))
if request.method == "POST":
formset = AuthorFormSet(request.POST, request.FILES,
queryset=Author.objects.filter(name__startswith='O'))
formset = AuthorFormSet(
request.POST, request.FILES,
queryset=Author.objects.filter(name__startswith='O'),
)
if formset.is_valid():
formset.save()
# Do something.

View File

@@ -66,8 +66,9 @@ MIME type :mimetype:`application/xhtml+xml`::
def my_view(request):
# View code here...
return render(request, 'myapp/index.html', {"foo": "bar"},
content_type="application/xhtml+xml")
return render(request, 'myapp/index.html', {
'foo': 'bar',
}, content_type='application/xhtml+xml')
This example is equivalent to::
@@ -78,8 +79,7 @@ This example is equivalent to::
# View code here...
t = loader.get_template('myapp/index.html')
c = {'foo': 'bar'}
return HttpResponse(t.render(c, request),
content_type="application/xhtml+xml")
return HttpResponse(t.render(c, request), content_type='application/xhtml+xml')
``render_to_response()``
========================

View File

@@ -434,8 +434,9 @@ traceback by adding the following to your settings file::
import warnings
warnings.filterwarnings(
'error', r"DateTimeField .* received a naive datetime",
RuntimeWarning, r'django\.db\.models\.fields')
'error', r"DateTimeField .* received a naive datetime",
RuntimeWarning, r'django\.db\.models\.fields',
)
Fixtures
--------

View File

@@ -468,8 +468,10 @@ If the string contains exactly one unnamed placeholder, you can interpolate
directly with the ``number`` argument::
class MyForm(forms.Form):
error_message = ungettext_lazy("You provided %d argument",
"You provided %d arguments")
error_message = ungettext_lazy(
"You provided %d argument",
"You provided %d arguments",
)
def clean(self):
# ...
@@ -1843,8 +1845,11 @@ If you need more flexibility, you could also add a new argument to your custom
def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
parser.add_argument('--extra-keyword', dest='xgettext_keywords',
action='append')
parser.add_argument(
'--extra-keyword',
dest='xgettext_keywords',
action='append',
)
def handle(self, *args, **options):
xgettext_keywords = options.pop('xgettext_keywords')