python类date()的实例源码

views.py 文件源码 项目:djangocms-concurrent-users 作者: Blueshoe 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def get(self, request, *args, **kwargs):
        _page = get_object_or_404(Page, pk=request.GET.get('page_id'))

        # release page for all users which did not update during the last timeframe
        PageIndicator.objects.filter(edited_on__lte=self.time_past, page=_page).delete()

        page_indicators = PageIndicator.objects.filter(edited_on__gte=self.time_past, page=_page)\
            .exclude(editor=request.user)

        response = {}
        if page_indicators.exists():
            response['conflict'] = True
            editing_user = page_indicators.first()
            response['concurrent_user'] = [editing_user.editor.username]
            # default behavior for concurrent users is blocking
            response['block_editing'] = getattr(settings, 'CONCURRENT_BLOCK_EDITING', BLOCK_EDITING_DEFAULT)

            response['message'] = _(u'Unfortunately you cannot edit this page at the moment: '
                                    u'user {user} is blocking it since {time}').format(
                    user=editing_user.editor,
                    time=_date(editing_user.started_editing, 'D, d. b, H:i'))
        else:
            response['conflict'] = False

        return JsonResponse(json.dumps(response), safe=False)
contrib_tags.py 文件源码 项目:a4-meinberlin 作者: liqd 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def html_date(value, displayfmt=None, datetimefmt='c', **kwargs):
    """Format a date and wrap it in a html <time> element.

    Additional html attributes may be provided as kwargs (e.g. 'class').

    Note: Converts the value to localtime as we loose the expects_localtime
    flag functionality by directly calling the date filter from django.
    """
    localtime_value = timezone.localtime(value)
    displaydate = defaultfilters.date(localtime_value, displayfmt)
    datetime = defaultfilters.date(localtime_value, datetimefmt)
    attribs = flatatt(kwargs)
    result = '<time %s datetime="%s">%s</time>' % (attribs,
                                                   datetime,
                                                   displaydate)
    return mark_safe(result)
formatting_filters.py 文件源码 项目:openbare 作者: openbare 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def format_date(date):
    """Format date string."""
    return defaultfilters.date(date, "j b Y")
humanize.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
humanize.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
humanize.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
models.py 文件源码 项目:mooder 作者: phith0n 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def generate_attachment_filename(instance, filename):
    filename, ext = os.path.splitext(filename)
    if ext not in ('.jpg', '.jpeg', '.png', '.bmp', '.gif', '.rar', '.gz', '.zip', '.7z', '.txt', '.pdf',
                   '.doc', '.docx', '.ppt', '.pptx', ):
        ext = '.attach'
    filename = "%s-%s%s" % (uuid4(), get_random_string(length=8), ext)

    tzinfo = timezone.get_current_timezone() if settings.USE_TZ else None
    date_dir = date(datetime.now(tz=tzinfo), 'Y/m')

    return "attachment/%s/%s" % (date_dir, filename)
models.py 文件源码 项目:mooder 作者: phith0n 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def generate_image_filename(instance, filename):
    filename, ext = os.path.splitext(filename)
    filename = "%s-%s%s" % (uuid4(), get_random_string(length=8), ext)

    tzinfo = timezone.get_current_timezone() if settings.USE_TZ else None
    date_dir = date(datetime.now(tz=tzinfo), 'Y/m/d')

    return "images/%s/%s" % (date_dir, filename)
models.py 文件源码 项目:pyconapac-2016 作者: pythonkr 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __unicode__(self):
        return _date(self.day, "Y-m-d (D)")
humanize.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
events.py 文件源码 项目:wagtail_room_booking 作者: Tamriel 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __str__(self):
        return ugettext('%(title)s: %(start)s - %(end)s') % {
            'title': self.title,
            'start': date(self.start, django_settings.DATE_FORMAT),
            'end': date(self.end, django_settings.DATE_FORMAT),
        }
