Exemplo n.º 1
0
 def _getMilestoneCondition(self):
     """See `HasMilestonesMixin`."""
     user = getUtility(ILaunchBag).user
     privacy_filter = ProductSet.getProductPrivacyFilter(user)
     return And(
         Milestone.productID == Product.id,
         Product.projectID == self.id,
         privacy_filter)
Exemplo n.º 2
0
 def getRelatedPillars(self, user=None):
     """See `IBugTracker`."""
     products = IStore(Product).find(
         Product, Product.bugtrackerID == self.id, Product.active == True,
         ProductSet.getProductPrivacyFilter(user)).order_by(Product.name)
     groups = IStore(ProjectGroup).find(
         ProjectGroup, ProjectGroup.bugtrackerID == self.id,
         ProjectGroup.active == True).order_by(ProjectGroup.name)
     return groups, products
Exemplo n.º 3
0
 def _milestone_ids_expr(self, user):
     from lp.registry.model.product import (
         Product,
         ProductSet,
     )
     return Select(Milestone.id,
                   tables=[Milestone, Product],
                   where=And(Milestone.name == self.name,
                             Milestone.productID == Product.id,
                             Product.project == self.target,
                             ProductSet.getProductPrivacyFilter(user)))
Exemplo n.º 4
0
 def _milestone_ids_expr(self, user):
     from lp.registry.model.product import (
         Product,
         ProductSet,
         )
     return Select(
         Milestone.id,
         tables=[Milestone, Product],
         where=And(
             Milestone.name == self.name,
             Milestone.productID == Product.id,
             Product.project == self.target,
             ProductSet.getProductPrivacyFilter(user)))
Exemplo n.º 5
0
    def _getMilestones(self, user, only_active):
        """Return a list of milestones for this project group.

        If only_active is True, only active milestones are returned,
        else all milestones.

        A project group has a milestone named 'A', if at least one of its
        products has a milestone named 'A'.
        """
        store = Store.of(self)

        columns = (
            Milestone.name,
            SQL('MIN(Milestone.dateexpected)'),
            SQL('BOOL_OR(Milestone.active)'),
            )
        privacy_filter = ProductSet.getProductPrivacyFilter(user)
        conditions = And(Milestone.product == Product.id,
                         Product.project == self,
                         Product.active == True,
                         privacy_filter)
        result = store.find(columns, conditions)
        result.group_by(Milestone.name)
        if only_active:
            result.having('BOOL_OR(Milestone.active) = TRUE')
        # MIN(Milestone.dateexpected) has to be used to match the
        # aggregate function in the `columns` variable.
        result.order_by(
            'milestone_sort_key(MIN(Milestone.dateexpected), Milestone.name) '
            'DESC')
        # An extra query is required here in order to get the correct
        # products without affecting the group/order of the query above.
        products_by_name = {}
        if result.any() is not None:
            milestone_names = [data[0] for data in result]
            product_conditions = And(
                Product.project == self,
                Milestone.product == Product.id,
                Product.active == True,
                privacy_filter,
                In(Milestone.name, milestone_names))
            for product, name in (
                store.find((Product, Milestone.name), product_conditions)):
                if name not in products_by_name.keys():
                    products_by_name[name] = product
        return shortlist(
            [ProjectMilestone(
                self, name, dateexpected, active,
                products_by_name.get(name, None))
             for name, dateexpected, active in result])
Exemplo n.º 6
0
 def getPillarsForBugtrackers(self, bugtrackers, user=None):
     """See `IBugTrackerSet`."""
     ids = [tracker.id for tracker in bugtrackers]
     products = IStore(Product).find(
         Product, Product.bugtrackerID.is_in(ids), Product.active == True,
         ProductSet.getProductPrivacyFilter(user)).order_by(Product.name)
     groups = IStore(ProjectGroup).find(
         ProjectGroup, ProjectGroup.bugtrackerID.is_in(ids),
         ProjectGroup.active == True).order_by(ProjectGroup.name)
     results = {}
     for product in products:
         results.setdefault(product.bugtracker, []).append(product)
     for project in groups:
         results.setdefault(project.bugtracker, []).append(project)
     return results
