def _iterate_objs(query_string): query = (Event.query.filter( Event.title_matches(to_unicode(query_string)), ~Event.is_deleted).options( undefer('effective_protection_mode'))) sort_dir = db.desc if self._descending else db.asc if self._orderBy == 'start': query = query.order_by(sort_dir(Event.start_dt)) elif self._orderBy == 'end': query = query.order_by(sort_dir(Event.end_dt)) elif self._orderBy == 'id': query = query.order_by(sort_dir(Event.id)) elif self._orderBy == 'title': query = query.order_by(sort_dir(db.func.lower(Event.title))) counter = 0 # Query the DB in chunks of 1000 records per query until the limit is satisfied for event in query.yield_per(1000): if event.can_access(self._user): counter += 1 # Start yielding only when the counter reaches the given offset if (self._offset is None) or (counter > self._offset): yield event # Stop querying the DB when the limit is satisfied if (self._limit is not None) and ( counter == self._offset + self._limit): break
def _iterate_objs(query_string): query = (Event.query .filter(Event.title_matches(to_unicode(query_string)), ~Event.is_deleted) .options(undefer('effective_protection_mode'))) sort_dir = db.desc if self._descending else db.asc if self._orderBy == 'start': query = query.order_by(sort_dir(Event.start_dt)) elif self._orderBy == 'end': query = query.order_by(sort_dir(Event.end_dt)) elif self._orderBy == 'id': query = query.order_by(sort_dir(Event.id)) elif self._orderBy == 'title': query = query.order_by(sort_dir(db.func.lower(Event.title))) counter = 0 # Query the DB in chunks of 1000 records per query until the limit is satisfied for event in query.yield_per(1000): if event.can_access(self._user): counter += 1 # Start yielding only when the counter reaches the given offset if (self._offset is None) or (counter > self._offset): yield event # Stop querying the DB when the limit is satisfied if (self._limit is not None) and (counter == self._offset + self._limit): break
def search_events(self, q, user, page, category_id, admin_override_enabled): filters = [Event.title_matches(q), ~Event.is_deleted] if category_id is not None: filters.append(Event.category_chain_overlaps(category_id)) query = (Event.query.filter(*filters).options( load_only('id', 'category_id', 'access_key', 'protection_mode'), undefer(Event.effective_protection_mode), _apply_acl_entry_strategy(selectinload(Event.acl_entries), EventPrincipal))) objs, pagenav = self._paginate(query, page, Event.id, user, admin_override_enabled) query = (Event.query.filter(Event.id.in_(e.id for e in objs)).options( undefer(Event.detailed_category_chain), selectinload(Event.person_links).joinedload('person').joinedload( 'user').load_only('is_system'), joinedload(Event.own_venue), joinedload(Event.own_room).options(raiseload('*'), joinedload('location')), )) events_by_id = {e.id: e for e in query} events = [events_by_id[e.id] for e in objs] res = HTMLStrippingEventSchema(many=True).dump(events) return pagenav, EventResultSchema(many=True).load(res)
def search_events(self, q, user, page, category_id, admin_override_enabled): filters = [Event.title_matches(q), ~Event.is_deleted] if category_id is not None: filters.append(Event.category_chain_overlaps(category_id)) query = (Event.query.filter(*filters).options( subqueryload(Event.acl_entries), undefer(Event.effective_protection_mode))) objs, pagenav = self._paginate(query, page, Event.id, user, admin_override_enabled) res = HTMLStrippingEventSchema(many=True).dump(objs) return pagenav, EventResultSchema(many=True).load(res)
def _iterate_objs(query_string): query = Event.find(Event.title_matches(to_unicode(query_string)), ~Event.is_deleted) if self._orderBy == 'start': query = query.order_by(Event.start_dt) elif self._orderBy == 'id': query = query.order_by(Event.id) counter = 0 # Query the DB in chunks of 1000 records per query until the limit is satisfied for event in query.yield_per(1000): if event.can_access(self._aw.getUser().user if self._aw.getUser() else None): counter += 1 # Start yielding only when the counter reaches the given offset if (self._offset is None) or (counter > self._offset): yield event # Stop querying the DB when the limit is satisfied if (self._limit is not None) and (counter == self._offset + self._limit): break
def _iterate_objs(query_string): query = Event.find(Event.title_matches(to_unicode(query_string)), ~Event.is_deleted) if self._orderBy == 'start': query = query.order_by(Event.start_dt) elif self._orderBy == 'id': query = query.order_by(Event.id) counter = 0 # Query the DB in chunks of 1000 records per query until the limit is satisfied for event in query.yield_per(1000): if event.can_access(self._aw.getUser().user if self._aw. getUser() else None): counter += 1 # Start yielding only when the counter reaches the given offset if (self._offset is None) or (counter > self._offset): yield event # Stop querying the DB when the limit is satisfied if (self._limit is not None) and ( counter == self._offset + self._limit): break