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
032c0916
Kaydet (Commit)
032c0916
authored
Agu 30, 2014
tarafından
Thomas Chaumeny
Kaydeden (comit)
Aymeric Augustin
Agu 31, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #23388 -- Made django.utils.timezone.override usable as a decorator
üst
8b6cb9d0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
1 deletion
+36
-1
timezone.py
django/utils/timezone.py
+2
-1
utils.txt
docs/ref/utils.txt
+4
-0
test_timezone.py
tests/utils_tests/test_timezone.py
+30
-0
No files found.
django/utils/timezone.py
Dosyayı görüntüle @
032c0916
...
...
@@ -16,6 +16,7 @@ except ImportError:
from
django.conf
import
settings
from
django.utils
import
six
from
django.utils.decorators
import
ContextDecorator
__all__
=
[
'utc'
,
'get_fixed_timezone'
,
...
...
@@ -248,7 +249,7 @@ def deactivate():
del
_active
.
value
class
override
(
object
):
class
override
(
ContextDecorator
):
"""
Temporarily set the time zone for the current thread.
...
...
docs/ref/utils.txt
Dosyayı görüntüle @
032c0916
...
...
@@ -901,6 +901,10 @@ appropriate entities.
``None``, the :ref:`current time zone <default-current-time-zone>` is unset
on entry with :func:`deactivate()` instead.
.. versionchanged:: 1.8
``override`` is now usable as a function decorator.
.. function:: localtime(value, timezone=None)
Converts an aware :class:`~datetime.datetime` to a different time zone,
...
...
tests/utils_tests/test_timezone.py
Dosyayı görüntüle @
032c0916
...
...
@@ -71,6 +71,36 @@ class TimezoneTests(unittest.TestCase):
finally
:
timezone
.
deactivate
()
def
test_override_decorator
(
self
):
default
=
timezone
.
get_default_timezone
()
@timezone.override
(
EAT
)
def
func_tz_eat
():
self
.
assertIs
(
EAT
,
timezone
.
get_current_timezone
())
@timezone.override
(
None
)
def
func_tz_none
():
self
.
assertIs
(
default
,
timezone
.
get_current_timezone
())
try
:
timezone
.
activate
(
ICT
)
func_tz_eat
()
self
.
assertIs
(
ICT
,
timezone
.
get_current_timezone
())
func_tz_none
()
self
.
assertIs
(
ICT
,
timezone
.
get_current_timezone
())
timezone
.
deactivate
()
func_tz_eat
()
self
.
assertIs
(
default
,
timezone
.
get_current_timezone
())
func_tz_none
()
self
.
assertIs
(
default
,
timezone
.
get_current_timezone
())
finally
:
timezone
.
deactivate
()
def
test_copy
(
self
):
self
.
assertIsInstance
(
copy
.
copy
(
timezone
.
UTC
()),
timezone
.
UTC
)
self
.
assertIsInstance
(
copy
.
copy
(
timezone
.
LocalTimezone
()),
timezone
.
LocalTimezone
)
...
...
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