当前位置: 首页>>代码示例>>Python>>正文


Python timesince.timesince方法代码示例

本文整理汇总了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 
开发者ID:zulip,项目名称:zulip,代码行数:25,代码来源:__init__.py

示例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) 
开发者ID:v1k45,项目名称:django-notify-x,代码行数:21,代码来源:models.py

示例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)} 
开发者ID:fpsw,项目名称:Servo,代码行数:33,代码来源:order.py

示例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 '' 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:defaultfilters.py

示例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 '' 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:7,代码来源:panels.py

示例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) 
开发者ID:rapidpro,项目名称:casepro,代码行数:33,代码来源:views.py

示例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 '' 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:12,代码来源:defaultfilters.py

示例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 
开发者ID:zulip,项目名称:zulip,代码行数:34,代码来源:views.py

示例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) 
开发者ID:fresearchgroup,项目名称:Collaboration-System,代码行数:9,代码来源:models.py

示例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" 
开发者ID:codingforentrepreneurs,项目名称:Django-Models-Unleashed,代码行数:17,代码来源:models.py

示例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) 
开发者ID:HackAssistant,项目名称:registration,代码行数:6,代码来源:admin.py

示例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} 
开发者ID:helfertool,项目名称:helfertool,代码行数:16,代码来源:lastlogin.py

示例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') 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_timesince.py

示例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') 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_timesince.py

示例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') 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:test_timesince.py


注:本文中的django.utils.timesince.timesince方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。