~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

Merged replication into pending-db-changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2298
2298
                "BugTask.datecreated > %s" % (
2299
2299
                    sqlvalues(params.created_since,)))
2300
2300
 
2301
 
        orderby_arg = self._processOrderBy(params)
 
2301
        orderby_arg, extra_joins = self._processOrderBy(params)
 
2302
        join_tables.extend(extra_joins)
2302
2303
 
2303
2304
        query = " AND ".join(extra_clauses)
2304
2305
 
3160
3161
 
3161
3162
    def getOrderByColumnDBName(self, col_name):
3162
3163
        """See `IBugTaskSet`."""
 
3164
        # Avoid circular imports.
 
3165
        from lp.registry.model.milestone import Milestone
3163
3166
        if BugTaskSet._ORDERBY_COLUMN is None:
3164
3167
            # Local import of Bug to avoid import loop.
3165
3168
            from lp.bugs.model.bug import Bug
3182
3185
                "users_affected_count": Bug.users_affected_count,
3183
3186
                "heat": BugTask.heat,
3184
3187
                "latest_patch_uploaded": Bug.latest_patch_uploaded,
 
3188
                "milestone_name": (
 
3189
                    Milestone.name,
 
3190
                    (Milestone,
 
3191
                     LeftJoin(Milestone, BugTask.milestone == Milestone.id))),
3185
3192
                }
3186
3193
        return BugTaskSet._ORDERBY_COLUMN[col_name]
3187
3194
 
3230
3237
 
3231
3238
        # Translate orderby keys into corresponding Table.attribute
3232
3239
        # strings.
 
3240
        extra_joins = []
3233
3241
        ambiguous = True
 
3242
        # Sorting by milestone only is a very "coarse" sort order.
 
3243
        # If no additional sort order is specified, add the bug task
 
3244
        # importance as a secondary sort order.
 
3245
        if len(orderby) == 1:
 
3246
            if orderby[0] == 'milestone_name':
 
3247
                # We want the most important bugtasks first; these have
 
3248
                # larger integer values.
 
3249
                orderby.append('-importance')
 
3250
            elif orderby[0] == '-milestone_name':
 
3251
                orderby.append('importance')
 
3252
            else:
 
3253
                # Other sort orders don't need tweaking.
 
3254
                pass
 
3255
 
3234
3256
        for orderby_col in orderby:
3235
3257
            if isinstance(orderby_col, SQLConstant):
3236
3258
                orderby_arg.append(orderby_col)
3237
3259
                continue
3238
3260
            if orderby_col.startswith("-"):
3239
3261
                col = self.getOrderByColumnDBName(orderby_col[1:])
 
3262
                if isinstance(col, tuple):
 
3263
                    extra_joins.append(col[1])
 
3264
                    col = col[0]
3240
3265
                order_clause = Desc(col)
3241
3266
            else:
3242
3267
                col = self.getOrderByColumnDBName(orderby_col)
 
3268
                if isinstance(col, tuple):
 
3269
                    extra_joins.append(col[1])
 
3270
                    col = col[0]
3243
3271
                order_clause = col
3244
3272
            if col in unambiguous_cols:
3245
3273
                ambiguous = False
3251
3279
            else:
3252
3280
                orderby_arg.append(BugTask.id)
3253
3281
 
3254
 
        return tuple(orderby_arg)
 
3282
        return tuple(orderby_arg), extra_joins
3255
3283
 
3256
3284
    def getBugCountsForPackages(self, user, packages):
3257
3285
        """See `IBugTaskSet`."""