Here are the examples of the python api django.template.defaultfilters.date taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
27 Examples
3
View Complete Implementation : tests.py
Copyright Apache License 2.0
Author : edisonlz
Copyright Apache License 2.0
Author : edisonlz
def test_naturalday(self):
today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)
tomorrow = today + datetime.timedelta(days=1)
someday = today - datetime.timedelta(days=10)
notdate = "I'm not a date value"
test_list = (today, yesterday, tomorrow, someday, notdate, None)
someday_result = defaultfilters.date(someday)
result_list = (_('today'), _('yesterday'), _('tomorrow'),
someday_result, "I'm not a date value", None)
self.humanize_tester(test_list, result_list, 'naturalday')
3
View Complete Implementation : contrib_tags.py
Copyright GNU Affero General Public License v3.0
Author : liqd
Copyright GNU Affero General Public License v3.0
Author : liqd
@register.simple_tag()
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. 'clast').
Note: Converts the value to localtime as we loose the expects_localtime
flag functionality by directly calling the date filter from django.
"""
if value:
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)
3
View Complete Implementation : contrib_tags.py
Copyright GNU Affero General Public License v3.0
Author : liqd
Copyright GNU Affero General Public License v3.0
Author : liqd
@register.simple_tag()
def html_date(value, displayfmt=None, datetimefmt='c', **kwargs):
if value:
"""Format a date and wrap it in a html <time> element.
Additional html attributes may be provided as kwargs (e.g. 'clast').
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)
3
View Complete Implementation : test_models.py
Copyright MIT License
Author : maykinmedia
Copyright MIT License
Author : maykinmedia
def test_get_message(self):
"""
Test the ``get_message`` method rendering a simple default log message.
"""
log = TimelineLog.log_from_request(self.request, self.article)
self.astertEqual(
log.get_message(),
'{0} - Anonymous user event on {1}.\n'.format(
date(log.timestamp, 'DATETIME_FORMAT'),
log.content_object
)
)
3
View Complete Implementation : sentry_helpers.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : NetEaseGame
Copyright BSD 3-Clause "New" or "Revised" License
Author : NetEaseGame
@register.filter
def date(dt, arg=None):
from django.template.defaultfilters import date
if not timezone.is_aware(dt):
dt = dt.replace(tzinfo=timezone.utc)
return date(dt, arg)
3
View Complete Implementation : sentry_helpers.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : NetEaseGame
Copyright BSD 3-Clause "New" or "Revised" License
Author : NetEaseGame
@register.simple_tag(takes_context=True)
def localized_datetime(context, dt, format='DATETIME_FORMAT'):
request = context['request']
timezone = getattr(request, 'timezone', None)
if not timezone:
timezone = pytz.timezone(settings.SENTRY_DEFAULT_TIME_ZONE)
dt = dt.astimezone(timezone)
return date(dt, format)
3
View Complete Implementation : models.py
Copyright GNU Lesser General Public License v3.0
Author : phith0n
Copyright GNU Lesser General Public License v3.0
Author : phith0n
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)
3
View Complete Implementation : models.py
Copyright GNU Lesser General Public License v3.0
Author : phith0n
Copyright GNU Lesser General Public License v3.0
Author : phith0n
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)
3
View Complete Implementation : date_and_time.py
Copyright GNU General Public License v3.0
Author : Uninett
Copyright GNU General Public License v3.0
Author : Uninett
@register.filter
def default_datetime(value):
"""Returns the date as represented by the default datetime format"""
try:
v = date(value, DATETIME_FORMAT)
except Exception:
return value
return v
0
View Complete Implementation : defaulttags.py
Copyright GNU General Public License v2.0
Author : blackye
Copyright GNU General Public License v2.0
Author : blackye
def render(self, context):
tzinfo = timezone.get_current_timezone() if settings.USE_TZ else None
return date(datetime.now(tz=tzinfo), self.format_string)