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


Python defaultfilters.date方法代码示例

本文整理汇总了Python中django.template.defaultfilters.date方法的典型用法代码示例。如果您正苦于以下问题:Python defaultfilters.date方法的具体用法?Python defaultfilters.date怎么用?Python defaultfilters.date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.template.defaultfilters的用法示例。


在下文中一共展示了defaultfilters.date方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _validator

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def _validator(self, value):
        """
        Validate the allowed_dates restrictions on the field.
        """
        allowed = self.config.get('allowed_dates', 'AL')
        today = datetime.date.today()
        if allowed == 'AL':
            pass
        elif allowed == 'LT' and value >= today:
            raise forms.ValidationError("The date must be before today.")
        elif allowed == 'LE' and value > today:
            raise forms.ValidationError("The date cannot be in the future.")
        elif allowed == 'GT' and value <= today:
            raise forms.ValidationError("The date must be after today.")
        elif allowed == 'GE' and value < today:
            raise forms.ValidationError("The date cannot be past.") 
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:other.py

示例2: test_render

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def test_render(self):
        expected_html = (
            '  <td>'
            '    <div class="media-left">'
            '       <img src="{thumbnail}"'
            '           class="thumb-60">'
            '    </div>'
            '    <div class="media-body resource-text">'
            '       <label for="file"><strong>Resource Name</strong></label>'
            '       <br>file.txt'
            '    </div>'
            '  </td>'
            '  <td class="hidden-xs hidden-sm">txt</td>'
            '  <td class="hidden-xs hidden-sm">'
            '      john<br>'
            '      John Lennon</td>'
            '  <td class="hidden-xs hidden-sm">{updated}</td>'
            '  <td class="hidden-xs hidden-sm">Attached to 1 other entity</td>'
        )
        widget = ResourceWidget(resource=self.resource)
        rendered = widget.render('file', True)
        assert expected_html.format(
            updated=date(self.resource.last_updated, 'N j, Y, P'),
            thumbnail=self.resource.thumbnail
        ) in rendered 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:27,代码来源:test_widgets.py

示例3: month

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def month(value):
    """
    Provides the month from a provided date as a string.

    This is used to work around a bug in the Spanish django month translations.
    See LEARNER-3859 for more details.

    Arguments:
        value (datetime): date to format

    Returns:
        string: A formatted version of the month
    """
    formatted = date(value, 'E')

    language = get_language()
    if language and language.split('-')[0].lower() == 'es':
        return formatted.lower()

    return formatted 
开发者ID:edx,项目名称:credentials,代码行数:22,代码来源:html.py

示例4: relative_date

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def relative_date(value):
    if value in ('', None):
        return ''

    current = timezone.now()
    
    if (current - value) > timedelta(days=1):
        return date(value, "SHORT_DATETIME_FORMAT")
        
    return naturaltime(value) 
开发者ID:fpsw,项目名称:Servo,代码行数:12,代码来源:servo_tags.py

示例5: __unicode__

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def __unicode__(self):
        return _date(self.day, "Y-m-d (D)") 
开发者ID:pythonkr,项目名称:pyconkr-2015,代码行数:4,代码来源:models.py

示例6: make_entry_field

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def make_entry_field(self, fieldsubmission=None):
        c = forms.DateField(required=self.config['required'],
            label=self.config['label'],
            validators=[self._validator],
            help_text=self.config['help_text'])
        
        c.widget.attrs['class'] = 'date-input' # a JS chunk uses the class to turn on the datepicker.
        
        if fieldsubmission:
            c.initial = fieldsubmission.data['info']

        return c 
开发者ID:sfu-fas,项目名称:coursys,代码行数:14,代码来源:other.py

示例7: _to_text

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def _to_text(self, fieldsubmission=None, format=settings.DATE_FORMAT):
        if fieldsubmission.data['info']:
            d = datetime.datetime.strptime(fieldsubmission.data['info'], '%Y-%m-%d').date()
            return escape(defaultfilters.date(d, format))
        else:
            return 'not entered' 
开发者ID:sfu-fas,项目名称:coursys,代码行数:8,代码来源:other.py

示例8: timestamp_to_string

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def timestamp_to_string(ts):
    return django_date(
        datetime.datetime.fromtimestamp(int(ts)),
        'SHORT_DATETIME_FORMAT') 
开发者ID:openstack,项目名称:freezer-web-ui,代码行数:6,代码来源:utils.py

示例9: naturalday

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
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. 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:30,代码来源:humanize.py

示例10: format_data_movimento

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def format_data_movimento(self):
        return '%s' % date(self.data_movimento, "d/m/Y") 
开发者ID:thiagopena,项目名称:djangoSIGE,代码行数:4,代码来源:movimento.py

示例11: format_data_emissao

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def format_data_emissao(self):
        return '%s' % date(self.data_emissao, "d/m/Y") 
开发者ID:thiagopena,项目名称:djangoSIGE,代码行数:4,代码来源:compras.py

示例12: format_data_vencimento

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def format_data_vencimento(self):
        return '%s' % date(self.data_vencimento, "d/m/Y") 
开发者ID:thiagopena,项目名称:djangoSIGE,代码行数:4,代码来源:compras.py

示例13: format_data_entrega

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def format_data_entrega(self):
        return '%s' % date(self.data_entrega, "d/m/Y") 
开发者ID:thiagopena,项目名称:djangoSIGE,代码行数:4,代码来源:compras.py

示例14: format_data_emissao

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def format_data_emissao(self):
        return '%s' % date(self.dhemi.date(), "d/m/Y") 
开发者ID:thiagopena,项目名称:djangoSIGE,代码行数:4,代码来源:nota_fiscal.py

示例15: naturalday

# 需要导入模块: from django.template import defaultfilters [as 别名]
# 或者: from django.template.defaultfilters import date [as 别名]
def naturalday(value, arg=None):
    """
    For date values that are tomorrow, today or yesterday compared to
    present day return representing string. Otherwise, return 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. 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:30,代码来源:humanize.py


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