Exemplo n.º 7
0
    def _getMilestones(self, user, only_active):
        """Return a list of milestones for this project group.

        If only_active is True, only active milestones are returned,
        else all milestones.

        A project group has a milestone named 'A', if at least one of its
        products has a milestone named 'A'.
        """
        store = Store.of(self)

        columns = (
            Milestone.name,
            SQL('MIN(Milestone.dateexpected)'),
            SQL('BOOL_OR(Milestone.active)'),
        )
        privacy_filter = ProductSet.getProductPrivacyFilter(user)
        conditions = And(Milestone.product == Product.id,
                         Product.projectgroup == self, Product.active == True,
                         privacy_filter)
        result = store.find(columns, conditions)
        result.group_by(Milestone.name)
        if only_active:
            result.having('BOOL_OR(Milestone.active) = TRUE')
        # MIN(Milestone.dateexpected) has to be used to match the
        # aggregate function in the `columns` variable.
        result.order_by(
            'milestone_sort_key(MIN(Milestone.dateexpected), Milestone.name) '
            'DESC')
        # An extra query is required here in order to get the correct
        # products without affecting the group/order of the query above.
        products_by_name = {}
        if result.any() is not None:
            milestone_names = [data[0] for data in result]
            product_conditions = And(Product.projectgroup == self,
                                     Milestone.product == Product.id,
                                     Product.active == True, privacy_filter,
                                     In(Milestone.name, milestone_names))
            for product, name in (store.find((Product, Milestone.name),
                                             product_conditions)):
                if name not in products_by_name.keys():
                    products_by_name[name] = product
        return shortlist([
            ProjectMilestone(self, name, dateexpected, active,
                             products_by_name.get(name, None))
            for name, dateexpected, active in result
        ])
Exemplo n.º 8
0
 def fetchProjectsForDisplay(self, user):
     """See `ITranslationGroup`."""
     # Avoid circular imports.
     from lp.registry.model.product import (
         get_precached_products,
         Product,
         ProductSet,
         )
     products = list(IStore(Product).find(
         Product,
         Product.translationgroupID == self.id,
         Product.active == True,
         ProductSet.getProductPrivacyFilter(user),
         ).order_by(Product.display_name))
     get_precached_products(products, need_licences=True)
     icons = bulk.load_related(LibraryFileAlias, products, ['iconID'])
     bulk.load_related(LibraryFileContent, icons, ['contentID'])
     return products
Exemplo n.º 9
0
    def build_search_query(self, user, text):
        """Query parameters shared by search() and count_search_matches().

        :returns: Storm ResultSet object
        """
        # These classes are imported in this method to prevent an import loop.
        from lp.registry.model.product import Product, ProductSet
        from lp.registry.model.projectgroup import ProjectGroup
        from lp.registry.model.distribution import Distribution
        OtherPillarName = ClassAlias(PillarName)
        origin = [
            PillarName,
            LeftJoin(OtherPillarName,
                     PillarName.alias_for == OtherPillarName.id),
            LeftJoin(Product, PillarName.product == Product.id),
            LeftJoin(ProjectGroup, PillarName.projectgroup == ProjectGroup.id),
            LeftJoin(Distribution, PillarName.distribution == Distribution.id),
        ]
        conditions = SQL('''
            PillarName.active = TRUE
            AND (PillarName.name = lower(%(text)s) OR

                 Product.fti @@ ftq(%(text)s) OR
                 lower(Product.title) = lower(%(text)s) OR

                 Project.fti @@ ftq(%(text)s) OR
                 lower(Project.title) = lower(%(text)s) OR

                 Distribution.fti @@ ftq(%(text)s) OR
                 lower(Distribution.title) = lower(%(text)s)
                )
            ''' % sqlvalues(text=ensure_unicode(text)))
        columns = [
            PillarName, OtherPillarName, Product, ProjectGroup, Distribution
        ]
        return IStore(PillarName).using(*origin).find(
            tuple(columns),
            And(conditions, ProductSet.getProductPrivacyFilter(user)))
Exemplo n.º 10
0
 def _getMilestoneCondition(self):
     """See `HasMilestonesMixin`."""
     user = getUtility(ILaunchBag).user
     privacy_filter = ProductSet.getProductPrivacyFilter(user)
     return And(Milestone.productID == Product.id,
                Product.projectgroupID == self.id, privacy_filter)
Exemplo n.º 11
0
 def getProducts(self, user):
     results = Store.of(self).find(Product, Product.projectgroup == self,
                                   Product.active == True,
                                   ProductSet.getProductPrivacyFilter(user))
     return results.order_by(Product.display_name)
Exemplo n.º 12
0
 def getProducts(self, user):
     results = Store.of(self).find(
         Product, Product.project == self, Product.active == True,
         ProductSet.getProductPrivacyFilter(user))
     return results.order_by(Product.displayname)