Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
89cb771b
Kaydet (Commit)
89cb771b
authored
Ock 31, 2013
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #19692 -- Completed deprecation of mimetype in favor of content_type.
Thanks Tim for the report and initial patch.
üst
b2039d39
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
81 additions
and
41 deletions
+81
-41
views.py
django/contrib/sitemaps/views.py
+21
-5
__init__.py
django/shortcuts/__init__.py
+9
-1
outputting-csv.txt
docs/howto/outputting-csv.txt
+3
-3
outputting-pdf.txt
docs/howto/outputting-pdf.txt
+2
-2
deprecation.txt
docs/internals/deprecation.txt
+8
-2
actions.txt
docs/ref/contrib/admin/actions.txt
+1
-3
template-response.txt
docs/ref/template-response.txt
+21
-15
shortcuts.txt
docs/topics/http/shortcuts.txt
+10
-3
generic_urls.py
tests/regressiontests/views/generic_urls.py
+1
-1
shortcuts.py
tests/regressiontests/views/tests/shortcuts.py
+2
-2
views.py
tests/regressiontests/views/views.py
+3
-4
No files found.
django/contrib/sitemaps/views.py
Dosyayı görüntüle @
89cb771b
import
warnings
from
django.contrib.sites.models
import
get_current_site
from
django.core
import
urlresolvers
from
django.core.paginator
import
EmptyPage
,
PageNotAnInteger
...
...
@@ -6,8 +8,15 @@ from django.template.response import TemplateResponse
from
django.utils
import
six
def
index
(
request
,
sitemaps
,
template_name
=
'sitemap_index.xml'
,
mimetype
=
'application/xml'
,
sitemap_url_name
=
'django.contrib.sitemaps.views.sitemap'
):
template_name
=
'sitemap_index.xml'
,
content_type
=
'application/xml'
,
sitemap_url_name
=
'django.contrib.sitemaps.views.sitemap'
,
mimetype
=
None
):
if
mimetype
:
warnings
.
warn
(
"The mimetype keyword argument is deprecated, use "
"content_type instead"
,
DeprecationWarning
,
stacklevel
=
2
)
content_type
=
mimetype
req_protocol
=
'https'
if
request
.
is_secure
()
else
'http'
req_site
=
get_current_site
(
request
)
...
...
@@ -24,10 +33,17 @@ def index(request, sitemaps,
sites
.
append
(
'
%
s?p=
%
s'
%
(
absolute_url
,
page
))
return
TemplateResponse
(
request
,
template_name
,
{
'sitemaps'
:
sites
},
content_type
=
mime
type
)
content_type
=
content_
type
)
def
sitemap
(
request
,
sitemaps
,
section
=
None
,
template_name
=
'sitemap.xml'
,
mimetype
=
'application/xml'
):
template_name
=
'sitemap.xml'
,
content_type
=
'application/xml'
,
mimetype
=
None
):
if
mimetype
:
warnings
.
warn
(
"The mimetype keyword argument is deprecated, use "
"content_type instead"
,
DeprecationWarning
,
stacklevel
=
2
)
content_type
=
mimetype
req_protocol
=
'https'
if
request
.
is_secure
()
else
'http'
req_site
=
get_current_site
(
request
)
...
...
@@ -51,4 +67,4 @@ def sitemap(request, sitemaps, section=None,
except
PageNotAnInteger
:
raise
Http404
(
"No page '
%
s'"
%
page
)
return
TemplateResponse
(
request
,
template_name
,
{
'urlset'
:
urls
},
content_type
=
mime
type
)
content_type
=
content_
type
)
django/shortcuts/__init__.py
Dosyayı görüntüle @
89cb771b
...
...
@@ -3,6 +3,7 @@ This module collects helper functions and classes that "span" multiple levels
of MVC. In other words, these functions/classes introduce controlled coupling
for convenience's sake.
"""
import
warnings
from
django.template
import
loader
,
RequestContext
from
django.http
import
HttpResponse
,
Http404
...
...
@@ -17,7 +18,14 @@ def render_to_response(*args, **kwargs):
Returns a HttpResponse whose content is filled with the result of calling
django.template.loader.render_to_string() with the passed arguments.
"""
httpresponse_kwargs
=
{
'content_type'
:
kwargs
.
pop
(
'mimetype'
,
None
)}
httpresponse_kwargs
=
{
'content_type'
:
kwargs
.
pop
(
'content_type'
,
None
)}
mimetype
=
kwargs
.
pop
(
'mimetype'
,
None
)
if
mimetype
:
warnings
.
warn
(
"The mimetype keyword argument is deprecated, use "
"content_type instead"
,
DeprecationWarning
,
stacklevel
=
2
)
httpresponse_kwargs
[
'content_type'
]
=
mimetype
return
HttpResponse
(
loader
.
render_to_string
(
*
args
,
**
kwargs
),
**
httpresponse_kwargs
)
def
render
(
request
,
*
args
,
**
kwargs
):
...
...
docs/howto/outputting-csv.txt
Dosyayı görüntüle @
89cb771b
...
...
@@ -20,7 +20,7 @@ Here's an example::
def some_view(request):
# Create the HttpResponse object with the appropriate CSV header.
response = HttpResponse(
mime
type='text/csv')
response = HttpResponse(
content_
type='text/csv')
response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
writer = csv.writer(response)
...
...
@@ -92,7 +92,7 @@ Here's an example, which generates the same CSV file as above::
def some_view(request):
# Create the HttpResponse object with the appropriate CSV header.
response = HttpResponse(
mime
type='text/csv')
response = HttpResponse(
content_
type='text/csv')
response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
# The data is hard-coded here, but you could load it from a database or
...
...
@@ -111,7 +111,7 @@ Here's an example, which generates the same CSV file as above::
The only difference between this example and the previous example is that this
one uses template loading instead of the CSV module. The rest of the code --
such as the ``
mime
type='text/csv'`` -- is the same.
such as the ``
content_
type='text/csv'`` -- is the same.
Then, create the template ``my_template_name.txt``, with this template code:
...
...
docs/howto/outputting-pdf.txt
Dosyayı görüntüle @
89cb771b
...
...
@@ -51,7 +51,7 @@ Here's a "Hello World" example::
def some_view(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(
mime
type='application/pdf')
response = HttpResponse(
content_
type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
# Create the PDF object, using the response object as its "file."
...
...
@@ -120,7 +120,7 @@ Here's the above "Hello World" example rewritten to use :mod:`io`::
def some_view(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(
mime
type='application/pdf')
response = HttpResponse(
content_
type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'
buffer = BytesIO()
...
...
docs/internals/deprecation.txt
Dosyayı görüntüle @
89cb771b
...
...
@@ -290,8 +290,14 @@ these changes.
specified as a plain string instead of a tuple will be removed and raise an
exception.
* The ``mimetype`` argument to :class:`~django.http.HttpResponse` ``__init__``
will be removed (``content_type`` should be used instead).
* The ``mimetype`` argument to the ``__init__`` methods of
:class:`~django.http.HttpResponse`,
:class:`~django.template.response.SimpleTemplateResponse`, and
:class:`~django.template.response.TemplateResponse`, will be removed.
``content_type`` should be used instead. This also applies to the
:func:`~django.shortcuts.render_to_response` shortcut and
the sitemamp views, :func:`~django.contrib.sitemaps.views.index` and
:func:`~django.contrib.sitemaps.views.sitemap`.
* When :class:`~django.http.HttpResponse` is instantiated with an iterator,
or when :attr:`~django.http.HttpResponse.content` is set to an iterator,
...
...
docs/ref/contrib/admin/actions.txt
Dosyayı görüntüle @
89cb771b
...
...
@@ -223,7 +223,7 @@ objects as JSON::
from django.core import serializers
def export_as_json(modeladmin, request, queryset):
response = HttpResponse(
mimetype="text/javascript
")
response = HttpResponse(
content_type="application/json
")
serializers.serialize("json", queryset, stream=response)
return response
...
...
@@ -356,5 +356,3 @@ Conditionally enabling or disabling actions
if 'delete_selected' in actions:
del actions['delete_selected']
return actions
docs/ref/template-response.txt
Dosyayı görüntüle @
89cb771b
...
...
@@ -56,11 +56,11 @@ Attributes
Methods
-------
.. method:: SimpleTemplateResponse.__init__(template, context=None,
mimetype=None, status=None, content_type
=None)
.. method:: SimpleTemplateResponse.__init__(template, context=None,
content_type=None, status
=None)
Instantiates a
:class:`~django.template.response.SimpleTemplateResponse` object
with the given template, context,
MIME type
and HTTP status.
with the given template, context,
content type,
and HTTP status.
``template``
The full name of a template, or a sequence of template names.
...
...
@@ -75,12 +75,15 @@ Methods
The HTTP Status code for the response.
``content_type``
An alias for ``mimetype``. Historically, this parameter was only called
``mimetype``, but since this is actually the value included in the HTTP
``Content-Type`` header, it can also include the character set encoding,
which makes it more than just a MIME type specification. If ``mimetype``
is specified (not ``None``), that value is used. Otherwise,
``content_type`` is used. If neither is given,
.. versionchanged:: 1.5
Historically, this parameter was only called ``mimetype`` (now
deprecated), but since this is actually the value included in the HTTP
``Content-Type`` header, it can also include the character set
encoding, which makes it more than just a MIME type specification. If
``mimetype`` is specified (not ``None``), that value is used.
Otherwise, ``content_type`` is used. If neither is given,
:setting:`DEFAULT_CONTENT_TYPE` is used.
...
...
@@ -144,7 +147,7 @@ TemplateResponse objects
Methods
-------
.. method:: TemplateResponse.__init__(request, template, context=None,
mimetype=None, status=None, content_type
=None, current_app=None)
.. method:: TemplateResponse.__init__(request, template, context=None,
content_type=None, status
=None, current_app=None)
Instantiates an ``TemplateResponse`` object with the given
template, context, MIME type and HTTP status.
...
...
@@ -165,12 +168,15 @@ Methods
The HTTP Status code for the response.
``content_type``
An alias for ``mimetype``. Historically, this parameter was only called
``mimetype``, but since this is actually the value included in the HTTP
``Content-Type`` header, it can also include the character set encoding,
which makes it more than just a MIME type specification. If ``mimetype``
is specified (not ``None``), that value is used. Otherwise,
``content_type`` is used. If neither is given,
.. versionchanged:: 1.5
Historically, this parameter was only called ``mimetype`` (now
deprecated), but since this is actually the value included in the HTTP
``Content-Type`` header, it can also include the character set
encoding, which makes it more than just a MIME type specification. If
``mimetype`` is specified (not ``None``), that value is used.
Otherwise, ``content_type`` is used. If neither is given,
:setting:`DEFAULT_CONTENT_TYPE` is used.
``current_app``
...
...
docs/topics/http/shortcuts.txt
Dosyayı görüntüle @
89cb771b
...
...
@@ -50,6 +50,9 @@ Optional arguments
The MIME type to use for the resulting document. Defaults to the value of
the :setting:`DEFAULT_CONTENT_TYPE` setting.
.. versionchanged:: 1.5
This parameter used to be called ``mimetype``.
``status``
The status code for the response. Defaults to ``200``.
...
...
@@ -87,7 +90,7 @@ This example is equivalent to::
``render_to_response``
======================
.. function:: render_to_response(template_name[, dictionary][, context_instance][,
mime
type])
.. function:: render_to_response(template_name[, dictionary][, context_instance][,
content_
type])
Renders a given template with a given context dictionary and returns an
:class:`~django.http.HttpResponse` object with that rendered text.
...
...
@@ -121,10 +124,14 @@ Optional arguments
my_data_dictionary,
context_instance=RequestContext(request))
``
mime
type``
``
content_
type``
The MIME type to use for the resulting document. Defaults to the value of
the :setting:`DEFAULT_CONTENT_TYPE` setting.
.. versionchanged:: 1.5
This parameter used to be called ``mimetype``.
Example
-------
...
...
@@ -148,7 +155,7 @@ This example is equivalent to::
t = loader.get_template('myapp/template.html')
c = Context({'foo': 'bar'})
return HttpResponse(t.render(c),
mime
type="application/xhtml+xml")
content_
type="application/xhtml+xml")
``redirect``
============
...
...
tests/regressiontests/views/generic_urls.py
Dosyayı görüntüle @
89cb771b
...
...
@@ -47,7 +47,7 @@ urlpatterns += patterns('',
urlpatterns
+=
patterns
(
'regressiontests.views.views'
,
(
r'^shortcuts/render_to_response/$'
,
'render_to_response_view'
),
(
r'^shortcuts/render_to_response/request_context/$'
,
'render_to_response_view_with_request_context'
),
(
r'^shortcuts/render_to_response/
mimetype/$'
,
'render_to_response_view_with_mime
type'
),
(
r'^shortcuts/render_to_response/
content_type/$'
,
'render_to_response_view_with_content_
type'
),
(
r'^shortcuts/render/$'
,
'render_view'
),
(
r'^shortcuts/render/base_context/$'
,
'render_view_with_base_context'
),
(
r'^shortcuts/render/content_type/$'
,
'render_view_with_content_type'
),
...
...
tests/regressiontests/views/tests/shortcuts.py
Dosyayı görüntüle @
89cb771b
...
...
@@ -21,8 +21,8 @@ class ShortcutTests(TestCase):
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR../path/to/static/media/
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/html; charset=utf-8'
)
def
test_render_to_response_with_
mime
type
(
self
):
response
=
self
.
client
.
get
(
'/shortcuts/render_to_response/
mime
type/'
)
def
test_render_to_response_with_
content_
type
(
self
):
response
=
self
.
client
.
get
(
'/shortcuts/render_to_response/
content_
type/'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
content
,
b
'FOO.BAR..
\n
'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'application/x-rendertest'
)
...
...
tests/regressiontests/views/views.py
Dosyayı görüntüle @
89cb771b
...
...
@@ -68,11 +68,11 @@ def render_to_response_view_with_request_context(request):
'bar'
:
'BAR'
,
},
context_instance
=
RequestContext
(
request
))
def
render_to_response_view_with_
mime
type
(
request
):
def
render_to_response_view_with_
content_
type
(
request
):
return
render_to_response
(
'debug/render_test.html'
,
{
'foo'
:
'FOO'
,
'bar'
:
'BAR'
,
},
mime
type
=
'application/x-rendertest'
)
},
content_
type
=
'application/x-rendertest'
)
def
render_view
(
request
):
return
render
(
request
,
'debug/render_test.html'
,
{
...
...
@@ -263,4 +263,4 @@ class Klass(object):
return
technical_500_response
(
request
,
*
exc_info
)
def
sensitive_method_view
(
request
):
return
Klass
()
.
method
(
request
)
\ No newline at end of file
return
Klass
()
.
method
(
request
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment