This repository was archived by the owner on May 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGlossaryTermConceptSearch.py
More file actions
executable file
·90 lines (77 loc) · 3.19 KB
/
GlossaryTermConceptSearch.py
File metadata and controls
executable file
·90 lines (77 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
"""Search for CDR GlossaryConceptName documents.
"""
from cdrcgi import AdvancedSearch
class GlossaryTermConceptSearch(AdvancedSearch):
"""Customize search for this document type."""
DOCTYPE = "GlossaryTermConcept"
SUBTITLE = "Glossary Term Concept"
PATHS = {
"concept": [
"/GlossaryTermConcept/TermDefinition/DefinitionText",
"/GlossaryTermConcept/TranslatedTermDefinition/DefinitionText",
],
"audience": [
"/GlossaryTermConcept/TermDefinition/Audience",
"/GlossaryTermConcept/TranslatedTermDefinition/Audience",
],
"dictionary": [
"/GlossaryTermConcept/TermDefinition/Dictionary",
"/GlossaryTermConcept/TranslatedTermDefinition/Dictionary",
],
"stat_en": [
"/GlossaryTermConcept/TermDefinition/DefinitionStatus",
],
"stat_es": [
"/GlossaryTermConcept/TranslatedTermDefinition/TranslatedStatus",
],
}
def __init__(self):
AdvancedSearch.__init__(self)
for name in self.PATHS:
setattr(self, name, self.fields.getvalue(name))
# pylint: disable=no-member
if self.audience and self.audience not in self.audiences:
raise Exception("Tampering with form values")
if self.dictionary and self.dictionary not in self.dictionaries:
raise Exception("Tampering with form values")
if self.stat_en and self.stat_en not in self.statuses_en:
raise Exception("Tampering with form values")
if self.stat_es and self.stat_es not in self.statuses_es:
raise Exception("Tampering with form values")
# pylint: enable=no-member
statuses_en = [""] + self.statuses_en
statuses_es = [""] + self.statuses_es
status_en = "Status (English)"
status_es = "Status (Spanish)"
self.search_fields = (
self.text_field("concept"),
self.select("audience", options=[""]+self.audiences),
self.select("dictionary", options=[""]+self.dictionaries),
self.select("stat_en", label=status_en, options=statuses_en),
self.select("stat_es", label=status_es, options=statuses_es),
)
self.query_fields = []
for name, paths in self.PATHS.items():
field = self.QueryField(getattr(self, name), paths)
self.query_fields.append(field)
@property
def audiences(self):
return self.values_for_paths(self.PATHS["audience"])
@property
def dictionaries(self):
return self.values_for_paths(self.PATHS["dictionary"])
@property
def statuses_en(self):
return self.values_for_paths(self.PATHS["stat_en"])
@property
def statuses_es(self):
return self.values_for_paths(self.PATHS["stat_es"])
def __values_list(self, paths):
"""duplicate????????????"""
query = self.DBQuery("query_term", "value").unique().order("value")
query.where(query.Condition("path", paths, "IN"))
rows = query.execute(self.session.cursor).fetchall()
return [row.value for row in rows]
if __name__ == "__main__":
GlossaryTermConceptSearch().run()