Python django.db.models.query.ModelIterable() Examples

The following are 10 code examples of django.db.models.query.ModelIterable(). 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.db.models.query , or try the search function .
Example #1
Source File: models.py    From cleanerversion with Apache License 2.0 6 votes vote down vote up
def _fetch_all(self):
        """
        Completely overrides the QuerySet._fetch_all method by adding the
        timestamp to all objects

        :return: See django.db.models.query.QuerySet._fetch_all for return
            values
        """
        if self._result_cache is None:
            self._result_cache = list(self.iterator())
            # TODO: Do we have to test for ValuesListIterable, ValuesIterable,
            # and FlatValuesListIterable here?
            if self._iterable_class == ModelIterable:
                for x in self._result_cache:
                    self._set_item_querytime(x)
        if self._prefetch_related_lookups and not self._prefetch_done:
            self._prefetch_related_objects() 
Example #2
Source File: events.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def byDay(self, fromDate, toDate):
        request = self.request
        class ByDayIterable(ModelIterable):
            def __iter__(self):
                evods = EventsByDayList(fromDate, toDate)
                for page in super().__iter__():
                    pageFromDate = getLocalDate(page.date,
                                                page.time_from, page.tz)
                    pageToDate   = getLocalDate(page.date,
                                                page.time_to, page.tz)
                    thisEvent = ThisEvent(page.title, page,
                                          page.get_url(request))
                    evods.add(thisEvent, pageFromDate, pageToDate)
                yield from evods

        qs = self._clone()
        qs._iterable_class = ByDayIterable
        return qs.filter(date__range=(fromDate - _2days, toDate + _2days)) 
Example #3
Source File: events.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def byDay(self, fromDate, toDate):
        request = self.request
        class ByDayIterable(ModelIterable):
            def __iter__(self):
                evods = EventsByDayList(fromDate, toDate)
                for page in super().__iter__():
                    pageFromDate = getLocalDate(page.date_from,
                                                page.time_from, page.tz)
                    pageToDate   = getLocalDate(page.date_to,
                                                page.time_to, page.tz)
                    thisEvent = ThisEvent(page.title, page,
                                          page.get_url(request))
                    evods.add(thisEvent, pageFromDate, pageToDate)
                yield from evods

        qs = self._clone()
        qs._iterable_class = ByDayIterable
        return qs.filter(date_to__gte   = fromDate - _2days)   \
                 .filter(date_from__lte = toDate + _2days) 
Example #4
Source File: events.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def byDay(self, fromDate, toDate):
        request = self.request
        class ByDayIterable(ModelIterable):
            def __iter__(self):
                evods = EventsByDayList(fromDate, toDate)
                for page in super().__iter__():
                    thisEvent = ThisEvent(page.postponement_title,
                                          page, page.get_url(request))
                    pageFromDate = getLocalDate(page.date,
                                                page.time_from, page.tz)
                    daysDelta = dt.timedelta(days=page.num_days - 1)
                    pageToDate = getLocalDate(page.date + daysDelta,
                                              page.time_to, page.tz)
                    evods.add(thisEvent, pageFromDate, pageToDate)
                yield from evods

        qs = self._clone()
        qs._iterable_class = ByDayIterable
        return qs.filter(date__range=(fromDate - _1day, toDate + _1day)) 
Example #5
Source File: test_query.py    From django-seal with MIT License 5 votes vote down vote up
def test_seal_non_sealable_model_iterable_subclass(self):
        message = (
            "iterable_class <class 'django.db.models.query.ModelIterable'> is not a subclass of SealedModelIterable"
        )
        with self.assertRaisesMessage(TypeError, message):
            SeaGull.objects.seal(iterable_class=ModelIterable) 
Example #6
Source File: events.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def this(self):
        request = self.request
        class ThisEventIterable(ModelIterable):
            def __iter__(self):
                for page in super().__iter__():
                    yield ThisEvent(page.title, page, page.get_url(request))
        qs = self._clone()
        qs._iterable_class = ThisEventIterable
        return qs 
Example #7
Source File: events.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def this(self, holidays=None):
        request = self.request
        class ThisRecurringEventIterable(ModelIterable):
            def __iter__(self):
                for page in super().__iter__():
                    if holidays is not None:
                        page.holidays = holidays
                    yield ThisEvent(page.title, page, page.get_url(request))
        qs = self._clone()
        qs._iterable_class = ThisRecurringEventIterable
        return qs 
Example #8
Source File: events.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def this(self):
        request = self.request
        class ThisExtraInfoIterable(ModelIterable):
            def __iter__(self):
                for page in super().__iter__():
                    yield ThisEvent(page.extra_title, page,
                                    page.get_url(request))
        qs = self._clone()
        qs._iterable_class = ThisExtraInfoIterable
        return qs 
Example #9
Source File: events.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def this(self):
        request = self.request
        # FIXME: ThisIterable classes have different names, but all
        # ByDayIterable classes don't - Whould changing this break backwards
        # compatibility for anyone?
        class ThisPostponementIterable(ModelIterable):
            def __iter__(self):
                for page in super().__iter__():
                    yield ThisEvent(page.postponement_title,
                                    page, page.get_url(request))
        qs = self._clone()
        qs._iterable_class = ThisPostponementIterable
        return qs 
Example #10
Source File: events.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def this(self, holidays=None):
        request = self.request
        class ThisClosedForHolidaysIterable(ModelIterable):
            def __iter__(self):
                for page in super().__iter__():
                    if holidays is not None:
                        page.holidays = holidays
                    yield ThisEvent(page.cancellation_title, page,
                                    page.get_url(request))
        qs = self._clone()
        qs._iterable_class = ThisClosedForHolidaysIterable
        return qs