Python django.utils.timezone.localdate() Examples

The following are 30 code examples of django.utils.timezone.localdate(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.utils.timezone , or try the search function .
Example #1
Source File: models.py    From eventoL with GNU General Public License v3.0 7 votes vote down vote up
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()
            )) 
Example #2
Source File: archivehistory.py    From tw-rental-house-data with MIT License 6 votes vote down vote up
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) 
Example #3
Source File: calendar.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #4
Source File: calendar.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #5
Source File: test_multiday_event.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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, "") 
Example #6
Source File: joyous_tags.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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} 
Example #7
Source File: test_timezone.py    From djongo with GNU Affero General Public License v3.0 6 votes vote down vote up
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)) 
Example #8
Source File: test_timezone.py    From djongo with GNU Affero General Public License v3.0 6 votes vote down vote up
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)) 
Example #9
Source File: export.py    From tw-rental-house-data with MIT License 6 votes vote down vote up
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
        } 
Example #10
Source File: test_getevents.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #11
Source File: test_getevents.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #12
Source File: test_simple_event.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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, "") 
Example #13
Source File: views.py    From eventoL with GNU General Public License v3.0 6 votes vote down vote up
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)}
        )
    ) 
Example #14
Source File: test_simple_event.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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)) 
Example #15
Source File: test_simple_event.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #16
Source File: process_crossref_events.py    From janeway with GNU Affero General Public License v3.0 6 votes vote down vote up
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() 
Example #17
Source File: models.py    From openwisp-radius with GNU General Public License v3.0 5 votes vote down vote up
def clean(self):
        if not hasattr(self, 'user'):
            return
        if self.user.is_active:
            logger.warning('user {} is already active'.format(self.user))
            raise ValidationError(_('This user is already active.'))
        if not self.user.phone_number:
            logger.warning('user {} does not have a ' 'phone number'.format(self.user))
            raise ValidationError(_('This user does not have a phone number.'))
        date_start = timezone.localdate()
        date_end = date_start + timedelta(days=1)
        PhoneToken = load_model('PhoneToken')
        qs = PhoneToken.objects.filter(created__range=[date_start, date_end])
        # limit generation of tokens per day by user
        user_token_count = qs.filter(user=self.user).count()
        if user_token_count >= app_settings.SMS_TOKEN_MAX_USER_DAILY:
            logger.warning(
                'user {} has reached the maximum ' 'daily SMS limit'.format(self.user)
            )
            raise ValidationError(_('Maximum daily limit reached.'))
        # limit generation of tokens per day by ip
        ip_token_count = qs.filter(ip=self.ip).count()
        if ip_token_count >= app_settings.SMS_TOKEN_MAX_IP_DAILY:
            logger.warning(
                logger.warning(
                    'user {} has reached the maximum '
                    'daily SMS limit from ip address {}'.format(self.user, self.ip)
                )
            )
            raise ValidationError(
                _('Maximum daily limit reached ' 'from this ip address.')
            ) 
Example #18
Source File: test_multiday_event.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testPastDt(self):
        self.assertEqual(self.event._past_datetime_from,
                         datetimetz(2012,12,31,23,0))
        now = timezone.localtime()
        today = now.date()
        nextWeek = today + dt.timedelta(7 - today.weekday())
        earlier = now - dt.timedelta(hours=1)
        if earlier.date() != now.date():
            earlier = datetimetz(now.date(), dt.time.min)
        nowEvent = MultidayEventPage(owner = self.user,
                                     slug  = "now",
                                     title = "Now Event",
                                     date_from = earlier.date(),
                                     date_to   = nextWeek,
                                     time_from = earlier.time(),
                                     time_to   = dt.time(1))
        self.calendar.add_child(instance=nowEvent)
        self.assertEqual(nowEvent._past_datetime_from, earlier)
        tomorrow = timezone.localdate() + dt.timedelta(days=1)
        futureEvent = MultidayEventPage(owner = self.user,
                                        slug  = "tomorrow",
                                        title = "Tomorrow's Event",
                                        date_from  = tomorrow,
                                        date_to    = tomorrow + dt.timedelta(2))
        self.calendar.add_child(instance=futureEvent)
        self.assertIsNone(futureEvent._past_datetime_from) 
Example #19
Source File: test_multiday_event.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testFutureDt(self):
        self.assertIsNone(self.event._future_datetime_from)
        now = timezone.localtime()
        today = now.date()
        nextWeek = today + dt.timedelta(7 - today.weekday())
        earlier = now - dt.timedelta(hours=1)
        if earlier.date() != now.date():
            earlier = datetimetz(now.date(), dt.time.min)
        nowEvent = MultidayEventPage(owner = self.user,
                                     slug  = "now",
                                     title = "Now Event",
                                     date_from = earlier.date(),
                                     date_to   = nextWeek,
                                     time_from = earlier.time(),
                                     time_to   = dt.time(1))
        self.calendar.add_child(instance=nowEvent)
        self.assertIsNone(nowEvent._future_datetime_from)
        tomorrow = timezone.localdate() + dt.timedelta(days=1)
        futureEvent = MultidayEventPage(owner = self.user,
                                        slug  = "tomorrow",
                                        title = "Tomorrow's Event",
                                        date_from  = tomorrow,
                                        date_to    = tomorrow + dt.timedelta(2))
        self.calendar.add_child(instance=futureEvent)
        self.assertEqual(futureEvent._future_datetime_from,
                         datetimetz(tomorrow, dt.time.max)) 
