356
356
# We join to SourcePackageName, ProductSeries, and Product to cache
357
357
# the objects that are implcitly needed to work with a
358
358
# Packaging object.
359
# Avoid circular import failures.
360
359
joins, conditions = self._current_sourcepackage_joins_and_conditions
361
origin = SQL(joins + """
360
# XXX: EdwinGrubbs 2010-07-29 bug=374777
361
# Storm doesn't support DISTINCT ON.
364
SELECT DISTINCT ON (Packaging.id)
366
spr.component AS spr_component,
367
SourcePackageName.name AS spn_name,
372
AND packaging.id IS NOT NULL
362
374
JOIN ProductSeries
363
375
ON Packaging.productseries = ProductSeries.id
365
377
ON ProductSeries.product = Product.id
367
condition = SQL(conditions + "AND packaging.id IS NOT NULL")
368
results = IStore(self).using(origin).find(Packaging, condition)
369
return results.order_by("""
371
CASE WHEN spr.component = 1 THEN 1000 ELSE 0 END
378
''' % dict(joins=joins, conditions=conditions))
379
return IStore(self).using(origin).find(Packaging).order_by('''
380
(CASE WHEN spr_component = 1 THEN 1000 ELSE 0 END
372
381
+ CASE WHEN Product.bugtracker IS NULL
373
382
THEN coalesce(total_bug_heat, 10) ELSE 0 END
374
383
+ CASE WHEN ProductSeries.translations_autoimport_mode = 1
375
384
THEN coalesce(po_messages, 10) ELSE 0 END
376
+ CASE WHEN ProductSeries.branch IS NULL THEN 500
379
SourcePackageName.name ASC
385
+ CASE WHEN ProductSeries.branch IS NULL THEN 500 ELSE 0 END
383
391
def _current_sourcepackage_joins_and_conditions(self):