mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 01:26:53 +03:00
Clean up all whitespace throughout project (#5578)
* Remove trailing whitespace from lines * Remove trailing nad leading whitespace from files Allows for cleaner diffs in future changes. For editors that automatically clean up whitespace on save, will avoid unrelated line changes in diffs.
This commit is contained in:
parent
f8e8381c00
commit
f9c67f04d4
7
.editorconfig
Normal file
7
.editorconfig
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,6 +13,7 @@
|
||||||
MANIFEST
|
MANIFEST
|
||||||
coverage.*
|
coverage.*
|
||||||
|
|
||||||
|
!.editorconfig
|
||||||
!.gitignore
|
!.gitignore
|
||||||
!.travis.yml
|
!.travis.yml
|
||||||
!.isort.cfg
|
!.isort.cfg
|
||||||
|
|
|
@ -7,4 +7,3 @@ file_filter = rest_framework/locale/<lang>/LC_MESSAGES/django.po
|
||||||
source_file = rest_framework/locale/en_US/LC_MESSAGES/django.po
|
source_file = rest_framework/locale/en_US/LC_MESSAGES/django.po
|
||||||
source_lang = en_US
|
source_lang = en_US
|
||||||
type = PO
|
type = PO
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Caching
|
# Caching
|
||||||
|
|
||||||
> A certain woman had a very sharp conciousness but almost no
|
> A certain woman had a very sharp conciousness but almost no
|
||||||
> memory ... She remembered enough to work, and she worked hard.
|
> memory ... She remembered enough to work, and she worked hard.
|
||||||
> - Lydia Davis
|
> - Lydia Davis
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ from rest_framework.views import APIView
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
|
||||||
class UserViewSet(viewsets.Viewset):
|
class UserViewSet(viewsets.Viewset):
|
||||||
|
|
||||||
# Cache requested url for each user for 2 hours
|
# Cache requested url for each user for 2 hours
|
||||||
@method_decorator(cache_page(60*60*2))
|
@method_decorator(cache_page(60*60*2))
|
||||||
@method_decorator(vary_on_cookie)
|
@method_decorator(vary_on_cookie)
|
||||||
def list(self, request, format=None):
|
def list(self, request, format=None):
|
||||||
content = {
|
content = {
|
||||||
|
@ -35,7 +35,7 @@ class UserViewSet(viewsets.Viewset):
|
||||||
class PostView(APIView):
|
class PostView(APIView):
|
||||||
|
|
||||||
# Cache page for the requested url
|
# Cache page for the requested url
|
||||||
@method_decorator(cache_page(60*60*2))
|
@method_decorator(cache_page(60*60*2))
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
content = {
|
content = {
|
||||||
'title': 'Post title',
|
'title': 'Post title',
|
||||||
|
|
|
@ -113,11 +113,11 @@ For example:
|
||||||
|
|
||||||
Note that if your API doesn't include any object level permissions, you may optionally exclude the `self.check_object_permissions`, and simply return the object from the `get_object_or_404` lookup.
|
Note that if your API doesn't include any object level permissions, you may optionally exclude the `self.check_object_permissions`, and simply return the object from the `get_object_or_404` lookup.
|
||||||
|
|
||||||
#### `filter_queryset(self, queryset)`
|
#### `filter_queryset(self, queryset)`
|
||||||
|
|
||||||
Given a queryset, filter it with whichever filter backends are in use, returning a new queryset.
|
Given a queryset, filter it with whichever filter backends are in use, returning a new queryset.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
def filter_queryset(self, queryset):
|
def filter_queryset(self, queryset):
|
||||||
filter_backends = (CategoryFilter,)
|
filter_backends = (CategoryFilter,)
|
||||||
|
|
|
@ -197,15 +197,15 @@ If you need to test if a request is a read operation or a write operation, you s
|
||||||
---
|
---
|
||||||
|
|
||||||
Custom permissions will raise a `PermissionDenied` exception if the test fails. To change the error message associated with the exception, implement a `message` attribute directly on your custom permission. Otherwise the `default_detail` attribute from `PermissionDenied` will be used.
|
Custom permissions will raise a `PermissionDenied` exception if the test fails. To change the error message associated with the exception, implement a `message` attribute directly on your custom permission. Otherwise the `default_detail` attribute from `PermissionDenied` will be used.
|
||||||
|
|
||||||
from rest_framework import permissions
|
from rest_framework import permissions
|
||||||
|
|
||||||
class CustomerAccessPermission(permissions.BasePermission):
|
class CustomerAccessPermission(permissions.BasePermission):
|
||||||
message = 'Adding customers not allowed.'
|
message = 'Adding customers not allowed.'
|
||||||
|
|
||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
...
|
...
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
The following is an example of a permission class that checks the incoming request's IP address against a blacklist, and denies the request if the IP has been blacklisted.
|
The following is an example of a permission class that checks the incoming request's IP address against a blacklist, and denies the request if the IP has been blacklisted.
|
||||||
|
|
|
@ -58,11 +58,11 @@ For example, you can append `router.urls` to a list of existing views…
|
||||||
router = routers.SimpleRouter()
|
router = routers.SimpleRouter()
|
||||||
router.register(r'users', UserViewSet)
|
router.register(r'users', UserViewSet)
|
||||||
router.register(r'accounts', AccountViewSet)
|
router.register(r'accounts', AccountViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
|
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns += router.urls
|
urlpatterns += router.urls
|
||||||
|
|
||||||
Alternatively you can use Django's `include` function, like so…
|
Alternatively you can use Django's `include` function, like so…
|
||||||
|
@ -106,10 +106,10 @@ For example, if you want to change the URL for our custom action to `^users/{pk}
|
||||||
|
|
||||||
from myapp.permissions import IsAdminOrIsSelf
|
from myapp.permissions import IsAdminOrIsSelf
|
||||||
from rest_framework.decorators import detail_route
|
from rest_framework.decorators import detail_route
|
||||||
|
|
||||||
class UserViewSet(ModelViewSet):
|
class UserViewSet(ModelViewSet):
|
||||||
...
|
...
|
||||||
|
|
||||||
@detail_route(methods=['post'], permission_classes=[IsAdminOrIsSelf], url_path='change-password')
|
@detail_route(methods=['post'], permission_classes=[IsAdminOrIsSelf], url_path='change-password')
|
||||||
def set_password(self, request, pk=None):
|
def set_password(self, request, pk=None):
|
||||||
...
|
...
|
||||||
|
@ -124,10 +124,10 @@ For example, if you want to change the name of our custom action to `'user-chang
|
||||||
|
|
||||||
from myapp.permissions import IsAdminOrIsSelf
|
from myapp.permissions import IsAdminOrIsSelf
|
||||||
from rest_framework.decorators import detail_route
|
from rest_framework.decorators import detail_route
|
||||||
|
|
||||||
class UserViewSet(ModelViewSet):
|
class UserViewSet(ModelViewSet):
|
||||||
...
|
...
|
||||||
|
|
||||||
@detail_route(methods=['post'], permission_classes=[IsAdminOrIsSelf], url_name='change-password')
|
@detail_route(methods=['post'], permission_classes=[IsAdminOrIsSelf], url_name='change-password')
|
||||||
def set_password(self, request, pk=None):
|
def set_password(self, request, pk=None):
|
||||||
...
|
...
|
||||||
|
|
|
@ -784,4 +784,3 @@ in [OpenAPI][open-api] format.
|
||||||
[api-blueprint]: https://apiblueprint.org/
|
[api-blueprint]: https://apiblueprint.org/
|
||||||
[static-files]: https://docs.djangoproject.com/en/stable/howto/static-files/
|
[static-files]: https://docs.djangoproject.com/en/stable/howto/static-files/
|
||||||
[named-arguments]: https://docs.djangoproject.com/en/stable/topics/http/urls/#named-groups
|
[named-arguments]: https://docs.djangoproject.com/en/stable/topics/http/urls/#named-groups
|
||||||
|
|
|
@ -84,7 +84,7 @@ It has two required arguments, and a single optional `messages` argument:
|
||||||
The validator should be applied to *serializer classes*, like so:
|
The validator should be applied to *serializer classes*, like so:
|
||||||
|
|
||||||
from rest_framework.validators import UniqueTogetherValidator
|
from rest_framework.validators import UniqueTogetherValidator
|
||||||
|
|
||||||
class ExampleSerializer(serializers.Serializer):
|
class ExampleSerializer(serializers.Serializer):
|
||||||
# ...
|
# ...
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.promo li a {
|
.promo li a {
|
||||||
float: left;
|
float: left;
|
||||||
|
|
|
@ -50,7 +50,7 @@ Prior to version 3.3.0 the semi extension header `X-HTTP-Method-Override` was su
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
METHOD_OVERRIDE_HEADER = 'HTTP_X_HTTP_METHOD_OVERRIDE'
|
METHOD_OVERRIDE_HEADER = 'HTTP_X_HTTP_METHOD_OVERRIDE'
|
||||||
|
|
||||||
class MethodOverrideMiddleware(object):
|
class MethodOverrideMiddleware(object):
|
||||||
def process_view(self, request, callback, callback_args, callback_kwargs):
|
def process_view(self, request, callback, callback_args, callback_kwargs):
|
||||||
if request.method != 'POST':
|
if request.method != 'POST':
|
||||||
|
|
|
@ -40,7 +40,7 @@ Here's an example of a view that returns a list of "Profile" instances, rendered
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</body></html>
|
</body></html>
|
||||||
|
|
||||||
## Rendering Forms
|
## Rendering Forms
|
||||||
|
|
||||||
Serializers may be rendered as forms by using the `render_form` template tag, and including the serializer instance as context to the template.
|
Serializers may be rendered as forms by using the `render_form` template tag, and including the serializer instance as context to the template.
|
||||||
|
@ -77,7 +77,7 @@ The following view demonstrates an example of using a serializer in a template f
|
||||||
{% load rest_framework %}
|
{% load rest_framework %}
|
||||||
|
|
||||||
<html><body>
|
<html><body>
|
||||||
|
|
||||||
<h1>Profile - {{ profile.name }}</h1>
|
<h1>Profile - {{ profile.name }}</h1>
|
||||||
|
|
||||||
<form action="{% url 'profile-detail' pk=profile.pk %}" method="POST">
|
<form action="{% url 'profile-detail' pk=profile.pk %}" method="POST">
|
||||||
|
|
|
@ -32,7 +32,7 @@ Wonder how else you can help? One of the best ways you can help Django REST Fram
|
||||||
[stackoverflow-com]: http://stackoverflow.com/jobs/developer-jobs-using-django
|
[stackoverflow-com]: http://stackoverflow.com/jobs/developer-jobs-using-django
|
||||||
[upwork-com]: https://www.upwork.com/o/jobs/browse/skill/django-framework/
|
[upwork-com]: https://www.upwork.com/o/jobs/browse/skill/django-framework/
|
||||||
[technobjobs-co-uk]: https://www.technojobs.co.uk/django-jobs
|
[technobjobs-co-uk]: https://www.technojobs.co.uk/django-jobs
|
||||||
[remoteok-io]: https://remoteok.io/remote-django-jobs
|
[remoteok-io]: https://remoteok.io/remote-django-jobs
|
||||||
[remotepython-com]: https://www.remotepython.com/jobs/
|
[remotepython-com]: https://www.remotepython.com/jobs/
|
||||||
[drf-funding]: https://fund.django-rest-framework.org/topics/funding/
|
[drf-funding]: https://fund.django-rest-framework.org/topics/funding/
|
||||||
[submit-pr]: https://github.com/encode/django-rest-framework
|
[submit-pr]: https://github.com/encode/django-rest-framework
|
||||||
|
|
|
@ -318,4 +318,3 @@ def authenticate(request=None, **credentials):
|
||||||
return authenticate(**credentials)
|
return authenticate(**credentials)
|
||||||
else:
|
else:
|
||||||
return authenticate(request=request, **credentials)
|
return authenticate(request=request, **credentials)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/* The navbar is fixed at >= 980px wide, so add padding to the body to prevent
|
/* The navbar is fixed at >= 980px wide, so add padding to the body to prevent
|
||||||
content running up underneath it. */
|
content running up underneath it. */
|
||||||
|
|
||||||
|
|
|
@ -411,4 +411,4 @@
|
||||||
<glyph unicode="" horiz-adv-x="1792" />
|
<glyph unicode="" horiz-adv-x="1792" />
|
||||||
<glyph unicode="" horiz-adv-x="1792" />
|
<glyph unicode="" horiz-adv-x="1792" />
|
||||||
</font>
|
</font>
|
||||||
</defs></svg>
|
</defs></svg>
|
||||||
|
|
Before Width: | Height: | Size: 197 KiB After Width: | Height: | Size: 197 KiB |
|
@ -285,4 +285,4 @@
|
||||||
<glyph unicode="🔑" d="M250 1200h600q21 0 35.5 -14.5t14.5 -35.5v-400q0 -21 -14.5 -35.5t-35.5 -14.5h-150v-500l-255 -178q-19 -9 -32 -1t-13 29v650h-150q-21 0 -35.5 14.5t-14.5 35.5v400q0 21 14.5 35.5t35.5 14.5zM400 1100v-100h300v100h-300z" />
|
<glyph unicode="🔑" d="M250 1200h600q21 0 35.5 -14.5t14.5 -35.5v-400q0 -21 -14.5 -35.5t-35.5 -14.5h-150v-500l-255 -178q-19 -9 -32 -1t-13 29v650h-150q-21 0 -35.5 14.5t-14.5 35.5v400q0 21 14.5 35.5t35.5 14.5zM400 1100v-100h300v100h-300z" />
|
||||||
<glyph unicode="🚪" d="M250 1200h750q39 0 69.5 -40.5t30.5 -84.5v-933l-700 -117v950l600 125h-700v-1000h-100v1025q0 23 15.5 49t34.5 26zM500 525v-100l100 20v100z" />
|
<glyph unicode="🚪" d="M250 1200h750q39 0 69.5 -40.5t30.5 -84.5v-933l-700 -117v950l600 125h-700v-1000h-100v1025q0 23 15.5 49t34.5 26zM500 525v-100l100 20v100z" />
|
||||||
</font>
|
</font>
|
||||||
</defs></svg>
|
</defs></svg>
|
||||||
|
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
|
@ -285,4 +285,4 @@
|
||||||
<glyph unicode="🔑" d="M250 1200h600q21 0 35.5 -14.5t14.5 -35.5v-400q0 -21 -14.5 -35.5t-35.5 -14.5h-150v-500l-255 -178q-19 -9 -32 -1t-13 29v650h-150q-21 0 -35.5 14.5t-14.5 35.5v400q0 21 14.5 35.5t35.5 14.5zM400 1100v-100h300v100h-300z" />
|
<glyph unicode="🔑" d="M250 1200h600q21 0 35.5 -14.5t14.5 -35.5v-400q0 -21 -14.5 -35.5t-35.5 -14.5h-150v-500l-255 -178q-19 -9 -32 -1t-13 29v650h-150q-21 0 -35.5 14.5t-14.5 35.5v400q0 21 14.5 35.5t35.5 14.5zM400 1100v-100h300v100h-300z" />
|
||||||
<glyph unicode="🚪" d="M250 1200h750q39 0 69.5 -40.5t30.5 -84.5v-933l-700 -117v950l600 125h-700v-1000h-100v1025q0 23 15.5 49t34.5 26zM500 525v-100l100 20v100z" />
|
<glyph unicode="🚪" d="M250 1200h750q39 0 69.5 -40.5t30.5 -84.5v-933l-700 -117v950l600 125h-700v-1000h-100v1025q0 23 15.5 49t34.5 26zM500 525v-100l100 20v100z" />
|
||||||
</font>
|
</font>
|
||||||
</defs></svg>
|
</defs></svg>
|
||||||
|
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
|
@ -69,7 +69,3 @@ at <code>rest_framework/docs/error.html</code>.</p>
|
||||||
<script src="{% static 'rest_framework/docs/js/jquery-1.10.2.min.js' %}"></script>
|
<script src="{% static 'rest_framework/docs/js/jquery-1.10.2.min.js' %}"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,4 +3,3 @@
|
||||||
<pre class="highlight javascript hide" data-language="javascript"><code>{% code html %}<!-- Load the JavaScript client library -->
|
<pre class="highlight javascript hide" data-language="javascript"><code>{% code html %}<!-- Load the JavaScript client library -->
|
||||||
<script src="{% static 'rest_framework/js/coreapi-0.1.1.js' %}"></script>
|
<script src="{% static 'rest_framework/js/coreapi-0.1.1.js' %}"></script>
|
||||||
<script src="{% url 'api-docs:schema-js' %}"></script>{% endcode %}</code></pre>
|
<script src="{% url 'api-docs:schema-js' %}"></script>{% endcode %}</code></pre>
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
|
|
||||||
from rest_framework import compat # noqa
|
from rest_framework import compat # noqa
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from tests import importable
|
from tests import importable
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user