本文整理匯總了Python中django.utils.formats.date_format方法的典型用法代碼示例。如果您正苦於以下問題:Python formats.date_format方法的具體用法?Python formats.date_format怎麽用?Python formats.date_format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.utils.formats
的用法示例。
在下文中一共展示了formats.date_format方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_community_landing_pending_after_contribution_opens
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def test_community_landing_pending_after_contribution_opens(self):
"""
This tests that the initial application results.
The applicant is approved.
The round is in the contribution period.
They should be able to see projects on the community landing page.
"""
project = self.setup_approved_project_approved_community('contributions_open')
applicant = factories.ApplicantApprovalFactory(approval_status=models.ApprovalStatus.PENDING, application_round=project.project_round.participating_round)
self.client.force_login(applicant.applicant.account)
response = self.client.get(reverse('community-landing', kwargs={'round_slug': project.project_round.participating_round.slug, 'community_slug': project.project_round.community.slug}))
self.assertEqual(response.status_code, 200)
self.assertNotContains(response,
'<p>If you are an Outreachy applicant, this information will be available once the Outreachy contribution period starts on {} at 4pm UTC. You can sign up for an email notification when the round opens by <a href="https://lists.outreachy.org/cgi-bin/mailman/listinfo/announce">subscribing to the Outreachy announcements mailing list</a>.</p>'.format(date_format(project.project_round.participating_round.contributions_open)),
html=True)
self.assertNotContains(response, '<h1>Outreachy Internships with Debian</h1>', html=True)
self.assertNotContains(response, '<h1>Open Projects</h1>', html=True)
self.assertNotContains(response, '<hr id="{}">'.format(project.slug), html=True)
self.assertNotContains(response, '<h2>{}</h2>'.format(project.short_title), html=True)
示例2: test_community_landing_approved_after_contribution_opens
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def test_community_landing_approved_after_contribution_opens(self):
"""
This tests that the initial application results.
The applicant is approved.
The round is in the contribution period.
They should be able to see projects on the community landing page.
"""
project = self.setup_approved_project_approved_community('contributions_open')
applicant = factories.ApplicantApprovalFactory(approval_status=models.ApprovalStatus.APPROVED, application_round=project.project_round.participating_round)
self.client.force_login(applicant.applicant.account)
response = self.client.get(reverse('community-landing', kwargs={'round_slug': project.project_round.participating_round.slug, 'community_slug': project.project_round.community.slug}))
self.assertEqual(response.status_code, 200)
self.assertNotContains(response,
'<p>If you are an Outreachy applicant, this information will be available once the Outreachy contribution period starts on {} at 4pm UTC. You can sign up for an email notification when the round opens by <a href="https://lists.outreachy.org/cgi-bin/mailman/listinfo/announce">subscribing to the Outreachy announcements mailing list</a>.</p>'.format(date_format(project.project_round.participating_round.contributions_open)),
html=True)
self.assertContains(response, '<h1>Outreachy Internships with Debian</h1>', html=True)
self.assertContains(response, '<h1>Open Projects</h1>', html=True)
self.assertContains(response, '<hr id="{}">'.format(project.slug), html=True)
self.assertContains(response, '<h2>{}</h2>'.format(project.short_title), html=True)
# ----- contribution recording page tests ----- #
示例3: render_email
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def render_email(self, form):
content = []
cleaned_data = form.cleaned_data
for field in form:
if field.name not in cleaned_data:
continue
value = cleaned_data.get(field.name)
if isinstance(value, list):
value = ', '.join(value)
# Format dates and datetimes with SHORT_DATE(TIME)_FORMAT
if isinstance(value, datetime.datetime):
value = date_format(value, settings.SHORT_DATETIME_FORMAT)
elif isinstance(value, datetime.date):
value = date_format(value, settings.SHORT_DATE_FORMAT)
content.append('{}: {}'.format(field.label, value))
return '\n'.join(content)
示例4: format_datetime
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def format_datetime(dt, include_time=True):
"""
Here we adopt the following rule:
1) format date according to active localization
2) append time in military format
"""
if dt is None:
return ''
if isinstance(dt, datetime.datetime):
try:
dt = timezone.localtime(dt)
except:
local_tz = pytz.timezone(getattr(settings, 'TIME_ZONE', 'UTC'))
dt = local_tz.localize(dt)
else:
assert isinstance(dt, datetime.date)
include_time = False
use_l10n = getattr(settings, 'USE_L10N', False)
text = formats.date_format(dt, use_l10n=use_l10n, format='SHORT_DATE_FORMAT')
if include_time:
text += dt.strftime(' %H:%M:%S')
return text
示例5: __init__
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def __init__(self, *args, **kwargs):
self.job = kwargs.pop('job')
super(JobDuplicateDayForm, self).__init__(*args, **kwargs)
# get a list of all days where a shifts begins
day_with_shifts = []
for shift in self.job.shift_set.all():
day = shift.date()
if day not in day_with_shifts:
day_with_shifts.append(day)
# and set choices for field
old_date_choices = []
for day in sorted(day_with_shifts):
day_str = str(day)
day_localized = formats.date_format(day, "SHORT_DATE_FORMAT")
old_date_choices.append((day_str, day_localized))
self.fields['old_date'].choices = old_date_choices
示例6: dateShortFormat
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def dateShortFormat(when):
"""
Short version of the date when, e.g. 14 April 2017
Uses the format given by JOYOUS_DATE_SHORT_FORMAT if that is set, or otherwise
the standard Django date format.
"""
retval = ""
if when is not None:
formatStr = getattr(settings, 'JOYOUS_DATE_SHORT_FORMAT', None) # e.g. "j F Y"
if formatStr:
retval = _Formatter(when).format(formatStr)
else:
retval = formats.date_format(when, "SHORT_DATE_FORMAT")
return retval.strip()
# ------------------------------------------------------------------------------
示例7: test_user_page_subscription_lite
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def test_user_page_subscription_lite(self):
image = Generators.image()
image.user = self.user
image.save()
us = Generators.premium_subscription(self.user, "AstroBin Lite")
self.client.login(username='user', password='password')
response = self.client.get(reverse('user_page', args=('user',)))
self.assertContains(response, "<h4>Subscription</h4>", html=True)
self.assertContains(response, "<strong data-test='subscription-type'>AstroBin Lite</strong>", html=True)
self.assertContains(
response,
"<strong data-test='expiration-date'>" +
formats.date_format(us.expires, "SHORT_DATE_FORMAT") +
"</strong>",
html=True)
self.assertContains(response, "<strong data-test='images-used'>0 / 123</strong>", html=True)
self.client.logout()
us.delete()
image.delete()
示例8: test_user_page_subscription_lite_2020
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def test_user_page_subscription_lite_2020(self):
image = Generators.image()
image.user = self.user
image.save()
us = Generators.premium_subscription(self.user, "AstroBin Lite 2020+")
self.client.login(username='user', password='password')
response = self.client.get(reverse('user_page', args=('user',)))
self.assertContains(response, "<h4>Subscription</h4>", html=True)
self.assertContains(response, "<strong data-test='subscription-type'>AstroBin Lite</strong>", html=True)
self.assertContains(
response,
"<strong data-test='expiration-date'>" +
formats.date_format(us.expires, "SHORT_DATE_FORMAT") +
"</strong>",
html=True)
self.assertContains(response, "<strong data-test='images-used'>0 / 123</strong>", html=True)
self.client.logout()
us.delete()
image.delete()
示例9: test_user_page_subscription_premium
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def test_user_page_subscription_premium(self):
image = Generators.image()
image.user = self.user
image.save()
us = Generators.premium_subscription(self.user, "AstroBin Premium")
self.client.login(username='user', password='password')
response = self.client.get(reverse('user_page', args=('user',)))
self.assertContains(response, "<h4>Subscription</h4>", html=True)
self.assertContains(response, "<strong data-test='subscription-type'>AstroBin Premium</strong>", html=True)
self.assertContains(
response,
"<strong data-test='expiration-date'>" +
formats.date_format(us.expires, "SHORT_DATE_FORMAT") +
"</strong>",
html=True)
self.assertContains(response, "<strong data-test='images-used'>0 / ∞</strong>", html=True)
self.client.logout()
us.delete()
image.delete()
示例10: test_user_page_subscription_premium_2020
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def test_user_page_subscription_premium_2020(self):
image = Generators.image()
image.user = self.user
image.save()
us = Generators.premium_subscription(self.user, "AstroBin Premium 2020+")
self.client.login(username='user', password='password')
response = self.client.get(reverse('user_page', args=('user',)))
self.assertContains(response, "<h4>Subscription</h4>", html=True)
self.assertContains(response, "<strong data-test='subscription-type'>AstroBin Premium</strong>", html=True)
self.assertContains(
response,
"<strong data-test='expiration-date'>" +
formats.date_format(us.expires, "SHORT_DATE_FORMAT") +
"</strong>",
html=True)
self.assertContains(response, "<strong data-test='images-used'>0 / ∞</strong>", html=True)
self.client.logout()
us.delete()
image.delete()
示例11: test_user_page_subscription_ultimate
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def test_user_page_subscription_ultimate(self):
image = Generators.image()
image.user = self.user
image.save()
us = Generators.premium_subscription(self.user, "AstroBin Ultimate 2020+")
self.client.login(username='user', password='password')
response = self.client.get(reverse('user_page', args=('user',)))
self.assertContains(response, "<h4>Subscription</h4>", html=True)
self.assertContains(response, "<strong data-test='subscription-type'>AstroBin Ultimate</strong>", html=True)
self.assertContains(
response,
"<strong data-test='expiration-date'>" +
formats.date_format(us.expires, "SHORT_DATE_FORMAT") +
"</strong>",
html=True)
self.assertContains(response, "<strong data-test='images-used'>0 / ∞</strong>", html=True)
self.client.logout()
us.delete()
image.delete()
示例12: parse_date
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def parse_date(value, **kwargs):
"""Parse a Date: header."""
tmp = email.utils.parsedate_tz(value)
if not tmp:
return value
ndate = datetime.datetime.fromtimestamp(email.utils.mktime_tz(tmp))
if ndate.tzinfo is not None:
tz = timezone.get_current_timezone()
ndate = tz.localize(datetime.datetime.fromtimestamp(ndate))
current_language = get_request().user.language
if datetime.datetime.now() - ndate > datetime.timedelta(7):
fmt = "LONG"
else:
fmt = "SHORT"
return date_format(
ndate,
DATETIME_FORMATS.get(current_language, DATETIME_FORMATS.get("en"))[fmt]
)
示例13: entries_by_date
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def entries_by_date(self, request, year, month=None, day=None, *args, **kwargs):
self.entries = self.get_entries().filter(date__year=year)
self.search_type = _('date')
self.search_term = year
if month:
self.entries = self.entries.filter(date__month=month)
df = DateFormat(date(int(year), int(month), 1))
self.search_term = df.format('F Y')
if day:
self.entries = self.entries.filter(date__day=day)
self.search_term = date_format(date(int(year), int(month), int(day)))
return Page.serve(self, request, *args, **kwargs)
示例14: date_el
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def date_el(datetime, arg=None):
if not datetime:
return ''
return mark_safe('<time datetime="%s">%s</time>' % (
datetime.isoformat(), formats.date_format(datetime, arg)))
示例15: display_for_field
# 需要導入模塊: from django.utils import formats [as 別名]
# 或者: from django.utils.formats import date_format [as 別名]
def display_for_field(value, field, html=True, only_date=True):
if getattr(field, 'flatchoices', None):
if html and field.name == 'color' and value:
return make_color_icon(value)
return dict(field.flatchoices).get(value, '')
elif html and (isinstance(field, (models.BooleanField, models.NullBooleanField))):
return make_boolean_icon(value)
elif isinstance(field, (models.BooleanField, models.NullBooleanField)):
boolchoice = {False: "否", True: "是"}
return boolchoice.get(value)
elif value is None:
return ""
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, (models.IntegerField, models.FloatField)):
return formats.number_format(value)
elif isinstance(field, models.ForeignKey) and value:
rel_obj = field.related_model.objects.get(pk=value)
if html and COLOR_FK_FIELD and isinstance(rel_obj, Option):
text_color = rel_obj.color
if not text_color:
text_color = 'text-info'
safe_value = format_html(
'<span class="text-{}">{}</span>', text_color, rel_obj.text)
return safe_value
return force_text(rel_obj)
elif isinstance(field, models.TextField) and value:
return force_text(value)
elif isinstance(field, models.DateTimeField):
if only_date:
return formats.date_format(value)
return formats.localize(timezone.template_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.FileField) and value:
return format_html('<a href="{}">{}</a>', value.url, value)
else:
return display_for_value(value)