Load all WordPress media from the given site.

        :param max_pages: kill counter to avoid infinite looping
        :return: None
778726
def load_media(self, max_pages=150):
        
        logger.info("loading media")

        # clear them all out so we don't get dupes
        if self.purge_first:
            logger.warning("purging ALL media from site %s", self.site_id)
            Media.objects.filter(site_id=self.site_id).delete()

        path = "sites/{}/media".format(self.site_id)
        params = {"number": 100}
        self.set_media_params_after(params)
        page = 1

        response = self.get(path, params)

        if not response.ok:
            logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)

        while response.ok and response.text and page < max_pages:
            logger.info(" - page: %d", page)

            api_medias = response.json().get("media")
            if not api_medias:
                # we're done here
                break

            medias = []
            for api_media in api_medias:

                # exclude media items that are not attached to posts (for now)
                if api_media["post_ID"] != 0:

                    # if it exists locally, update local version if anything has changed
                    existing_media = Media.objects.filter(site_id=self.site_id, wp_id=api_media["ID"]).first()
                    if existing_media:
                        self.update_existing_media(existing_media, api_media)
                    else:
                        medias.append(self.get_new_media(api_media))

            if medias:
                Media.objects.bulk_create(medias)

            # get next page
            page += 1
            params["page"] = page
            response = self.get(path, params)

            if not response.ok:
                logger.warning("Response NOT OK! status_code=%s\n%s", response.status_code, response.text)
                return
283945
def num_pages(self):
        

        if self.count == 0 and not self.allow_empty_first_page:
            return 0

        hits = max(1, self.count - self.orphans)

        return int(ceil(hits / float(self.per_page)))
980848
def all(self):
        
        return self.pages(self.url.page, self.url.max_page)
572225
def fetch_pages(response, limit, type)
      pages = [GoogleApps::Atom.feed(response.body)]

      while (pages.last.next_page) and (pages.count * PAGE_SIZE[:user] < limit)
        pages << get_next_page(pages.last.next_page, type)
      end
      pages
    end
1332104
def get_all_file_report_pages(self, query):
        
        responses = []
        r = self.get_hashes_from_search(query)
        responses.append(r)

        if ('results' in r.keys()) and ('next_page' in r['results'].keys()):
            next_page = r['results']['next_page']
        else:
            next_page = None

        while next_page:
            r = self.get_hashes_from_search(query, next_page)

            if ('results' in r.keys()) and ('next_page' in r['results'].keys()):
                next_page = r['results']['next_page']
            else:
                next_page = None

            responses.append(r)
        return dict(results=responses)
1034200
def retrieve_pages(dir, dot_pages)
      theme_pages = []
      dot_pages.each do |page|
        theme_pages << Page.new(@site, dir, "/", page)
      end
      site.pages.concat(theme_pages)
    end
513781
def _continued_query(self, query_params, key="pages"):
        
        query_params.update(self.__title_query_param())

        last_cont = dict()
        prop = query_params.get("prop")

        while True:
            params = query_params.copy()
            params.update(last_cont)

            request = self.mediawiki.wiki_request(params)

            if "query" not in request:
                break

            pages = request["query"][key]
            if "generator" in query_params:
                for datum in pages.values():
                    yield datum
            elif isinstance(pages, list):
                for datum in list(enumerate(pages)):
                    yield datum[1]
            else:
                for datum in pages[self.pageid].get(prop, list()):
                    yield datum

            if "continue" not in request or request["continue"] == last_cont:
                break

            last_cont = request["continue"]
1138728
def pages(self):
        """"""
        rev = self.db.get('site:rev')
        if int(rev) != self.revision:
            self.reload_site()

        return self._pages
51529
def pages(self, limit=0):
        """"""
        if limit > 0:
            self.iterator.limit = limit
        return self.iterator
249456
def _get_link_pages(page, per_page, count, page_url):
    # type: (int, int, int, str) -> Dict[str, str]
    
    current_page = _page_arg(page)
    links = {}
    end = page * per_page

    if page > 1:
        links['prev'] = page_url.replace(current_page, _page_arg(page - 1))

    if end < count:
        links['next'] = page_url.replace(current_page, _page_arg(page + 1))

    if per_page < count:
        links['first'] = page_url.replace(current_page, _page_arg(1))
        links['last'] = page_url.replace(current_page, _page_arg((count + per_page - 1) // per_page))

    return links
734072
def all(self):
        
        page = self._load(self.href)
        while True:
            try:
                for item in page._items:
                    yield item
                page = page.next_page()
            except PaginationError:
                break
370288
def index():
    
    context = {'postform': NewPostForm(),
               'pageform': NewPageForm(),
               'delform': DeleteForm()}

    n = request.args.get('all')
    if n is None:
        wants_now = None
    else:
        wants_now = n == '1'

    if wants_now is None and current_user.wants_all_posts:
        wants = True
    else:
        wants = wants_now

    if current_user.can_edit_all_posts and wants:
        posts = site.all_posts
        pages = site.pages
    else:
        wants = False
        posts = []
        pages = []
        for p in site.timeline:
            if (p.meta('author.uid') and
                    p.meta('author.uid') != str(current_user.uid)):
                continue
            if p.is_post:
                posts.append(p)
            else:
                pages.append(p)

    context['posts'] = posts
    context['pages'] = pages
    context['title'] = 'Posts & Pages'
    context['wants'] = wants
    return render('coil_index.tmpl', context)
1148104
def get_directories(self, request):
        

        queryset = self.folder.media_folder_children.all().order_by(*config.MEDIA_FOLDERS_ORDER_BY.split(","))

        paginator = Paginator(queryset, self.objects_per_page)

        page = request.GET.get('page', None)

        try:
            object_list = paginator.page(page)
        except PageNotAnInteger:

            if page == "all":
                object_list = queryset
            else:
                object_list = paginator.page(1)

        except EmptyPage:
            object_list = paginator.page(paginator.num_pages)

        return object_list
1174048
def on_site(self, site_id=None):
        
        if settings.PAGE_USE_SITE_ID:
            if not site_id:
                site_id = settings.SITE_ID
            return self.filter(sites=site_id)
        return self.all()
133927
public void loadPages() {
        if (optimalPageWidth == 0 || optimalPageHeight == 0) {
            return;
        }

        // Cancel all current tasks
        renderingAsyncTask.removeAllTasks();
        cacheManager.makeANewSet();

        // Find current index in filtered user pages
        int index = currentPage;
        if (filteredUserPageIndexes != null) {
            index = filteredUserPageIndexes[currentPage];
        }

        // Loop through the pages like [...][4][2][0][1][3][...]
        // loading as many parts as it can.
        int parts = 0;
        for (int i = 0; i <= Constants.LOADED_SIZE / 2 && parts < CACHE_SIZE; i++) {
            parts += loadPage(index + i, CACHE_SIZE - parts);
            if (i != 0 && parts < CACHE_SIZE) {
                parts += loadPage(index - i, CACHE_SIZE - parts);
            }
        }

        invalidate();
    }
1074267
def next_page(params = {}, opts = {})
      return self.class.empty_list(opts) unless has_more
      last_id = data.last.id

      params = filters.merge(starting_after: last_id).merge(params)

      list(params, opts)
    end
1043782
def get_all_file_report_pages(self, query):
        
        responses = []
        next_page, response = self.get_hashes_from_search(self, query)
        responses.append(_return_response_and_status_code(response))
        while next_page:
            next_page, response = self.get_hashes_from_search(query, next_page)
            responses.append(_return_response_and_status_code(response))
        return dict(results=responses)