Example #20
Source File: test_recurring_event.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testStatus(self):
        pastEvent = RecurringEventPage(owner = self.user,
                                       slug  = "past",
                                       title = "Past Event",
                                       repeat = Recurrence(dtstart=dt.date(2008,2,1),
                                                           until=dt.date(2008,5,4),
                                                           freq=WEEKLY,
                                                           byweekday=[SA,SU]))
        self.calendar.add_child(instance=pastEvent)
        self.assertEqual(pastEvent.status, "finished")
        self.assertEqual(pastEvent.status_text, "These events have finished.")
        now = timezone.localtime()
        earlier = now - dt.timedelta(hours=1)
        if earlier.date() != now.date():
            earlier = datetimetz(now.date(), dt.time.min)
        nowEvent = RecurringEventPage(owner = self.user,
                                      slug  = "now",
                                      title = "Now Event",
                                      repeat = Recurrence(dtstart=dt.date(2010,1,1),
                                                          freq=DAILY),
                                      time_from = earlier.time(),
                                      time_to   = dt.time.max)
        self.calendar.add_child(instance=nowEvent)
        self.assertEqual(nowEvent.status, "started")
        self.assertEqual(nowEvent.status_text, "This event has started.")
        today = timezone.localdate()
        notToday = [weekday for weekday in EVERYWEEKDAY if weekday.weekday != today.weekday()]
        pastAndFutureEvent = RecurringEventPage(owner = self.user,
                                                slug  = "not-today",
                                                title = "Any day but today",
                                                repeat = Recurrence(dtstart=dt.date(2009,8,7),
                                                                    freq=WEEKLY,
                                                                    byweekday=notToday))
        self.calendar.add_child(instance=pastAndFutureEvent)
        self.assertIsNone(pastAndFutureEvent.status)
        self.assertEqual(pastAndFutureEvent.status_text, "") 
Example #21
Source File: events.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _getFromTime(self, atDate=None):
        """
        What was the time of this event?  Due to time zones that depends what
        day we are talking about.  If no day is given, assume today.

        :param atDate: day in local timezone for which we want the time_from
        :rtype: time_from in local timezone
        """
        if atDate is None:
            atDate = timezone.localdate()
        return getLocalTimeAtDate(atDate, self.time_from, self.tz) 
Example #22
Source File: dates.py    From bioforum with MIT License 5 votes vote down vote up
def timezone_today():
    """Return the current date in the current time zone."""
    if settings.USE_TZ:
        return timezone.localdate()
    else:
        return datetime.date.today() 
Example #23
Source File: calendar.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _getCommonContext(self, request):
        cxt = self.get_context(request)
        cxt.update({'version':  __version__,
                    'themeCSS': getattr(settings, "JOYOUS_THEME_CSS", ""),
                    'today':    timezone.localdate(),

                    # Init these variables to prevent template DEBUG messages
                    'listLink':     None,
                    'weeklyLink':   None,
                    'monthlyLink':  None,
                   })
        return cxt 
Example #24
Source File: joyous_tags.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def events_this_week(context):
    """
    Displays a week's worth of events.   Starts week with Monday, unless today is Sunday.
    """
    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
    calName = cal.title if cal else None
    today = timezone.localdate()
    beginOrd = today.toordinal()
    if today.weekday() != 6:
        # Start week with Monday, unless today is Sunday
        beginOrd -= today.weekday()
    endOrd = beginOrd + 6
    dateFrom = dt.date.fromordinal(beginOrd)
    dateTo   = dt.date.fromordinal(endOrd)
    if cal:
        events = cal._getEventsByDay(request, dateFrom, dateTo)
    else:
        events = getAllEventsByDay(request, dateFrom, dateTo)
    return {'request':      request,
            'today':        today,
            'calendarUrl':  calUrl,
            'calendarName': calName,
            'events':       events } 
Example #25
Source File: widgets.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def valid_dates(self):
        valid_dates = None # null in JS
        if self.overrides_repeat:
            today = timezone.localdate()
            past = (today - dt.timedelta(days=200)).replace(day=1)
            future = (today + dt.timedelta(days=600)).replace(day=1)
            valid_dates = ["{:%Y%m%d}".format(occurence) for occurence in
                           self.overrides_repeat.between(past, future, inc=True)]
        return valid_dates 
Example #26
Source File: dates.py    From python2017 with MIT License 5 votes vote down vote up
def timezone_today():
    """
    Return the current date in the current time zone.
    """
    if settings.USE_TZ:
        return timezone.localdate()
    else:
        return datetime.date.today() 
Example #27
Source File: models.py    From eventoL with GNU General Public License v3.0 5 votes vote down vote up
def attended_today(self):
        return AttendeeAttendanceDate.objects.filter(
            attendee=self, date__date=timezone.localdate()).exists() 
Example #28
Source File: models.py    From eventoL with GNU General Public License v3.0 5 votes vote down vote up
def attended_today(self):
        return EventUserAttendanceDate.objects.filter(
            event_user=self, date__date=timezone.localdate()).exists() 
Example #29
Source File: dates.py    From python with Apache License 2.0 5 votes vote down vote up
def timezone_today():
    """
    Return the current date in the current time zone.
    """
    if settings.USE_TZ:
        return timezone.localdate()
    else:
        return datetime.date.today() 
Example #30
Source File: dates.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def timezone_today():
    """Return the current date in the current time zone."""
    if settings.USE_TZ:
        return timezone.localdate()
    else:
        return datetime.date.today()