Python django.utils.formats 模块,time_format() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用django.utils.formats.time_format()

项目:api-django    作者:lafranceinsoumise    | 项目源码 | 文件源码
def get_display_date(self):
        tz = timezone.get_current_timezone()
        start_time = self.start_time.astimezone(tz)
        end_time = self.end_time.astimezone(tz)

        if start_time.date() == end_time.date():
            date = formats.date_format(start_time, 'DATE_FORMAT')
            return _("le {date}, de {start_hour} à {end_hour}").format(
                date=date,
                start_hour=formats.time_format(start_time, 'TIME_FORMAT'),
                end_hour=formats.time_format(end_time, 'TIME_FORMAT')
            )

        return _("du {start_date}, {start_time} au {end_date}, {end_time}").format(
            start_date=formats.date_format(start_time, 'DATE_FORMAT'),
            start_time=formats.date_format(start_time, 'TIME_FORMAT'),
            end_date=formats.date_format(end_time, 'DATE_FORMAT'),
            end_time=formats.date_format(end_time, 'TIME_FORMAT'),
        )
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def time(value, arg=None):
    """Formats a time according to the given format."""
    if value in (None, ''):
        return ''
    if arg is None:
        arg = settings.TIME_FORMAT
    try:
        return formats.time_format(value, arg)
    except AttributeError:
        try:
            return time_format(value, arg)
        except AttributeError:
            return ''
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def time(value, arg=None):
    """Formats a time according to the given format."""
    if value in (None, ''):
        return ''
    try:
        return formats.time_format(value, arg)
    except (AttributeError, TypeError):
        try:
            return time_format(value, arg)
        except (AttributeError, TypeError):
            return ''
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def time(value, arg=None):
    """Formats a time according to the given format."""
    if value in (None, ''):
        return ''
    try:
        return formats.time_format(value, arg)
    except (AttributeError, TypeError):
        try:
            return time_format(value, arg)
        except (AttributeError, TypeError):
            return ''
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def time(value, arg=None):
    """Formats a time according to the given format."""
    if value in (None, ''):
        return ''
    if arg is None:
        arg = settings.TIME_FORMAT
    try:
        return formats.time_format(value, arg)
    except AttributeError:
        try:
            return time_format(value, arg)
        except AttributeError:
            return ''
项目:lenuage    作者:laboiteproject    | 项目源码 | 文件源码
def update_data(self):
        # TODO: handle whole day events, display multiple events
        now = timezone.now()
        tonight = now.replace(hour=23, minute=59)

        self.dtstart = None
        self.summary = None

        calendar = Calendar()
        r = requests.get(self.ics_url)

        calendar = calendar.from_ical(r.text)

        for event in calendar.walk():
            if event.get('dtstart') and event.get('dtend'):
                dtstart = event.get('dtstart').dt
                dtend = event.get('dtend').dt
                if not isinstance(dtstart, datetime) or not isinstance(dtend, datetime):
                    dtstart = datetime.fromordinal(dtstart.toordinal())
                    dtend = datetime.fromordinal(dtend.toordinal())
                try:
                    dtstart = timezone.localtime(dtstart, timezone.utc)
                    dtend = timezone.localtime(dtend, timezone.utc)
                except ValueError:
                    dtstart = dtstart.replace(tzinfo=timezone.utc)
                    dtend = dtend.replace(tzinfo=timezone.utc)
                if now <= dtend <= tonight:
                    dtstart = timezone.localtime(dtstart, pytz.timezone('Europe/Paris'))
                    self.dtstart = formats.time_format(dtstart, 'TIME_FORMAT')
                    self.summary = str(unidecode.unidecode(event.get('summary')))
        self.save()
项目:lenuage    作者:laboiteproject    | 项目源码 | 文件源码
def update_data(self):
        now = timezone.localtime(timezone.now(), self.timezone)

        self.time = formats.time_format(now, 'TIME_FORMAT')
        self.date = formats.date_format(now, 'SHORT_DATE_FORMAT')
        self.save()
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def time(value, arg=None):
    """Formats a time according to the given format."""
    if value in (None, ''):
        return ''
    if arg is None:
        arg = settings.TIME_FORMAT
    try:
        return formats.time_format(value, arg)
    except AttributeError:
        try:
            return time_format(value, arg)
        except AttributeError:
            return ''
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def time(value, arg=None):
    """Formats a time according to the given format."""
    if value in (None, ''):
        return ''
    if arg is None:
        arg = settings.TIME_FORMAT
    try:
        return formats.time_format(value, arg)
    except AttributeError:
        try:
            return time_format(value, arg)
        except AttributeError:
            return ''