Commit Graph

239 Commits

Author SHA1 Message Date
Carlton Gibson
a540acdc95
Allowed customising API documentation code samples (#5752)
* Allowed additional languages in API documentation

* Documented renderer_classes parameter and customising languages.
2018-01-25 09:39:03 +01:00
Jon Dufresne
d3f3c3d9c1 Prefer https protocol for links in docs when available 2018-01-15 15:15:21 +01:00
Jon Dufresne
ffe3dbb1b1 Perfer iter(dict) over iter(dict.keys()) (#5736)
Calling dict.keys() is unnecessary. The two are functionally equivalent
on modern Pythons.

Inspired by Lennart Regebro's talk "Prehistoric Patterns in Python" from
PyCon 2017.

https://www.youtube.com/watch?v=V5-JH23Vk0I
2018-01-08 09:49:46 +00:00
Ryan P Kilby
b7ed645927 Disable HTML inputs for dict/list fields (#5702) 2018-01-02 10:50:49 +01:00
Sander Steffann
d71bd57b64 SchemaJSRenderer renders invalid Javascript (#5607)
* SchemaJSRenderer renders invalid Javascript

Under Py3 the base64.b64encode() method returns a binary object, which gets rendered as `b'...'` in schema.js. This results in the output becoming:

    var coreJSON = window.atob('b'eyJf...'');

which is invalid Javascript. Because base64 only uses ASCII characters it is safe to decode('ascii') it. Under Py2 this will result in a unicode object, which is fine. Under Py3 it results in a string, which is also fine. This solves the problem and results in a working schema.js output.

* Add regression test for #5608

* Add regression test for #5608

* Apparently the linter on Travis wants the imports in a different order than on my box...
2017-11-22 15:47:03 +01:00
Jon Dufresne
ff556a91fd Remove references to unsupported Django versions in docs and code (#5602)
Per the trove classifiers, DRF only supports Django versions 1.10+. Can
drop documentation, code comments, and workarounds for older Django
versions.
2017-11-20 09:35:54 +01:00
Éric Araujo
57ad208dc6 add pygments CSS block in browsable API views (#5584) 2017-11-10 09:42:21 +01:00
Jon Dufresne
f77e794dc8 Fix all BytesWarning caught during tests (#5561)
Running the tests with bytes warning enabled shows some bytes/str
mixups. Fix them all.

Some examples of mixing usage:

str(b'foo') -- calling str() on bytes
b'foo' == 'foo' -- compare str with bytes
'foo' + b'bar' -- concatenating str and bytes
2017-11-06 10:02:48 +01:00
Carlton Gibson
565c722762
Add interactive docs error template (#5548) 2017-11-06 09:04:07 +01:00
Jamie Cockburn
efb047fa07 JSONField renders as textarea (#5529) (#5530) 2017-10-25 10:55:41 +02:00
Ryan P Kilby
cbfa444454 Fix HiddenField stripping in BrowsableAPIRenderer (#5499) 2017-10-16 09:35:53 +02:00
Carlton Gibson
c674687782 Remove Django 1.8 & 1.9 compatibility code (#5481)
* Identify code that needs to be pulled out of/removed from compat.py

* Extract modern code from get_names_and_managers in compat.py and remove compat code

* Extract modern code from is_authenticated() in compat.py and remove.

* Extract modern code from is_anonymous() in compat.py and remove

* Extract modern code from get_related_model() from compat.py and remove

* Extract modern code from value_from_object() in compat.py and remove

* Update postgres compat

JSONField now always available.

* Remove DecimalValidator compat

* Remove get_remote_field compat

* Remove template_render compat

Plus isort.

* Remove set_many compat

* Remove include compat
2017-10-05 20:41:38 +02:00
Ryan P Kilby
8ab75a2f01 Add 'STRICT_JSON' API setting.
STRICT_JSON controls the renderer & parser behavior on whether or not
to accept non-standard float values (NaN, Infinity).
2017-09-25 09:08:20 +02:00
Ryan P Kilby
d740bae95a Update json imports 2017-09-25 09:08:20 +02:00
Daniele Varrazzo
e42eb42d49 Don't make the content mandatory in the generic content form (#5372)
Sometimes, probably in the upgrade from Django 1.9 to 1.10, a post with
empty content is forbidden by javascript, with the message "Please fill
in this field". Filling the form with '{}' allows an application/json
request to be submitted.

The API call itself works perfectly well with a post with empty content:
the interface shouldn't make assumptions about it.
2017-09-04 10:04:48 +01:00
elmccarthy
b905197f24 Fix issue #5258 (#5259)
Sanitize serializer.data to remove hidden fields before rendering template JSON instance to raw data form.

* Fix lint issues
2017-07-10 11:43:36 +01:00
Tom Christie
de9a8c4811 Fix mime type on schema.js endpoint. Closes #4968. 2017-03-13 10:03:13 +00:00
Tom Christie
52db57a6e7 Version 3.6 (#4943) 2017-03-09 14:49:51 +00:00
Tom Christie
68d2020112 Live API documentation (#4755) 2017-03-03 15:24:37 +00:00
Artem Muterko
b6b2c4bb5b Renderer tests (#4791) 2017-01-08 16:33:43 +00:00
Artem Muterko
4dd71d68d2 Remove extra parentheses (#4789) 2017-01-08 16:09:23 +00:00
Tom Christie
0dec36eb41 Version 3.5 (#4525)
* Start test case

* Added 'requests' test client

* Address typos

* Graceful fallback if requests is not installed.

* Add cookie support

* Tests for auth and CSRF

* Py3 compat

* py3 compat

* py3 compat

* Add get_requests_client

* Added SchemaGenerator.should_include_link

* add settings for html cutoff on related fields

* Router doesn't work if prefix is blank, though project urls.py handles prefix

* Fix Django 1.10 to-many deprecation

* Add django.core.urlresolvers compatibility

* Update django-filter & django-guardian

* Check for empty router prefix; adjust URL accordingly

It's easiest to fix this issue after we have made the regex.  To try
to fix it before would require doing something different for List vs
Detail, which means we'd have to know which type of url we're
constructing before acting accordingly.

* Fix misc django deprecations

* Use TOC extension instead of header

* Fix deprecations for py3k

* Add py3k compatibility to is_simple_callable

* Add is_simple_callable tests

* Drop python 3.2 support (EOL, Dropped by Django)

* schema_renderers= should *set* the renderers, not append to them.

* API client (#4424)

* Fix release notes

* Add note about 'User account is disabled.' vs 'Unable to log in'

* Clean up schema generation (#4527)

* Handle multiple methods on custom action (#4529)

* RequestsClient, CoreAPIClient

* exclude_from_schema

* Added 'get_schema_view()' shortcut

* Added schema descriptions

* Better descriptions for schemas

* Add type annotation to schema generation

* Coerce schema 'pk' in path to actual field name

* Deprecations move into assertion errors

* Use get_schema_view in tests

* Updte CoreJSON media type

* Handle schema structure correctly when path prefixs exist. Closes #4401

* Add PendingDeprecation to Router schema generation.

* Added SCHEMA_COERCE_PATH_PK and SCHEMA_COERCE_METHOD_NAMES

* Renamed and documented 'get_schema_fields' interface.
2016-10-10 13:03:46 +01:00
Tom Christie
b76984d222 Allow custom CSRF_HEADER_NAME setting. (#4415) 2016-08-18 11:24:03 +01:00
Tom Christie
0781182646 Fix call to .resolve_context (#4371) 2016-08-09 17:48:29 +01:00
Tom Christie
bb613c5ad1 Version 3.4.3 (#4361)
* Version 3.4.3
2016-08-05 13:33:25 +01:00
René Fleschenberg
9f5e841daf Change template context generation in TemplateHTMLRenderer (#4236)
- Change the name of ``resolve_context()`` to ``get_template_context()``.
- Pass the renderer context to this method, to give subclasses more flexibility
  when overriding.
2016-08-02 13:11:41 +01:00
Tom Christie
6ff9840bde Schemas & client libraries. (#4179)
* Added schema generation support.
* New tutorial section.
* API guide on schema generation.
* Topic guide on API clients.
2016-07-04 16:38:17 +01:00
Tom Christie
bb22ab8ee7 More robust form rendering in the browsable API (#4181) 2016-06-08 17:13:20 +01:00
Tom Christie
994e1ba927 Django 1.10 support. (#4158)
* Added TEMPLATES setting to tests
* Remove deprecated view-string in URL conf
* Replace 'urls = ...' in test classes with override_settings('ROOT_URLCONF=...')
* Refactor UsingURLPatterns to use override_settings(ROOT_URLCONF=...) style
* Get model managers and names in a version-compatible manner.
* Apply override_settings to a TestCase, not a mixin class
* Use '.callback' property instead of private attributes when inspecting urlpatterns
* Pass 'user' to template explicitly
* Correct sorting of import statements.
* Remove unused TEMPLATE_LOADERS setting, in favor of TEMPLATES.
* Remove code style issue
* BaseFilter test requires a concrete model
* Resolve tox.ini issues
* Resolve isort differences between local and tox environments
2016-06-01 15:31:00 +01:00
Alexander Gaevsky
1328982de3 Set proper status code in AdminRenderer for the redirection after POST/DELETE requests. (#4106) 2016-05-16 09:22:28 +01:00
Clinton Blackburn
9d9658f128 Added support for custom CSRF cookie names
Instead of hardcoding the CSRF cookie name, the value is passed to the template as a context variable, rendered as a JavaScript variable, and read by csrf.js.

Fixes #4048
2016-04-11 23:58:55 -04:00
Stephan Groß
a101251a2a Fix blank lines around docstrings 2016-03-17 11:06:47 +00:00
Karambir Singh Nain
69f1e3a9fd Remove old django checks from tests and compat
Remove skipping of tests for Django<1.8. Remove several functions from compat.py not needed for Django>=1.8
2016-02-19 01:47:45 +05:30
Mikalay Radchuk
714607307e Fixes AttributeError in HTMLFormRenderer.render
If `HTMLFormRenderer.render` will be called with default arguments,
`AttributeError: 'NoneType' object has no attribute 'get'` will be raised.
2016-01-26 21:26:30 +03:00
Raphael Merx
fcc0a70f7c Fixed suggestion for format in test renderer
Rendered would suggest using format='JSON' when the right argument is
format='json'.
2015-12-10 15:19:03 -08:00
Tom Christie
378b7b8963 Merge pull request #3655 from andreif/fix/headers-order
Sort response headers in api renderer
2015-11-18 17:25:54 +00:00
Andrei Fokau
8692816401 Sort response headers in api renderer to keep the same order 2015-11-18 17:33:12 +01:00
Andrei Fokau
802ee5d0ea Fix template.render deprecation warnings for 1.9+ 2015-11-18 17:06:35 +01:00
Tom Christie
c53c9eddfe Merge pull request #3315 from tomchristie/filters
First pass at HTML rendering for filters
2015-10-22 11:42:35 +01:00
Tom Christie
0c6d46729c Docs on the filter HTML interface 2015-10-22 11:37:27 +01:00
Tom Christie
34eb18b498 Merge branch 'master' into filters
Conflicts:
	rest_framework/compat.py
	rest_framework/filters.py
2015-10-19 13:14:42 +01:00
Tom Christie
90247afe29 Docs on Forms API 2015-10-12 21:14:58 +01:00
Tom Christie
41182c6f06 Formns API 2015-10-06 10:58:20 +01:00
Philippe Ombredanne
3262ee6c90 Fixed minor doc typo. 2015-09-29 21:59:09 +02:00
Tom Christie
566812ac0b Remove method and content overriding 2015-09-17 15:17:29 +01:00
Tom Christie
0b77e733a8 Don't display filter control on detail views 2015-08-27 14:35:39 +01:00
Tom Christie
aeb57913c9 Filter HTML refinments 2015-08-27 14:25:44 +01:00
Tom Christie
5db900c625 First pass at HTML rendering for filters 2015-08-21 16:13:52 +01:00
Tom Christie
75be91912c Allow AdminRenderer to function when pagination is disabled. Closes #3275. 2015-08-20 12:28:00 +01:00
Tom Christie
6942fa5dab Mask view docstring on 401 and 403 responses. Closes #3216. 2015-08-05 13:59:55 +01:00