1 class QChoicesAtom(QAtom):
2 """This class represents a query for an attribute with a discrete fixed
3 set of choices.
4 """
5 def __init__(self, **kwargs):
6 QAtom.__init__(self, **kwargs)
7
8
9 searchString = " ".join(self.search)
10
11
12 if searchString[0] in "1234556789":
13 search = int(search)
14
15
16
17 else:
18 for i, choice in enumerate(choicesDict[self.attribute]):
19 if choice.match(searchString):
20 search = i
21 break
22
23
24
25
26 try:
27 self.search = search
28 except NameError:
29 raise ValueError(
30 "search not among defined choices for attribute")
31
32
33 def rawQuery(self):
34
35 if self.operator == "exact":
36 operator = (self.negative and " != " or " == ")
37 else:
38 raise ValueError(
39 "operator makes no sense for type/creator code query")
40
41 return self.attribute + operator + str(self.search)