1
# Copyright 2010 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
11
from storm.expr import (
16
from storm.locals import Max
18
from zope.interface import implements
20
from lazr.delegates import delegates
22
from lp.results.database.search import search_to_expression
24
from lp.results.services.formatters import item_to_tuple
26
from lp.results.interfaces import (
30
TestPersonSearchParams,
33
from lp.results.models.person import (
37
from lp.results.models.testrank import HasTestRankProjectsMixin
38
from lp.results.models.teststat import (
39
HasTestStatPeopleMixin,
45
class TestPerson(TestStatPersonMixin, HasTestRankProjectsMixin):
46
"""Users within the Django authentication system are represented by
49
__slots__ = ("person", "test_run_count", "last_test_run_date",)
51
implements(ITestPerson)
53
delegates(IPerson, context="person")
55
def __init__(self, person, test_run_count, last_test_run_date):
57
self.test_run_count = test_run_count
58
self.last_test_run_date = last_test_run_date
60
def __cmp__(self, other):
61
if ITestPerson.providedBy(other):
64
return cmp(self.person, other)
67
class TestPersonSet(PersonSet, HasTestStatPeopleMixin):
68
"""See `ITestPersonSet`."""
69
implements(ITestPersonSet)
71
search_params_factory = TestPersonSearchParams
73
def buildSearchExpressions(self, search_params):
75
expressions = super(TestPersonSet, self).buildSearchExpressions(
78
if search_params.date_modified:
81
TestStat.date_modified,
82
search_params.date_modified))
84
if search_params.project:
88
search_params.project,
89
modifier=lambda x: x.id))
93
def buildSearchResult(self, search_params):
95
result = super(TestPersonSet, self).buildSearchResult(search_params)
97
return result.group_by(Person)
99
def buildSearchTables(self, search_params):
101
tables = super(TestPersonSet, self).buildSearchTables(search_params)
105
TestStat.person_id == Person.id))
109
def getSearchResultDecorator(self, result):
111
return TestPerson(*result)
113
def getSearchResultTables(self):
115
result_tables = super(TestPersonSet, self).getSearchResultTables()
117
return item_to_tuple(result_tables) + (
118
Alias(Sum(TestStat.counter), name="test_run_count"),
119
Alias(Max(TestStat.date_modified), name="last_test_run_date"),
123
test_person_set = TestPersonSet()