本文整理汇总了Python中django.utils.timezone.localdate方法的典型用法代码示例。如果您正苦于以下问题:Python timezone.localdate方法的具体用法?Python timezone.localdate怎么用?Python timezone.localdate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.timezone
的用法示例。
在下文中一共展示了timezone.localdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def handle(self, *args, **options):
"""Collects Crossref Events, parses them and stores new events locally.
:param args: None
:param options: None
:return: None
"""
translation.activate(settings.LANGUAGE_CODE)
file_name = '{date}.json'.format(date=timezone.localdate())
file_path = os.path.join(settings.BASE_DIR, 'files', 'temp', file_name)
if os.path.isfile(file_path):
# Process file
print('Existing file found.')
process_events()
else:
# Fetch data
print('Fetching data from crossref event tracking API.')
fetch_crossref_data()
process_events()
示例2: draw
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def draw(request, event_slug):
users = [
str(attendance_date.attendee) for attendance_date in
AttendeeAttendanceDate.objects.filter(
attendee__event__event_slug=event_slug,
date__date=timezone.localdate()
)
]
return render(
request,
'event/draw.html',
update_event_info(
event_slug,
{'eventusers': users, 'eventusersjson': json.dumps(users)}
)
)
示例3: get_queryset
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def get_queryset(self):
today = timezone.localdate()
return super() \
.get_queryset() \
.annotate(attendees_count=models.Count('attendee', distinct=True)) \
.annotate(last_date=models.Max('eventdate__date')) \
.annotate(activity_proposal_is_open=models.Case(
models.When(models.Q(limit_proposal_date__gte=today), then=True),
default=False,
output_field=models.BooleanField()
)) \
.annotate(registration_is_open=models.Case(
models.When(models.Q(last_date__gte=today), then=True),
default=False,
output_field=models.BooleanField()
))
示例4: handle
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def handle(self, *args, **options):
output = options['output_dir']
if not path.isdir(output):
raise CommandError('Directory {} not existed'.format(output))
if options['before_date'] and options['days_ago']:
raise CommandError('Donot use --before-date and --days-ago at the same time -___-')
before_date = timezone.localdate()
if options['before_date']:
before_date = options['before_date']
elif options['days_ago']:
before_date -= timedelta(options['days_ago'])
else:
before_date -= timedelta(self.default_days_ago)
self.remove_old_ts(output, before_date)
self.make_tgz(output)
示例5: is_end_of_sth
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def is_end_of_sth(self):
today = timezone.localdate()
tomorrow = today + timedelta(days=1)
is_end_of_month = today.month != tomorrow.month
is_end_of_quarter = False
is_end_of_year = False
if is_end_of_month:
is_end_of_quarter = today.month % 3 == 0
is_end_of_year = today.month == 12
return {
'month': is_end_of_month,
'quarter': is_end_of_quarter,
'year': is_end_of_year
}
示例6: test_localdate
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def test_localdate(self):
naive = datetime.datetime(2015, 1, 1, 0, 0, 1)
with self.assertRaisesMessage(ValueError, 'localtime() cannot be applied to a naive datetime'):
timezone.localdate(naive)
with self.assertRaisesMessage(ValueError, 'localtime() cannot be applied to a naive datetime'):
timezone.localdate(naive, timezone=EAT)
aware = datetime.datetime(2015, 1, 1, 0, 0, 1, tzinfo=ICT)
self.assertEqual(timezone.localdate(aware, timezone=EAT), datetime.date(2014, 12, 31))
with timezone.override(EAT):
self.assertEqual(timezone.localdate(aware), datetime.date(2014, 12, 31))
with mock.patch('django.utils.timezone.now', return_value=aware):
self.assertEqual(timezone.localdate(timezone=EAT), datetime.date(2014, 12, 31))
with timezone.override(EAT):
self.assertEqual(timezone.localdate(), datetime.date(2014, 12, 31))
示例7: minicalendar
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def minicalendar(context):
"""
Displays a little ajax version of the calendar.
"""
today = timezone.localdate()
request = context['request']
home = request.site.root_page
cal = CalendarPage.objects.live().descendant_of(home).first()
calUrl = cal.get_url(request) if cal else None
if cal:
events = cal._getEventsByWeek(request, today.year, today.month)
else:
events = getAllEventsByWeek(request, today.year, today.month)
return {'request': request,
'today': today,
'year': today.year,
'month': today.month,
'calendarUrl': calUrl,
'monthName': calendar.month_name[today.month],
'weekdayInfo': zip(weekday_abbr, weekday_name),
'events': events}
示例8: servePast
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def servePast(self, request):
"""Past events list view."""
myurl = self.get_url(request)
today = timezone.localdate()
monthlyUrl = myurl + self.reverse_subpage('serveMonth',
args=[today.year, today.month])
weekYear, weekNum, dow = gregorian_to_week_date(today)
weeklyUrl = myurl + self.reverse_subpage('serveWeek',
args=[weekYear, weekNum])
listUrl = myurl + self.reverse_subpage('serveUpcoming')
pastEvents = self._getPastEvents(request)
eventsPage = self._paginate(request, pastEvents)
cxt = self._getCommonContext(request)
cxt.update({'weeklyUrl': weeklyUrl,
'monthlyUrl': monthlyUrl,
'listUrl': listUrl,
'events': eventsPage})
cxt.update(self._getExtraContext("past"))
return TemplateResponse(request,
"joyous/calendar_list_past.html",
cxt)
示例9: serveMiniMonth
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def serveMiniMonth(self, request, year=None, month=None):
"""Serve data for the MiniMonth template tag."""
if not request.is_ajax():
raise Http404("/mini/ is for ajax requests only")
today = timezone.localdate()
if year is None: year = today.year
if month is None: month = today.month
year = int(year)
month = int(month)
cxt = self._getCommonContext(request)
cxt.update({'year': year,
'month': month,
'calendarUrl': self.get_url(request),
'monthName': MONTH_NAMES[month],
'weekdayInfo': zip(weekday_abbr, weekday_name),
'events': self._getEventsByWeek(request, year, month)})
cxt.update(self._getExtraContext("mini"))
return TemplateResponse(request,
"joyous/includes/minicalendar.html",
cxt)
示例10: testStatus
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def testStatus(self):
self.assertEqual(self.event.status, "finished")
self.assertEqual(self.event.status_text, "This event has finished.")
today = timezone.localdate()
yesterday = today - dt.timedelta(1)
nextWeek = today + dt.timedelta(7 - today.weekday())
nowEvent = MultidayEventPage(owner = self.user,
slug = "now",
title = "Now Event",
date_from = yesterday,
date_to = nextWeek)
self.calendar.add_child(instance=nowEvent)
self.assertEqual(nowEvent.status, "started")
self.assertEqual(nowEvent.status_text, "This event has started.")
tomorrow = today + dt.timedelta(days=1)
futureEvent = MultidayEventPage(owner = self.user,
slug = "tomorrow",
title = "Tomorrow's Event",
date_from = tomorrow,
date_to = tomorrow + dt.timedelta(days=1))
self.calendar.add_child(instance=futureEvent)
self.assertIsNone(futureEvent.status)
self.assertEqual(futureEvent.status_text, "")
示例11: testGetAllUpcomingEvents
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def testGetAllUpcomingEvents(self):
today = timezone.localdate()
futureEvent = MultidayEventPage(owner = self.user,
slug = "tomorrow",
title = "Tomorrow's Event",
date_from = today + dt.timedelta(days=1),
date_to = today + dt.timedelta(days=3),
time_from = dt.time(17),
time_to = dt.time(10,30))
self.calendar.add_child(instance=futureEvent)
events = getAllUpcomingEvents(self.request, home=self.home,
holidays=self.calendar.holidays)
self.assertEqual(len(events), 1)
title, event, url = events[0]
self.assertEqual(title, "Tomorrow's Event")
self.assertEqual(event.slug, "tomorrow")
events0 = getAllUpcomingEvents(self.request)
self.assertEqual(len(events0), 1)
示例12: testGetAllCurrentEvents
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def testGetAllCurrentEvents(self):
today = timezone.localdate()
futureEvent = MultidayEventPage(owner = self.user,
slug = "yesterday",
title = "Yesterday's Event",
date_from = today - dt.timedelta(days=1),
date_to = today + dt.timedelta(days=3),
time_from = dt.time(17),
time_to = dt.time(10,30))
self.calendar.add_child(instance=futureEvent)
events = getAllUpcomingEvents(self.request, home=self.home)
self.assertEqual(len(events), 1)
title, event, url = events[0]
self.assertEqual(title, "Yesterday's Event")
self.assertEqual(event.slug, "yesterday")
events0 = getAllUpcomingEvents(self.request)
self.assertEqual(len(events0), 1)
示例13: testStatus
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def testStatus(self):
self.assertEqual(self.event.status, "finished")
self.assertEqual(self.event.status_text, "This event has finished.")
now = timezone.localtime()
earlier = now - dt.timedelta(hours=1)
if earlier.date() != now.date():
earlier = datetimetz(now.date(), dt.time.min)
nowEvent = SimpleEventPage(owner = self.user,
slug = "now",
title = "Now Event",
date = now.date(),
time_from = earlier.time(),
time_to = dt.time.max)
self.assertEqual(nowEvent.status, "started")
self.assertEqual(nowEvent.status_text, "This event has started.")
tomorrow = timezone.localdate() + dt.timedelta(days=1)
futureEvent = SimpleEventPage(owner = self.user,
slug = "tomorrow",
title = "Tomorrow's Event",
date = tomorrow)
self.calendar.add_child(instance=futureEvent)
self.assertIsNone(futureEvent.status)
self.assertEqual(futureEvent.status_text, "")
示例14: testFutureDt
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def testFutureDt(self):
self.assertIsNone(self.event._future_datetime_from)
now = timezone.localtime()
earlier = now - dt.timedelta(hours=1)
if earlier.date() != now.date():
earlier = datetimetz(now.date(), dt.time.min)
nowEvent = SimpleEventPage(owner = self.user,
slug = "now",
title = "Now Event",
date = now.date(),
time_from = earlier.time(),
time_to = dt.time.max)
self.calendar.add_child(instance=nowEvent)
self.assertIsNone(nowEvent._future_datetime_from)
tomorrow = timezone.localdate() + dt.timedelta(days=1)
futureEvent = SimpleEventPage(owner = self.user,
slug = "tomorrow",
title = "Tomorrow's Event",
date = tomorrow)
self.calendar.add_child(instance=futureEvent)
self.assertEqual(futureEvent._future_datetime_from,
datetimetz(tomorrow, dt.time.max))
示例15: testPastDt
# 需要导入模块: from django.utils import timezone [as 别名]
# 或者: from django.utils.timezone import localdate [as 别名]
def testPastDt(self):
self.assertEqual(self.event._past_datetime_from, datetimetz(1987,6,5,11,0))
now = timezone.localtime()
earlier = now - dt.timedelta(hours=1)
if earlier.date() != now.date():
earlier = datetimetz(now.date(), dt.time.min)
nowEvent = SimpleEventPage(owner = self.user,
slug = "now",
title = "Now Event",
date = now.date(),
time_from = earlier.time(),
time_to = dt.time.max)
self.calendar.add_child(instance=nowEvent)
self.assertEqual(nowEvent._past_datetime_from, earlier)
tomorrow = timezone.localdate() + dt.timedelta(days=1)
futureEvent = SimpleEventPage(owner = self.user,
slug = "tomorrow",
title = "Tomorrow's Event",
date = tomorrow)
self.calendar.add_child(instance=futureEvent)
self.assertIsNone(futureEvent._past_datetime_from)