~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/browser/root.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-12 01:56:30 UTC
  • mfrom: (13404.1.1 revert-13392)
  • Revision ID: launchpad@pqm.canonical.com-20110712015630-mzy3uu3ujp5pqi9e
[release-critical=wgrant][r=wgrant][rollback=13392] Revert r13392. It
 breaks when there are multiple batchnavs on a single page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
import time
14
14
 
15
15
import feedparser
16
 
from lazr.batchnavigator import ListRangeFactory
17
16
from lazr.batchnavigator.z3batching import batch
18
17
from zope.component import getUtility
19
18
from zope.interface import Interface
567
566
class GoogleBatchNavigator(BatchNavigator):
568
567
    """A batch navigator with a fixed size of 20 items per batch."""
569
568
 
570
 
    _batch_factory = WindowedListBatch
571
569
    # Searches generally don't show the 'Last' link when there is a
572
570
    # good chance of getting over 100,000 results.
573
571
    show_last_link = False
575
573
    singular_heading = 'page'
576
574
    plural_heading = 'pages'
577
575
 
578
 
    def __init__(self, results, request, start=0, size=20, callback=None,
579
 
                 transient_parameters=None, force_start=False,
580
 
                 range_factory=None):
 
576
    def __init__(self, results, request, start=0, size=20, callback=None):
581
577
        """See `BatchNavigator`.
582
578
 
583
579
        :param results: A `PageMatches` object that contains the matching
588
584
        :param size: The batch size is fixed to 20, The param is not used.
589
585
        :param callback: Not used.
590
586
        """
 
587
        # We do not want to call super() because it will use the batch
 
588
        # size from the URL.
 
589
        # pylint: disable-msg=W0231
591
590
        results = WindowedList(results, start, results.total)
592
 
        super(GoogleBatchNavigator, self).__init__(results, request,
593
 
            start=start, size=size, callback=callback,
594
 
            transient_parameters=transient_parameters, force_start=force_start,
595
 
            range_factory=range_factory)
 
591
        self.request = request
 
592
        request_start = request.get(self.start_variable_name, None)
 
593
        if request_start is None:
 
594
            self.start = start
 
595
        else:
 
596
            try:
 
597
                self.start = int(request_start)
 
598
            except (ValueError, TypeError):
 
599
                self.start = start
596
600
 
597
 
    def determineSize(self, size, batch_params_source):
598
 
        # Force the default and users requested sizes to 20.
599
601
        self.default_size = 20
600
 
        return 20
 
602
 
 
603
        self.transient_parameters = [self.start_variable_name]
 
604
 
 
605
        self.batch = WindowedListBatch(
 
606
            results, start=self.start, size=self.default_size)
 
607
        self.setHeadings(
 
608
            self.default_singular_heading, self.default_plural_heading)