~launchpad-results/launchpad-results/trunk

« back to all changes in this revision

Viewing changes to lib/lpresults/hardware/models/system.py

  • Committer: Marc Tardif
  • Date: 2011-09-28 15:18:09 UTC
  • Revision ID: marc.tardif@canonical.com-20110928151809-rwn04clcebacbnfm
Added processor states for system units.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from lazr.restful.simple import TraverseWithGet
25
25
 
26
26
from lpresults.database.search import search_to_expression
 
27
from lpresults.database.textgrams import get_text_grams_as_text
27
28
from lpresults.database.textsearch import (
28
29
    TSMatch,
29
30
    TSVectorPart,
30
31
    TSVectorValidator,
31
 
    get_search_query,
 
32
    get_grams_query,
32
33
    )
33
34
 
34
35
from lpresults.registry.models.search import SearchSet
44
45
 
45
46
SYSTEM_VALIDATOR = TSVectorValidator(
46
47
    "text_search_vector",
47
 
    TSVectorPart(u"make", weight=u"A"),
48
 
    TSVectorPart(u"model", weight=u"B"))
 
48
    TSVectorPart(u"model", weight=u"A", transform=(get_text_grams_as_text,)),
 
49
    TSVectorPart(u"make", weight=u"B", transform=(get_text_grams_as_text,)))
49
50
 
50
51
 
51
52
class System(UnitTargetMixin):
55
56
    implements(ISystem)
56
57
 
57
58
    id = Int(primary=True, allow_none=False, default=AutoReload)
58
 
    make = Unicode(allow_none=False, validator=SYSTEM_VALIDATOR)
59
59
    model = Unicode(allow_none=False, validator=SYSTEM_VALIDATOR)
 
60
    make = Unicode(validator=SYSTEM_VALIDATOR)
60
61
 
61
62
    text_search_vector = RawStr()
62
63
 
63
 
    def __init__(self, make, model):
 
64
    def __init__(self, model, make=None):
 
65
        self.model = model
64
66
        self.make = make
65
 
        self.model = model
66
67
 
67
68
    @property
68
69
    def __parent__(self):
74
75
 
75
76
    @property
76
77
    def name(self):
77
 
        return u"%s %s" % (self.make, self.model)
 
78
        if self.make:
 
79
            return u"%s %s" % (self.make, self.model)
 
80
        else:
 
81
            return self.model
78
82
 
79
83
 
80
84
class SystemSet(TraverseWithGet, SearchSet):
93
97
    def __parent__(self):
94
98
        return getUtility(IServiceRootResource)
95
99
 
96
 
    def retrieve(self, make, model):
 
100
    def retrieve(self, model, make=None):
97
101
        """See `ISystemSet`."""
98
102
        store = get_hardware_store()
99
 
        system = store.find(System, make=make, model=model).one()
 
103
        system = store.find(System, model=model, make=make).one()
100
104
        if not system:
101
 
            system = System(make, model)
 
105
            system = System(model, make)
102
106
            store.add(system)
103
107
 
104
108
        notify(ObjectCreatedEvent(system))
140
144
        """See SearchSet."""
141
145
        expressions = super(SystemSet, self).buildSearchText(search_text)
142
146
 
143
 
        text_search_query = get_search_query(search_text)
 
147
        text_search_query = get_grams_query(search_text)
144
148
        expressions.append(
145
149
            TSMatch(text_search_query, System.text_search_vector))
146
150