當前位置: 首頁>>代碼示例>>Python>>正文


Python timezone.localdate方法代碼示例

本文整理匯總了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() 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:27,代碼來源:process_crossref_events.py

示例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)}
        )
    ) 
開發者ID:eventoL,項目名稱:eventoL,代碼行數:18,代碼來源:views.py

示例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()
            )) 
開發者ID:eventoL,項目名稱:eventoL,代碼行數:18,代碼來源:models.py

示例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) 
開發者ID:g0v,項目名稱:tw-rental-house-data,代碼行數:22,代碼來源:archivehistory.py

示例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
        } 
開發者ID:g0v,項目名稱:tw-rental-house-data,代碼行數:19,代碼來源:export.py

示例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)) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_timezone.py

示例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} 
開發者ID:linuxsoftware,項目名稱:ls.joyous,代碼行數:23,代碼來源:joyous_tags.py

示例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) 
開發者ID:linuxsoftware,項目名稱:ls.joyous,代碼行數:24,代碼來源:calendar.py

示例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) 
開發者ID:linuxsoftware,項目名稱:ls.joyous,代碼行數:24,代碼來源:calendar.py

示例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, "") 
開發者ID:linuxsoftware,項目名稱:ls.joyous,代碼行數:25,代碼來源:test_multiday_event.py

示例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) 
開發者ID:linuxsoftware,項目名稱:ls.joyous,代碼行數:20,代碼來源:test_getevents.py

示例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) 
開發者ID:linuxsoftware,項目名稱:ls.joyous,代碼行數:19,代碼來源:test_getevents.py

示例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, "") 
開發者ID:linuxsoftware,項目名稱:ls.joyous,代碼行數:25,代碼來源:test_simple_event.py

示例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)) 
開發者ID:linuxsoftware,項目名稱:ls.joyous,代碼行數:24,代碼來源:test_simple_event.py

示例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) 
開發者ID:linuxsoftware,項目名稱:ls.joyous,代碼行數:23,代碼來源:test_simple_event.py


注:本文中的django.utils.timezone.localdate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。