當前位置: 首頁>>代碼示例>>Python>>正文


Python timezone.deactivate方法代碼示例

本文整理匯總了Python中django.utils.timezone.deactivate方法的典型用法代碼示例。如果您正苦於以下問題:Python timezone.deactivate方法的具體用法?Python timezone.deactivate怎麽用?Python timezone.deactivate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.utils.timezone的用法示例。


在下文中一共展示了timezone.deactivate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def __call__(self, request):
        # Code to be executed for each request before
        # the view (and later middleware) are called.

        response = self.get_response(request)

        # Code to be executed for each request/response after
        # the view is called.

        tzname = request.session.get('django_timezone')

        if not tzname:
            # Get it from the Account. Should hopefully happens once per session
            user = request.user
            if user and not user.is_anonymous:
                tzname = user.time_zone
                if tzname:
                    request.session['django_timezone'] = tzname

        if tzname:
            timezone.activate(pytz.timezone(tzname))
        else:
            timezone.deactivate()

        return response 
開發者ID:dkarchmer,項目名稱:django-aws-template,代碼行數:27,代碼來源:timezoneMiddleware.py

示例2: __call__

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def __call__(self, request):
        if "HTTP_X_FORWARDED_FOR" in request.META:
            request.META["HTTP_X_PROXY_REMOTE_ADDR"] = request.META["REMOTE_ADDR"]
            parts = request.META["HTTP_X_FORWARDED_FOR"].split(",", 1)
            request.META["REMOTE_ADDR"] = parts[0]
        ip = request.META["REMOTE_ADDR"]
        g = GeoIP2()
        try:
            ip_response = g.city(ip)
            time_zone = ip_response['time_zone']
        except AddressNotFoundError:
            time_zone = None
        if time_zone:
            timezone_object = pytz.timezone(time_zone)
            timezone.activate(timezone_object)
        else:
            timezone.deactivate()
        return self.get_response(request) 
開發者ID:meneses-pt,項目名稱:goals.zone,代碼行數:20,代碼來源:timezone.py

示例3: test_override

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def test_override(self):
        default = timezone.get_default_timezone()
        try:
            timezone.activate(ICT)

            with timezone.override(EAT):
                self.assertIs(EAT, timezone.get_current_timezone())
            self.assertIs(ICT, timezone.get_current_timezone())

            with timezone.override(None):
                self.assertIs(default, timezone.get_current_timezone())
            self.assertIs(ICT, timezone.get_current_timezone())

            timezone.deactivate()

            with timezone.override(EAT):
                self.assertIs(EAT, timezone.get_current_timezone())
            self.assertIs(default, timezone.get_current_timezone())

            with timezone.override(None):
                self.assertIs(default, timezone.get_current_timezone())
            self.assertIs(default, timezone.get_current_timezone())
        finally:
            timezone.deactivate() 
開發者ID:nesdis,項目名稱:djongo,代碼行數:26,代碼來源:test_timezone.py

示例4: process_request

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def process_request(self, request):
        tzname = request.session.get('django_timezone')
        if tzname:
            timezone.activate(pytz.timezone(tzname))
        else:
            timezone.deactivate() 
開發者ID:fpsw,項目名稱:Servo,代碼行數:8,代碼來源:middleware.py

示例5: tearDown

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def tearDown(self):
        timezone.deactivate() 
開發者ID:charettes,項目名稱:django-sundial,代碼行數:4,代碼來源:test_middleware.py

示例6: process_request

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def process_request(self, request):
        if request.user.is_authenticated():
            tz = request.session.get('django_timezone',
                                     default=request.user.profile.time_zone) or settings.TIME_ZONE
            timezone.activate(tz)
        else:
            timezone.deactivate() 
開發者ID:znick,項目名稱:anytask,代碼行數:9,代碼來源:timezone_middleware.py

示例7: get_message

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def get_message(user, user_type, issue, events, from_email, domain):
    user_profile = user.profile

    if not user_profile.send_my_own_events:
        events = events.exclude(author_id=user.id)

    if not events:
        return ()

    lang = user_profile.language
    translation.activate(lang)
    timezone.activate(user_profile.time_zone)

    subject = (_(u'kurs') + u': {0} | ' + _(u'zadacha') + u': {1} | ' + _(u'student') + u': {2} {3}'). \
        format(issue.task.course.name, issue.task.get_title(lang), issue.student.last_name, issue.student.first_name)

    context = {
        "user": user,
        "domain": domain,
        "title": subject,
        "user_type": user_type,
        "issue": issue,
        "events": events,
        "STATIC_URL": settings.STATIC_URL,
    }

    plain_text = render_to_string('email_issue_notification.txt', context)
    html = render_to_string('email_issue_notification.html', context)
    translation.deactivate()
    timezone.deactivate()

    return subject, plain_text, html, from_email, [user.email] 
