mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-09 08:00:52 +03:00
Merge master
This commit is contained in:
commit
36e21153fb
|
@ -30,7 +30,7 @@ The default authentication policy may be set globally, using the `DEFAULT_AUTHEN
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||||
'rest_framework.authentication.UserBasicAuthentication',
|
'rest_framework.authentication.BasicAuthentication',
|
||||||
'rest_framework.authentication.SessionAuthentication',
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ The default authentication policy may be set globally, using the `DEFAULT_AUTHEN
|
||||||
You can also set the authentication policy on a per-view basis, using the `APIView` class based views.
|
You can also set the authentication policy on a per-view basis, using the `APIView` class based views.
|
||||||
|
|
||||||
class ExampleView(APIView):
|
class ExampleView(APIView):
|
||||||
authentication_classes = (SessionAuthentication, UserBasicAuthentication)
|
authentication_classes = (SessionAuthentication, BasicAuthentication)
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated,)
|
||||||
|
|
||||||
def get(self, request, format=None):
|
def get(self, request, format=None):
|
||||||
|
@ -51,7 +51,7 @@ You can also set the authentication policy on a per-view basis, using the `APIVi
|
||||||
Or, if you're using the `@api_view` decorator with function based views.
|
Or, if you're using the `@api_view` decorator with function based views.
|
||||||
|
|
||||||
@api_view(['GET'])
|
@api_view(['GET'])
|
||||||
@authentication_classes((SessionAuthentication, UserBasicAuthentication))
|
@authentication_classes((SessionAuthentication, BasicAuthentication))
|
||||||
@permissions_classes((IsAuthenticated,))
|
@permissions_classes((IsAuthenticated,))
|
||||||
def example_view(request, format=None):
|
def example_view(request, format=None):
|
||||||
content = {
|
content = {
|
||||||
|
|
|
@ -31,8 +31,8 @@ The default throttling policy may be set globally, using the `DEFAULT_THROTTLE_C
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_THROTTLE_CLASSES': (
|
'DEFAULT_THROTTLE_CLASSES': (
|
||||||
'rest_framework.throttles.AnonThrottle',
|
'rest_framework.throttling.AnonRateThrottle',
|
||||||
'rest_framework.throttles.UserThrottle'
|
'rest_framework.throttling.UserRateThrottle'
|
||||||
),
|
),
|
||||||
'DEFAULT_THROTTLE_RATES': {
|
'DEFAULT_THROTTLE_RATES': {
|
||||||
'anon': '100/day',
|
'anon': '100/day',
|
||||||
|
@ -136,7 +136,7 @@ For example, given the following views...
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_THROTTLE_CLASSES': (
|
'DEFAULT_THROTTLE_CLASSES': (
|
||||||
'rest_framework.throttles.ScopedRateThrottle'
|
'rest_framework.throttling.ScopedRateThrottle'
|
||||||
),
|
),
|
||||||
'DEFAULT_THROTTLE_RATES': {
|
'DEFAULT_THROTTLE_RATES': {
|
||||||
'contacts': '1000/day',
|
'contacts': '1000/day',
|
||||||
|
|
|
@ -52,6 +52,7 @@ The following people have helped make REST framework great.
|
||||||
* Madis Väin - [madisvain]
|
* Madis Väin - [madisvain]
|
||||||
* Stephan Groß - [minddust]
|
* Stephan Groß - [minddust]
|
||||||
* Pavel Savchenko - [asfaltboy]
|
* Pavel Savchenko - [asfaltboy]
|
||||||
|
* Otto Yiu - [ottoyiu]
|
||||||
|
|
||||||
Many thanks to everyone who's contributed to the project.
|
Many thanks to everyone who's contributed to the project.
|
||||||
|
|
||||||
|
@ -139,3 +140,4 @@ To contact the author directly:
|
||||||
[madisvain]: https://github.com/madisvain
|
[madisvain]: https://github.com/madisvain
|
||||||
[minddust]: https://github.com/minddust
|
[minddust]: https://github.com/minddust
|
||||||
[asfaltboy]: https://github.com/asfaltboy
|
[asfaltboy]: https://github.com/asfaltboy
|
||||||
|
[ottoyiu]: https://github.com/OttoYiu
|
||||||
|
|
|
@ -92,7 +92,7 @@ Let's take a look at how we can compose our views by using the mixin classes.
|
||||||
|
|
||||||
class SnippetList(mixins.ListModelMixin,
|
class SnippetList(mixins.ListModelMixin,
|
||||||
mixins.CreateModelMixin,
|
mixins.CreateModelMixin,
|
||||||
generics.MultipleObjectBaseView):
|
generics.MultipleObjectAPIView):
|
||||||
model = Snippet
|
model = Snippet
|
||||||
serializer_class = SnippetSerializer
|
serializer_class = SnippetSerializer
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ Let's take a look at how we can compose our views by using the mixin classes.
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
return self.create(request, *args, **kwargs)
|
return self.create(request, *args, **kwargs)
|
||||||
|
|
||||||
We'll take a moment to examine exactly what's happening here - We're building our view using `MultipleObjectBaseView`, and adding in `ListModelMixin` and `CreateModelMixin`.
|
We'll take a moment to examine exactly what's happening here - We're building our view using `MultipleObjectAPIView`, and adding in `ListModelMixin` and `CreateModelMixin`.
|
||||||
|
|
||||||
The base class provides the core functionality, and the mixin classes provide the `.list()` and `.create()` actions. We're then explicitly binding the `get` and `post` methods to the appropriate actions. Simple enough stuff so far.
|
The base class provides the core functionality, and the mixin classes provide the `.list()` and `.create()` actions. We're then explicitly binding the `get` and `post` methods to the appropriate actions. Simple enough stuff so far.
|
||||||
|
|
||||||
|
|
|
@ -212,9 +212,9 @@ class ModelField(WritableField):
|
||||||
def from_native(self, value):
|
def from_native(self, value):
|
||||||
try:
|
try:
|
||||||
rel = self.model_field.rel
|
rel = self.model_field.rel
|
||||||
|
return rel.to._meta.get_field(rel.field_name).to_python(value)
|
||||||
except:
|
except:
|
||||||
return self.model_field.to_python(value)
|
return self.model_field.to_python(value)
|
||||||
return rel.to._meta.get_field(rel.field_name).to_python(value)
|
|
||||||
|
|
||||||
def field_to_native(self, obj, field_name):
|
def field_to_native(self, obj, field_name):
|
||||||
value = self.model_field._get_val_from_obj(obj)
|
value = self.model_field._get_val_from_obj(obj)
|
||||||
|
|
|
@ -29,7 +29,7 @@ class CreateModelMixin(object):
|
||||||
class ListModelMixin(object):
|
class ListModelMixin(object):
|
||||||
"""
|
"""
|
||||||
List a queryset.
|
List a queryset.
|
||||||
Should be mixed in with `MultipleObjectBaseView`.
|
Should be mixed in with `MultipleObjectAPIView`.
|
||||||
"""
|
"""
|
||||||
empty_error = u"Empty list and '%(class_name)s.allow_empty' is False."
|
empty_error = u"Empty list and '%(class_name)s.allow_empty' is False."
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ class JSONPRenderer(JSONRenderer):
|
||||||
callback = self.get_callback(renderer_context)
|
callback = self.get_callback(renderer_context)
|
||||||
json = super(JSONPRenderer, self).render(data, accepted_media_type,
|
json = super(JSONPRenderer, self).render(data, accepted_media_type,
|
||||||
renderer_context)
|
renderer_context)
|
||||||
return "%s(%s);" % (callback, json)
|
return u"%s(%s);" % (callback, json)
|
||||||
|
|
||||||
|
|
||||||
class XMLRenderer(BaseRenderer):
|
class XMLRenderer(BaseRenderer):
|
||||||
|
|
|
@ -131,12 +131,12 @@
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ post_form.non_field_errors }}
|
{{ post_form.non_field_errors }}
|
||||||
{% for field in post_form %}
|
{% for field in post_form %}
|
||||||
<div class="control-group {% if field.errors %}error{% endif %}">
|
<div class="control-group"> <!--{% if field.errors %}error{% endif %}-->
|
||||||
{{ field.label_tag|add_class:"control-label" }}
|
{{ field.label_tag|add_class:"control-label" }}
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{ field }}
|
{{ field }}
|
||||||
<span class="help-inline">{{ field.help_text }}</span>
|
<span class="help-inline">{{ field.help_text }}</span>
|
||||||
{{ field.errors|add_class:"help-block" }}
|
<!--{{ field.errors|add_class:"help-block" }}-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -156,12 +156,12 @@
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ put_form.non_field_errors }}
|
{{ put_form.non_field_errors }}
|
||||||
{% for field in put_form %}
|
{% for field in put_form %}
|
||||||
<div class="control-group {% if field.errors %}error{% endif %}">
|
<div class="control-group"> <!--{% if field.errors %}error{% endif %}-->
|
||||||
{{ field.label_tag|add_class:"control-label" }}
|
{{ field.label_tag|add_class:"control-label" }}
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{ field }}
|
{{ field }}
|
||||||
<span class='help-inline'>{{ field.help_text }}</span>
|
<span class='help-inline'>{{ field.help_text }}</span>
|
||||||
{{ field.errors|add_class:"help-block" }}
|
<!--{{ field.errors|add_class:"help-block" }}-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user