~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-13 10:49:24 UTC
  • mfrom: (13404.2.3 batchnav)
  • Revision ID: launchpad@pqm.canonical.com-20110713104924-mfbue2x6uo8skz1r
[r=lifeless][bug=809719] Update to lazr.batchnavigator 1.2.5.

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
16
17
from lazr.batchnavigator.z3batching import batch
17
18
from zope.component import getUtility
18
19
from zope.interface import Interface
566
567
class GoogleBatchNavigator(BatchNavigator):
567
568
    """A batch navigator with a fixed size of 20 items per batch."""
568
569
 
 
570
    _batch_factory = WindowedListBatch
569
571
    # Searches generally don't show the 'Last' link when there is a
570
572
    # good chance of getting over 100,000 results.
571
573
    show_last_link = False
573
575
    singular_heading = 'page'
574
576
    plural_heading = 'pages'
575
577
 
576
 
    def __init__(self, results, request, start=0, size=20, callback=None):
 
578
    def __init__(self, results, request, start=0, size=20, callback=None,
 
579
                 transient_parameters=None, force_start=False,
 
580
                 range_factory=None):
577
581
        """See `BatchNavigator`.
578
582
 
579
583
        :param results: A `PageMatches` object that contains the matching
584
588
        :param size: The batch size is fixed to 20, The param is not used.
585
589
        :param callback: Not used.
586
590
        """
587
 
        # We do not want to call super() because it will use the batch
588
 
        # size from the URL.
589
 
        # pylint: disable-msg=W0231
590
591
        results = WindowedList(results, start, results.total)
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
 
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)
600
596
 
 
597
    def determineSize(self, size, batch_params_source):
 
598
        # Force the default and users requested sizes to 20.
601
599
        self.default_size = 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)
 
600
        return 20