本文整理匯總了Python中django.utils.timesince.timesince方法的典型用法代碼示例。如果您正苦於以下問題:Python timesince.timesince方法的具體用法?Python timesince.timesince怎麽用?Python timesince.timesince使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.utils.timesince
的用法示例。
在下文中一共展示了timesince.timesince方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: environment
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def environment(**options: Any) -> Environment:
env = Environment(**options)
env.globals.update({
'default_page_params': {
'debug_mode': False,
'webpack_public_path': staticfiles_storage.url(
settings.WEBPACK_LOADER['DEFAULT']['BUNDLE_DIR_NAME'],
),
},
'static': staticfiles_storage.url,
'url': reverse,
'render_markdown_path': render_markdown_path,
})
env.install_gettext_translations(translation, True)
env.filters['slugify'] = slugify
env.filters['pluralize'] = pluralize
env.filters['display_list'] = display_list
env.filters['device_action'] = device_action
env.filters['timesince'] = timesince
return env
示例2: __str__
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def __str__(self):
ctx = {
'actor': self.actor or self.actor_text,
'verb': self.verb,
'description': self.description,
'target': self.target or self.target_text,
'obj': self.obj or self.obj_text,
'at': timesince(self.created),
}
if ctx['actor']:
if not ctx['target']:
return _("{actor} {verb} {at} ago").format(**ctx)
elif not ctx['obj']:
return _("{actor} {verb} on {target} {at} ago").format(**ctx)
elif ctx['obj']:
return _(
"{actor} {verb} {obj} on {target} {at} ago").format(**ctx)
return _("{description} -- {at} ago").format(**ctx)
示例3: get_title
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def get_title(self):
"""
Returns a human-readable title for this order, based on various criteria
"""
from django.utils.timesince import timesince
now = timezone.now()
moment_seconds = 120
if self.closed_at:
if (now - self.closed_at).seconds < moment_seconds:
return _("Closed a moment ago")
return _(u"Closed for %(time)s") % {'time': timesince(self.closed_at)}
if self.status and self.status_started_at is not None:
if (now - self.status_started_at).seconds < moment_seconds:
return _(u"%s a moment ago") % self.status.status.title
delta = timesince(self.status_started_at)
d = {'status': self.status.status.title, 'time': delta}
return _("%(status)s for %(time)s" % d)
if self.user is None:
if (now - self.created_at).seconds < moment_seconds:
return _("Created a moment ago")
return _("Unassigned for %(delta)s") % {'delta': timesince(self.created_at)}
if self.in_progress():
if (now - self.started_at).seconds < moment_seconds:
return _("Started a moment ago")
return _("Open for %(delta)s") % {'delta': timesince(self.started_at)}
示例4: timesince_filter
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def timesince_filter(value, arg=None):
"""Formats a date as the time since that date (i.e. "4 days, 6 hours")."""
if not value:
return ''
try:
if arg:
return timesince(value, arg)
return timesince(value)
except (ValueError, TypeError):
return ''
示例5: nav_subtitle
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def nav_subtitle(self):
if self.enabled and self.last_invalidation is not None:
return (_('Last invalidation: %s')
% timesince(self.last_invalidation))
return ''
示例6: get
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def get(self, request, *args, **kwargs):
org = self.request.org
user = self.request.user
page = int(self.request.GET.get("page", 1))
search = self.derive_search()
items = Outgoing.search_replies(org, user, search)
paginator = LazyPaginator(items, 50)
outgoing = paginator.page(page)
has_more = paginator.num_pages > page
def as_json(msg):
delay = (msg.created_on - msg.reply_to.created_on).total_seconds()
obj = msg.as_json()
obj.update(
{
"reply_to": {
"text": msg.reply_to.text,
"flagged": msg.reply_to.is_flagged,
"labels": [l.as_json(full=False) for l in msg.reply_to.labels.all()],
},
"response": {
"delay": timesince(msg.reply_to.created_on, now=msg.created_on),
"warning": delay > RESPONSE_DELAY_WARN_SECONDS,
},
}
)
return obj
return JsonResponse({"results": [as_json(o) for o in outgoing], "has_more": has_more}, encoder=JSONEncoder)
示例7: timesince_filter
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def timesince_filter(value, arg=None):
"""Format a date as the time since that date (i.e. "4 days, 6 hours")."""
if not value:
return ''
try:
if arg:
return timesince(value, arg)
return timesince(value)
except (ValueError, TypeError):
return ''
示例8: get_confirmations
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def get_confirmations(types: List[int], object_ids: List[int],
hostname: Optional[str]=None) -> List[Dict[str, Any]]:
lowest_datetime = timezone_now() - timedelta(days=30)
confirmations = Confirmation.objects.filter(type__in=types, object_id__in=object_ids,
date_sent__gte=lowest_datetime)
confirmation_dicts = []
for confirmation in confirmations:
realm = confirmation.realm
content_object = confirmation.content_object
type = confirmation.type
days_to_activate = _properties[type].validity_in_days
expiry_date = confirmation.date_sent + timedelta(days=days_to_activate)
if hasattr(content_object, "status"):
if content_object.status == STATUS_ACTIVE:
link_status = "Link has been clicked"
else:
link_status = "Link has never been clicked"
else:
link_status = ""
if timezone_now() < expiry_date:
expires_in = timesince(confirmation.date_sent, expiry_date)
else:
expires_in = "Expired"
url = confirmation_url(confirmation.confirmation_key, realm, type)
confirmation_dicts.append({"object": confirmation.content_object,
"url": url, "type": type, "link_status": link_status,
"expires_in": expires_in})
return confirmation_dicts
示例9: timesince
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def timesince(self, now=None):
"""
Shortcut for the ``django.utils.timesince.timesince`` function of the
current timestamp.
"""
from django.utils.timesince import timesince as timesince_
return timesince_(self.timestamp, now)
示例10: age
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def age(self):
if self.publish == 'publish':
now = datetime.now()
publish_time = datetime.combine(
self.publish_date,
datetime.now().min.time()
)
try:
difference = now - publish_time
except:
return "Unknown"
if difference <= timedelta(minutes=1):
return 'just now'
return '{time} ago'.format(time= timesince(publish_time).split(', ')[0])
return "Not published"
示例11: status_last_updated
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def status_last_updated(self, app):
if not app.status_update_date:
return None
return timesince(app.status_update_date)
示例12: lastlogin
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def lastlogin(user):
if not user.last_login:
return _("Never")
login_date = _to_date(user.last_login)
now_date = _to_date(datetime.datetime.now(utc if is_aware(login_date) else None))
if login_date == now_date:
return _("Today")
elif login_date == now_date - datetime.timedelta(days=1):
return _("Yesterday")
else:
last_login_ago = timesince(login_date, now_date)
return _("%(last_login_ago)s ago") % {"last_login_ago": last_login_ago}
示例13: test_equal_datetimes
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def test_equal_datetimes(self):
""" equal datetimes. """
# NOTE: \xa0 avoids wrapping between value and unit
self.assertEqual(timesince(self.t, self.t), '0\xa0minutes')
示例14: test_ignore_microseconds_and_seconds
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def test_ignore_microseconds_and_seconds(self):
""" Microseconds and seconds are ignored. """
self.assertEqual(timesince(self.t, self.t + self.onemicrosecond), '0\xa0minutes')
self.assertEqual(timesince(self.t, self.t + self.onesecond), '0\xa0minutes')
示例15: test_other_units
# 需要導入模塊: from django.utils import timesince [as 別名]
# 或者: from django.utils.timesince import timesince [as 別名]
def test_other_units(self):
""" Test other units. """
self.assertEqual(timesince(self.t, self.t + self.oneminute), '1\xa0minute')
self.assertEqual(timesince(self.t, self.t + self.onehour), '1\xa0hour')
self.assertEqual(timesince(self.t, self.t + self.oneday), '1\xa0day')
self.assertEqual(timesince(self.t, self.t + self.oneweek), '1\xa0week')
self.assertEqual(timesince(self.t, self.t + self.onemonth), '1\xa0month')
self.assertEqual(timesince(self.t, self.t + self.oneyear), '1\xa0year')