本文整理汇总了Python中corehq.util.timezones.conversions.ServerTime.strftime方法的典型用法代码示例。如果您正苦于以下问题:Python ServerTime.strftime方法的具体用法?Python ServerTime.strftime怎么用?Python ServerTime.strftime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.util.timezones.conversions.ServerTime
的用法示例。
在下文中一共展示了ServerTime.strftime方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: template_context
# 需要导入模块: from corehq.util.timezones.conversions import ServerTime [as 别名]
# 或者: from corehq.util.timezones.conversions.ServerTime import strftime [as 别名]
def template_context(self):
event = self.messaging_event
date = ServerTime(event.date).user_time(self.timezone).done()
return {
'messaging_event_date': date.strftime(SERVER_DATETIME_FORMAT),
'messaging_event_type': self.get_source_display(event, display_only=True),
}
示例2: _update_tech_issue_for_escalation
# 需要导入模块: from corehq.util.timezones.conversions import ServerTime [as 别名]
# 或者: from corehq.util.timezones.conversions.ServerTime import strftime [as 别名]
def _update_tech_issue_for_escalation(case, escalated_ticket_level):
today = ServerTime(datetime.utcnow()).user_time(pytz.timezone('Asia/Kolkata')).done().date()
return update_case(
case.domain,
case.case_id,
case_properties={
'ticket_level': escalated_ticket_level,
'change_in_level': '1',
'touch_case_date': today.strftime('%Y-%m-%d'),
},
close=False,
xmlns=AUTO_UPDATE_XMLNS,
device_id=__name__ + "._update_tech_issue_for_escalation",
)
示例3: _fmt_date
# 需要导入模块: from corehq.util.timezones.conversions import ServerTime [as 别名]
# 或者: from corehq.util.timezones.conversions.ServerTime import strftime [as 别名]
def _fmt_date(somedate):
time = ServerTime(somedate).user_time(self.timezone).done()
return time.strftime(SERVER_DATETIME_FORMAT)
示例4: OutboundDailyCounter
# 需要导入模块: from corehq.util.timezones.conversions import ServerTime [as 别名]
# 或者: from corehq.util.timezones.conversions.ServerTime import strftime [as 别名]
class OutboundDailyCounter(object):
def __init__(self, domain_object=None):
self.domain_object = domain_object
if domain_object:
self.date = ServerTime(datetime.utcnow()).user_time(domain_object.get_default_timezone()).done().date()
else:
self.date = datetime.utcnow().date()
self.key = 'outbound-daily-count-for-%s-%s' % (
domain_object.name if domain_object else '',
self.date.strftime('%Y-%m-%d')
)
# We need access to the raw redis client because calling incr on
# a django_redis RedisCache object raises an error if the key
# doesn't exist.
self.client = get_redis_client().client.get_client()
def increment(self):
# If the key doesn't exist, redis will set it to 0 and then increment.
value = self.client.incr(self.key)
# If it's the first time we're calling incr, set the key's expiration
if value == 1:
self.client.expire(self.key, 24 * 60 * 60)
return value
def decrement(self):
return self.client.decr(self.key)
@property
def current_usage(self):
return self.client.get(self.key) or 0
@property
def daily_limit(self):
if self.domain_object:
return self.domain_object.get_daily_outbound_sms_limit()
else:
# If the message isn't tied to a domain, still impose a limit.
# Outbound messages not tied to a domain can happen when unregistered
# contacts opt in or out from a gateway.
return 10000
def can_send_outbound_sms(self, queued_sms):
"""
Returns False if the outbound daily limit has been exceeded.
"""
value = self.increment()
if value > self.daily_limit:
# Delay processing by an hour so that in case the
# limit gets increased within the same day, we start
# processing the backlog right away.
self.decrement()
delay_processing(queued_sms, 60)
# Log the fact that we reached this limit
DailyOutboundSMSLimitReached.create_for_domain_and_date(
self.domain_object.name if self.domain_object else '',
self.date
)
return False
return True
示例5: server_to_user_time
# 需要导入模块: from corehq.util.timezones.conversions import ServerTime [as 别名]
# 或者: from corehq.util.timezones.conversions.ServerTime import strftime [as 别名]
def server_to_user_time(server_time, timezone):
user_time = ServerTime(server_time).user_time(timezone).done()
return user_time.strftime("%Y-%m-%d %H:%M")
示例6: format_timestamp
# 需要导入模块: from corehq.util.timezones.conversions import ServerTime [as 别名]
# 或者: from corehq.util.timezones.conversions.ServerTime import strftime [as 别名]
def format_timestamp(self, utc_timestamp):
ist_timestamp = ServerTime(utc_timestamp).user_time(self.timezone).done()
return ist_timestamp.strftime('%Y-%m-%d %H:%M:%S')