本文整理汇总了Python中django.conf.settings.TIME_ZONE属性的典型用法代码示例。如果您正苦于以下问题:Python settings.TIME_ZONE属性的具体用法?Python settings.TIME_ZONE怎么用?Python settings.TIME_ZONE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类django.conf.settings
的用法示例。
在下文中一共展示了settings.TIME_ZONE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calendar_data
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def calendar_data(request):
"""
AJAX JSON results for the calendar (rendered by dashboard.views.calendar)
"""
try:
st = iso8601.parse_date(request.GET['start'])
en = iso8601.parse_date(request.GET['end'])
except (KeyError, ValueError, iso8601.ParseError):
return NotFoundResponse(request, errormsg="Bad request")
user = get_object_or_404(Person, userid=request.user.username)
local_tz = pytz.timezone(settings.TIME_ZONE)
start = st - datetime.timedelta(days=1)
end = en + datetime.timedelta(days=1)
resp = HttpResponse(content_type="application/json")
events = _calendar_event_data(user, start, end, local_tz, dt_string=True, colour=True,
due_before=datetime.timedelta(minutes=1), due_after=datetime.timedelta(minutes=30))
json.dump(list(events), resp, indent=1)
return resp
示例2: _offering_meeting_time_data
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def _offering_meeting_time_data(request, offering):
"""
fullcalendar.js data for this offering's events
"""
try:
st = iso8601.parse_date(request.GET['start'])
en = iso8601.parse_date(request.GET['end'])
except (KeyError, ValueError, iso8601.ParseError):
return NotFoundResponse(request, errormsg="Bad request")
local_tz = pytz.timezone(settings.TIME_ZONE)
start = st - datetime.timedelta(days=1)
end = en + datetime.timedelta(days=1)
response = HttpResponse(content_type='application/json')
data = list(_offerings_calendar_data([offering], None, start, end, local_tz,
dt_string=True, colour=True, browse_titles=True))
json.dump(data, response, indent=1)
return response
示例3: ensure_defaults
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def ensure_defaults(self, alias):
"""
Puts the defaults into the settings dictionary for a given connection
where no settings is provided.
"""
try:
conn = self.databases[alias]
except KeyError:
raise ConnectionDoesNotExist("The connection %s doesn't exist" % alias)
conn.setdefault('ATOMIC_REQUESTS', False)
conn.setdefault('AUTOCOMMIT', True)
conn.setdefault('ENGINE', 'django.db.backends.dummy')
if conn['ENGINE'] == 'django.db.backends.' or not conn['ENGINE']:
conn['ENGINE'] = 'django.db.backends.dummy'
conn.setdefault('CONN_MAX_AGE', 0)
conn.setdefault('OPTIONS', {})
conn.setdefault('TIME_ZONE', 'UTC' if settings.USE_TZ else settings.TIME_ZONE)
for setting in ['NAME', 'USER', 'PASSWORD', 'HOST', 'PORT']:
conn.setdefault(setting, '')
示例4: migrate_activity_block_time
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def migrate_activity_block_time(apps, schema_editor):
"""
Convert hours to Django time zone.
Activity block time is in UTC but once it is converted
to time we actually want time as it would be represented
in settings.TIME_ZONE
"""
current_tz = timezone(settings.TIME_ZONE)
ActivityBlock = apps.get_model("tracking", "ActivityBlock")
for block in ActivityBlock.objects.all():
if block.to_datetime is not None:
block.to_datetime = block.to_datetime.astimezone(current_tz).replace(
tzinfo=utc
)
block.from_datetime = block.from_datetime.astimezone(current_tz).replace(
tzinfo=utc
)
block.save()
示例5: timezone
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def timezone(self):
"""
Time zone for datetimes stored as naive values in the database.
Return a tzinfo object or None.
This is only needed when time zone support is enabled and the database
doesn't support time zones. (When the database supports time zones,
the adapter handles aware datetimes so Django doesn't need to.)
"""
if not settings.USE_TZ:
return None
elif self.features.supports_timezones:
return None
elif self.settings_dict['TIME_ZONE'] is None:
return timezone.utc
else:
return pytz.timezone(self.settings_dict['TIME_ZONE'])
示例6: notify
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def notify(self, service, now):
msg = '{service.name}({service.value},{service.grace}) not send heartbeat at {now}'.format(
service=service,
now=now.in_timezone(settings.TIME_ZONE).to_datetime_string()
)
logger.warning(msg)
if not service.notify_to.strip():
logger.warning('service %s notify_to is empty', service.name)
return
notify_async(service.notify_to.strip().split(";"),
service.name,
service.tp,
service.value,
service.grace,
msg
)
示例7: process_at_service
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def process_at_service(self, service):
"""
当 当前时间 > at时,看[at, at + grace]之间是否有上报的数据
"""
latest_ping = self.get_last_ping(service)
if not latest_ping:
return
at = pendulum.parse(service.value, tz=settings.TIME_ZONE).in_timezone('UTC')
last_created = pendulum.instance(latest_ping.created)
now = pendulum.now(tz='UTC')
if now < at.add(minutes=int(service.grace)):
return
if last_created < at:
self.notify(service, now)
示例8: get_openrosa_headers
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def get_openrosa_headers(
self, request, location=True, content_length=True):
tz = pytz.timezone(settings.TIME_ZONE)
dt = datetime.now(tz).strftime('%a, %d %b %Y %H:%M:%S %Z')
data = {
'Date': dt,
'X-OpenRosa-Version': '1.0'
}
if content_length:
data['X-OpenRosa-Accept-Content-Length'] = DEFAULT_CONTENT_LENGTH
if location:
data['Location'] = request.build_absolute_uri(request.path)
return data
示例9: pootle_context
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def pootle_context(request):
"""Exposes settings to templates."""
# FIXME: maybe we should expose relevant settings only?
return {
"settings": {
"ZING_TITLE": settings.ZING_TITLE,
"ZING_SIGNUP_ENABLED": settings.ZING_SIGNUP_ENABLED,
"CACHE_TIMEOUT": CACHE_TIMEOUT,
"CAN_CONTACT": bool(settings.ZING_CONTACT_EMAIL.strip()),
"TZ": settings.TIME_ZONE,
"TZ_OFFSET": TZ_OFFSET,
"DEBUG": settings.DEBUG,
},
"ALL_LANGUAGES": Language.live.cached_dict(
translation.get_language(), request.user.is_superuser
),
"ALL_PROJECTS": Project.objects.cached_dict(request.user),
"SOCIAL_AUTH_PROVIDERS": _get_social_auth_providers(request),
}
示例10: to_date_datetime
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def to_date_datetime(date_or_datetime, hour, minute, second, microsecond):
mytz = pytz.timezone(settings.TIME_ZONE)
if isinstance(date_or_datetime, datetime.datetime):
if timezone.is_aware(date_or_datetime):
date = date_or_datetime.astimezone(mytz)
else:
date = mytz.localize(date_or_datetime)
elif isinstance(date_or_datetime, datetime.date):
date = date_or_datetime
return mytz.localize(
datetime.datetime(
date.year,
date.month,
date.day,
hour,
minute,
second,
microsecond,
)
)
示例11: timezone
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def timezone(self):
"""
Time zone for datetimes stored as naive values in the database.
Returns a tzinfo object or None.
This is only needed when time zone support is enabled and the database
doesn't support time zones. (When the database supports time zones,
the adapter handles aware datetimes so Django doesn't need to.)
"""
if not settings.USE_TZ:
return None
elif self.features.supports_timezones:
return None
elif self.settings_dict['TIME_ZONE'] is None:
return timezone.utc
else:
return pytz.timezone(self.settings_dict['TIME_ZONE'])
示例12: _update_item_status
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def _update_item_status(s_item: models.ScheduledOperation):
"""Update the status of the scheduled item.
:param s_item: Scheduled item
:return: Nothing
"""
now = datetime.now(pytz.timezone(settings.TIME_ZONE))
if s_item.frequency and (
not s_item.execute_until or now < s_item.execute_until
):
new_status = models.scheduler.STATUS_PENDING
else:
new_status = models.scheduler.STATUS_DONE
# Save the new status in the DB
models.ScheduledOperation.objects.filter(pk=s_item.id).update(
status=new_status)
s_item.refresh_from_db(fields=['status'])
if settings.DEBUG:
CELERY_LOGGER.info('Status set to %s', s_item.status)
示例13: get_default_timezone
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def get_default_timezone():
"""
Returns the default time zone as a tzinfo instance.
This is the time zone defined by settings.TIME_ZONE.
See also :func:`get_current_timezone`.
"""
global _localtime
if _localtime is None:
if isinstance(settings.TIME_ZONE, six.string_types) and pytz is not None:
_localtime = pytz.timezone(settings.TIME_ZONE)
else:
# This relies on os.environ['TZ'] being set to settings.TIME_ZONE.
_localtime = LocalTimezone()
return _localtime
# This function exists for consistency with get_current_timezone_name
示例14: ensure_defaults
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def ensure_defaults(self, alias):
"""
Puts the defaults into the settings dictionary for a given connection
where no settings is provided.
"""
try:
conn = self.databases[alias]
except KeyError:
raise ConnectionDoesNotExist("The connection %s doesn't exist" % alias)
conn.setdefault('ENGINE', 'django.db.backends.dummy')
if conn['ENGINE'] == 'django.db.backends.' or not conn['ENGINE']:
conn['ENGINE'] = 'django.db.backends.dummy'
conn.setdefault('OPTIONS', {})
conn.setdefault('TIME_ZONE', 'UTC' if settings.USE_TZ else settings.TIME_ZONE)
for setting in ['NAME', 'USER', 'PASSWORD', 'HOST', 'PORT']:
conn.setdefault(setting, '')
for setting in ['TEST_CHARSET', 'TEST_COLLATION', 'TEST_NAME', 'TEST_MIRROR']:
conn.setdefault(setting, None)
示例15: setUp
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import TIME_ZONE [as 别名]
def setUp(self):
self.super_user = User.objects.create_superuser(
'admin', 'admin@example.com', 'password'
)
timezone = pytz.timezone(settings.TIME_ZONE)
self.event = models.Event.objects.create(
targetamount=5,
datetime=today_noon,
timezone=timezone,
name='test event',
short='test',
)
self.rand = random.Random(None)
self.client.force_login(self.super_user)