~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/model/bugtask.py

  • Committer: Rick Harding
  • Date: 2012-01-05 21:28:01 UTC
  • mto: This revision was merged to the branch mainline in revision 14648.
  • Revision ID: rick.harding@canonical.com-20120105212801-t96zn8mnegqsa3yy
garden

Show diffs side-by-side

added added

removed removed

Lines of Context:
2368
2368
                "BugTask.datecreated > %s" % (
2369
2369
                    sqlvalues(params.created_since,)))
2370
2370
 
 
2371
        orderby_arg, extra_joins = self._processOrderBy(params)
 
2372
        join_tables.extend(extra_joins)
 
2373
 
2371
2374
        query = " AND ".join(extra_clauses)
2372
2375
 
2373
2376
        if not decorators:
2383
2386
        else:
2384
2387
            with_clause = None
2385
2388
        return (
2386
 
            query, clauseTables, decorator, join_tables,
 
2389
            query, clauseTables, orderby_arg, decorator, join_tables,
2387
2390
            has_duplicate_results, with_clause)
2388
2391
 
2389
2392
    def buildUpstreamClause(self, params):
2641
2644
                    SpecificationBug.specification %s)
2642
2645
                """ % search_value_to_where_condition(linked_blueprints)
2643
2646
 
2644
 
    def buildOrigin(self, join_tables, prejoin_tables, clauseTables,
2645
 
                    start_with=BugTask):
 
2647
    def buildOrigin(self, join_tables, prejoin_tables, clauseTables):
2646
2648
        """Build the parameter list for Store.using().
2647
2649
 
2648
2650
        :param join_tables: A sequence of tables that should be joined
2661
2663
        and in clauseTables. This method ensures that each table
2662
2664
        appears exactly once in the returned sequence.
2663
2665
        """
2664
 
        origin = [start_with]
 
2666
        origin = [BugTask]
2665
2667
        already_joined = set(origin)
2666
2668
        for table, join in join_tables:
2667
2669
            if table is None or table not in already_joined:
2689
2691
        :param args: optional additional BugTaskSearchParams instances,
2690
2692
        """
2691
2693
        orig_store = store = IStore(BugTask)
2692
 
        [query, clauseTables, bugtask_decorator, join_tables,
 
2694
        [query, clauseTables, orderby, bugtask_decorator, join_tables,
2693
2695
        has_duplicate_results, with_clause] = self.buildQuery(params)
2694
2696
        if with_clause:
2695
2697
            store = store.with_(with_clause)
2696
 
        orderby_expression, orderby_joins = self._processOrderBy(params)
2697
2698
        if len(args) == 0:
2698
2699
            if has_duplicate_results:
2699
2700
                origin = self.buildOrigin(join_tables, [], clauseTables)
2700
 
                outer_origin = self.buildOrigin(
2701
 
                     orderby_joins, prejoins, [])
 
2701
                outer_origin = self.buildOrigin([], prejoins, [])
2702
2702
                subquery = Select(BugTask.id, where=SQL(query), tables=origin)
2703
2703
                resultset = store.using(*outer_origin).find(
2704
2704
                    resultrow, In(BugTask.id, subquery))
2705
2705
            else:
2706
 
                origin = self.buildOrigin(
2707
 
                    join_tables + orderby_joins, prejoins, clauseTables)
 
2706
                origin = self.buildOrigin(join_tables, prejoins, clauseTables)
2708
2707
                resultset = store.using(*origin).find(resultrow, query)
2709
2708
            if prejoins:
2710
2709
                decorator = lambda row: bugtask_decorator(row[0])
2711
2710
            else:
2712
2711
                decorator = bugtask_decorator
2713
2712
 
2714
 
            resultset.order_by(orderby_expression)
 
2713
            resultset.order_by(orderby)
2715
2714
            return DecoratedResultSet(resultset, result_decorator=decorator,
2716
2715
                pre_iter_hook=pre_iter_hook)
2717
2716
 
2721
2720
 
2722
2721
        decorators = [bugtask_decorator]
2723
2722
        for arg in args:
2724
 
            [query, clauseTables, decorator, join_tables,
 
2723
            [query, clauseTables, ignore, decorator, join_tables,
2725
2724
             has_duplicate_results, with_clause] = self.buildQuery(arg)
2726
2725
            origin = self.buildOrigin(join_tables, [], clauseTables)
2727
2726
            localstore = store
2746
2745
                bugtask = decorator(bugtask)
2747
2746
            return bugtask
2748
2747
 
2749
 
        origin = self.buildOrigin(
2750
 
            orderby_joins, prejoins, [],
2751
 
            start_with=Alias(resultset._get_select(), "BugTask"))
 
2748
        origin = [Alias(resultset._get_select(), "BugTask")]
2752
2749
        if prejoins:
 
2750
            origin += [join for table, join in prejoins]
2753
2751
            decorator = prejoin_decorator
2754
2752
        else:
2755
2753
            decorator = simple_decorator
2756
2754
 
2757
2755
        result = store.using(*origin).find(resultrow)
2758
 
        result.order_by(orderby_expression)
 
2756
        result.order_by(orderby)
2759
2757
        return DecoratedResultSet(result, result_decorator=decorator,
2760
2758
            pre_iter_hook=pre_iter_hook)
2761
2759