events.py 文件源码 项目:wagtail_room_booking 作者: Tamriel 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_occurrence(self, date):
        if timezone.is_naive(date) and django_settings.USE_TZ:
            date = timezone.make_aware(date, timezone.utc)
        rule = self.get_rrule_object()
        if rule:
            next_occurrence = rule.after(date, inc=True)
        else:
            next_occurrence = self.start
        if next_occurrence == date:
            try:
                return Occurrence.objects.get(event=self, original_start=date)
            except Occurrence.DoesNotExist:
                return self._create_occurrence(next_occurrence)
events.py 文件源码 项目:wagtail_room_booking 作者: Tamriel 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __str__(self):
        return ugettext("%(start)s to %(end)s") % {
            'start': date(self.start, django_settings.DATE_FORMAT),
            'end': date(self.end, django_settings.DATE_FORMAT)
        }
periods.py 文件源码 项目:wagtail_room_booking 作者: Tamriel 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __str__(self):
        date_format = 'l, %s' % settings.DATE_FORMAT
        return ugettext('Week: %(start)s-%(end)s') % {
            'start': date_filter(self.start, date_format),
            'end': date_filter(self.end, date_format),
        }
periods.py 文件源码 项目:wagtail_room_booking 作者: Tamriel 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __str__(self):
        date_format = 'l, %s' % settings.DATE_FORMAT
        return ugettext('Day: %(start)s-%(end)s') % {
            'start': date_filter(self.start, date_format),
            'end': date_filter(self.end, date_format),
        }
humanize.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
humanize.py 文件源码 项目:DjangoBlog 作者: 0daybug 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
humanize.py 文件源码 项目:wanblog 作者: wanzifa 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
humanize.py 文件源码 项目:tabmaster 作者: NicolasMinghetti 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
humanize.py 文件源码 项目:trydjango18 作者: lucifer-yqh 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
humanize.py 文件源码 项目:trydjango18 作者: wei0104 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
humanize.py 文件源码 项目:ims 作者: ims-team 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
humanize.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day returns representing string. Otherwise, returns a string
    formatted according to settings.DATE_FORMAT.
    """
    try:
        tzinfo = getattr(value, 'tzinfo', None)
        value = date(value.year, value.month, value.day)
    except AttributeError:
        # Passed value wasn't a date object
        return value
    except ValueError:
        # Date arguments out of range
        return value
    today = datetime.now(tzinfo).date()
    delta = value - today
    if delta.days == 0:
        return _('today')
    elif delta.days == 1:
        return _('tomorrow')
    elif delta.days == -1:
        return _('yesterday')
    return defaultfilters.date(value, arg)


# This filter doesn't require expects_localtime=True because it deals properly
# with both naive and aware datetimes. Therefore avoid the cost of conversion.
movimento.py 文件源码 项目:djangoSIGE 作者: thiagopena 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def format_data_movimento(self):
        return '%s' % date(self.data_movimento, "d/m/Y")
vendas.py 文件源码 项目:djangoSIGE 作者: thiagopena 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def format_data_emissao(self):
        return '%s' % date(self.data_emissao, "d/m/Y")
vendas.py 文件源码 项目:djangoSIGE 作者: thiagopena 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def format_data_vencimento(self):
        return '%s' % date(self.data_vencimento, "d/m/Y")
vendas.py 文件源码 项目:djangoSIGE 作者: thiagopena 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def format_data_entrega(self):
        return '%s' % date(self.data_entrega, "d/m/Y")
compras.py 文件源码 项目:djangoSIGE 作者: thiagopena 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def format_data_emissao(self):
        return '%s' % date(self.data_emissao, "d/m/Y")
compras.py 文件源码 项目:djangoSIGE 作者: thiagopena 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def format_data_entrega(self):
        return '%s' % date(self.data_entrega, "d/m/Y")
nota_fiscal.py 文件源码 项目:djangoSIGE 作者: thiagopena 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def format_data_emissao(self):
        return '%s' % date(self.dhemi.date(), "d/m/Y")


问题


面经


文章

微信
公众号

扫码关注公众号