開發者ID:znick,項目名稱:anytask,代碼行數:34,代碼來源:send_notifications.py

示例8: process_request

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def process_request(self, request):
        if request.user.is_authenticated():
            timezone.activate(request.user.timezone)
        else:
            timezone.deactivate() 
開發者ID:whitesmith,項目名稱:hawkpost,代碼行數:7,代碼來源:middleware.py

示例9: __call__

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def __call__(self, request):
        if request.user.is_authenticated:
            if hasattr(request.user, 'settings'):
                settings = request.user.settings
            else:
                from palanaeum.models import UserSettings
                settings = UserSettings.objects.create(user=request.user)
            tzname = settings.timezone
            timezone.activate(pytz.timezone(tzname))
        else:
            timezone.deactivate()

        response = self.get_response(request)

        return response 
開發者ID:Palanaeum,項目名稱:palanaeum,代碼行數:17,代碼來源:middleware.py

示例10: setUp

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def setUp(self):
        timezone.deactivate()
        utils.cache_clear()
        self.user = utils.create_user() 
開發者ID:nitely,項目名稱:Spirit,代碼行數:6,代碼來源:tests.py

示例11: test_timezone

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def test_timezone(self):
        """
        Should activate the user timezone
        """
        timezone.deactivate()
        utils.login(self)
        req = RequestFactory().get('/')
        req.user = self.user
        time_zone = 'America/Argentina/Buenos_Aires'
        self.user.st.timezone = time_zone

        self.assertEqual(timezone.get_current_timezone().zone, 'UTC')
        middleware.TimezoneMiddleware().process_request(req)
        self.assertEqual(timezone.get_current_timezone().zone, time_zone) 
開發者ID:nitely,項目名稱:Spirit,代碼行數:16,代碼來源:tests.py

示例12: test_timezone_bad_tz

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def test_timezone_bad_tz(self):
        timezone.deactivate()
        utils.login(self)
        req = RequestFactory().get('/')
        req.user = self.user
        self.user.st.timezone = 'badtimezone'

        time_zone = 'America/Argentina/Buenos_Aires'
        timezone.activate(time_zone)
        self.assertEqual(timezone.get_current_timezone().zone, time_zone)
        middleware.TimezoneMiddleware().process_request(req)
        self.assertEqual(timezone.get_current_timezone().zone, 'UTC') 
開發者ID:nitely,項目名稱:Spirit,代碼行數:14,代碼來源:tests.py

示例13: test_timezone_anonymous_user

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def test_timezone_anonymous_user(self):
        class AnonymUserMock(object):
            @property
            def is_authenticated(self):
                return False

        timezone.deactivate()
        req = RequestFactory().get('/')
        req.user = AnonymUserMock()

        time_zone = 'America/Argentina/Buenos_Aires'
        timezone.activate(time_zone)
        self.assertEqual(timezone.get_current_timezone().zone, time_zone)
        middleware.TimezoneMiddleware().process_request(req)
        self.assertEqual(timezone.get_current_timezone().zone, 'UTC') 
開發者ID:nitely,項目名稱:Spirit,代碼行數:17,代碼來源:tests.py

示例14: process_request

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def process_request(self, request):
        if not request.user.is_authenticated:
            timezone.deactivate()
            return

        try:
            timezone.activate(request.user.st.timezone)
        except pytz.exceptions.UnknownTimeZoneError:
            timezone.deactivate()
            logger.error(
                '%s is not a valid timezone.', request.user.st.timezone) 
開發者ID:nitely,項目名稱:Spirit,代碼行數:13,代碼來源:middleware.py

示例15: process_request

# 需要導入模塊: from django.utils import timezone [as 別名]
# 或者: from django.utils.timezone import deactivate [as 別名]
def process_request(self, request):
        if request.user.is_authenticated:
            if request.user.timezone is not None:
                timezone.activate(pytz.timezone(request.user.timezone))
            else:
                timezone.activate(pytz.timezone('UTC'))
        else:
            timezone.deactivate() 
開發者ID:iguana-project,項目名稱:iguana,代碼行數:10,代碼來源:timezone_middleware.py


注:本文中的django.utils.timezone.deactivate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。