Ejemplo n.º 1
0
 def test_iter_view_registrations(self):
     """iter_view_registrations provides only registrations of class."""
     macros = getMultiAdapter((object(), LaunchpadTestRequest()),
                              name='+base-layout-macros')
     names = set(reg.name
                 for reg in iter_view_registrations(macros.__class__))
     self.assertIn('+base-layout-macros', names)
     self.assertNotIn('+related-pages', names)
 def test_iter_view_registrations(self):
     """iter_view_registrations provides only registrations of class."""
     macros = getMultiAdapter(
         (object(), LaunchpadTestRequest()), name='+base-layout-macros')
     names = set(
         reg.name for reg in iter_view_registrations(macros.__class__))
     self.assertIn('+base-layout-macros', names)
     self.assertNotIn('+related-pages', names)
Ejemplo n.º 3
0
    def initialize(self):
        super(PillarSharingView, self).initialize()
        cache = IJSONRequestCache(self.request)
        cache.objects['information_types'] = self.information_types
        cache.objects['sharing_permissions'] = self.sharing_permissions
        cache.objects['bug_sharing_policies'] = self.bug_sharing_policies
        cache.objects['branch_sharing_policies'] = (
            self.branch_sharing_policies)
        cache.objects['specification_sharing_policies'] = (
            self.specification_sharing_policies)
        cache.objects['has_edit_permission'] = check_permission(
            "launchpad.Edit", self.context)
        view_names = set(reg.name
                         for reg in iter_view_registrations(self.__class__))
        if len(view_names) != 1:
            raise AssertionError("Ambiguous view name.")
        cache.objects['view_name'] = view_names.pop()
        batch_navigator = self.grantees()
        cache.objects['grantee_data'] = (
            self._getSharingService().jsonGranteeData(batch_navigator.batch))

        grant_counts = (self._getSharingService().getAccessPolicyGrantCounts(
            self.context))
        cache.objects['invisible_information_types'] = [
            count_info[0].title for count_info in grant_counts
            if count_info[1] == 0
        ]

        def _getBatchInfo(batch):
            if batch is None:
                return None
            return {'memo': batch.range_memo, 'start': batch.startNumber() - 1}

        next_batch = batch_navigator.batch.nextBatch()
        cache.objects['next'] = _getBatchInfo(next_batch)
        prev_batch = batch_navigator.batch.prevBatch()
        cache.objects['prev'] = _getBatchInfo(prev_batch)
        cache.objects['total'] = batch_navigator.batch.total()
        cache.objects['forwards'] = batch_navigator.batch.range_forwards
        last_batch = batch_navigator.batch.lastBatch()
        cache.objects['last_start'] = last_batch.startNumber() - 1
        cache.objects.update(_getBatchInfo(batch_navigator.batch))
Ejemplo n.º 4
0
    def initialize(self):
        super(PillarSharingView, self).initialize()
        cache = IJSONRequestCache(self.request)
        cache.objects['information_types'] = self.information_types
        cache.objects['sharing_permissions'] = self.sharing_permissions
        cache.objects['bug_sharing_policies'] = self.bug_sharing_policies
        cache.objects['branch_sharing_policies'] = (
            self.branch_sharing_policies)
        cache.objects['specification_sharing_policies'] = (
            self.specification_sharing_policies)
        cache.objects['has_edit_permission'] = check_permission(
            "launchpad.Edit", self.context)
        view_names = set(reg.name for reg in
                         iter_view_registrations(self.__class__))
        if len(view_names) != 1:
            raise AssertionError("Ambiguous view name.")
        cache.objects['view_name'] = view_names.pop()
        batch_navigator = self.grantees()
        cache.objects['grantee_data'] = (
            self._getSharingService().jsonGranteeData(batch_navigator.batch))

        grant_counts = (
            self._getSharingService().getAccessPolicyGrantCounts(self.context))
        cache.objects['invisible_information_types'] = [
            count_info[0].title for count_info in grant_counts
            if count_info[1] == 0]

        def _getBatchInfo(batch):
            if batch is None:
                return None
            return {'memo': batch.range_memo,
                    'start': batch.startNumber() - 1}

        next_batch = batch_navigator.batch.nextBatch()
        cache.objects['next'] = _getBatchInfo(next_batch)
        prev_batch = batch_navigator.batch.prevBatch()
        cache.objects['prev'] = _getBatchInfo(prev_batch)
        cache.objects['total'] = batch_navigator.batch.total()
        cache.objects['forwards'] = batch_navigator.batch.range_forwards
        last_batch = batch_navigator.batch.lastBatch()
        cache.objects['last_start'] = last_batch.startNumber() - 1
        cache.objects.update(_getBatchInfo(batch_navigator.batch))
Ejemplo n.º 5
0
def get_batch_properties_for_json_cache(view, batchnav):
    """Get values to insert into `IJSONRequestCache` for JS batchnavs."""
    properties = {}
    view_names = set(reg.name
                     for reg in iter_view_registrations(view.__class__))
    if len(view_names) != 1:
        raise AssertionError("Ambiguous view name.")
    properties['view_name'] = view_names.pop()

    def _getBatchInfo(batch):
        if batch is None:
            return None
        return {'memo': batch.range_memo, 'start': batch.startNumber() - 1}

    next_batch = batchnav.batch.nextBatch()
    properties['next'] = _getBatchInfo(next_batch)
    prev_batch = batchnav.batch.prevBatch()
    properties['prev'] = _getBatchInfo(prev_batch)
    properties['total'] = batchnav.batch.total()
    properties['forwards'] = batchnav.batch.range_forwards
    last_batch = batchnav.batch.lastBatch()
    properties['last_start'] = last_batch.startNumber() - 1
    properties.update(_getBatchInfo(batchnav.batch))
    return properties