1 """
2 Fast Web->DB->JSON machinery, for now only for the portal page. It's
3 not quite clear to me yet what to do with this kind of thing.
4
5 It would seem we could do with more of these very lightweight
6 things; on the other hand, these bypass all metadata mangement...
7 ah, let's see.
8 """
9
10
11
12
13
14
15
16 import json
17
18 from nevow import rend
19 from nevow import inevow
20
21 from gavo import base
22
23
24
25 RESMETA_FIELDS = ("title, accessurl, referenceurl,"
26 " sourcerd, resid, owner, browseable")
27
28
30 """A resource returning Json for the database query given in the
31 query class attribute (and potentially some arguments).
32
33 TODO: we should do some more sensible error handling.
34 """
46
47
49 query = (
50 "SELECT "+RESMETA_FIELDS+
51 " FROM dc.resources"
52 " NATURAL JOIN dc.interfaces"
53 " NATURAL JOIN dc.sets"
54 " WHERE setname='local'"
55 " AND NOT deleted"
56 " ORDER BY title")
57
58
60 query = (
61 "SELECT subject, count(*) as numMatch"
62 " FROM dc.subjects"
63 " NATURAL JOIN dc.sets"
64 " WHERE setname='local'"
65 " AND NOT deleted"
66 " GROUP BY subject"
67 " ORDER BY subject")
68
69
71 query = (
72 "SELECT author, count(*) as numMatch"
73 " FROM dc.authors"
74 " NATURAL JOIN dc.sets"
75 " WHERE setname='local'"
76 " AND NOT deleted"
77 " GROUP BY author"
78 " ORDER BY author")
79
80
81 -class ByFulltext(JSONQuery):
82 query = (
83 "SELECT DISTINCT "+RESMETA_FIELDS+
84 " FROM dc.resources"
85 " NATURAL JOIN dc.interfaces"
86 " NATURAL JOIN dc.subjects"
87 " NATURAL JOIN dc.sets"
88 " WHERE setname='local'"
89 " AND NOT deleted"
90 " AND (to_tsvector('english', description) || to_tsvector(subject) "
91 " || to_tsvector('english', title) || to_tsvector(authors))"
92 " @@ plainto_tsquery(%(q)s)"
93 " ORDER BY title")
94
95
97 query = (
98 "SELECT "+RESMETA_FIELDS+
99 " FROM dc.resources"
100 " NATURAL JOIN dc.interfaces"
101 " NATURAL JOIN dc.subjects"
102 " NATURAL JOIN dc.sets"
103 " WHERE setname='local'"
104 " AND subject=%(subject)s"
105 " AND NOT deleted"
106 " ORDER BY title")
107
108
110 query = (
111 "SELECT "+RESMETA_FIELDS+
112 " FROM dc.resources"
113 " NATURAL JOIN dc.interfaces"
114 " NATURAL JOIN dc.authors"
115 " NATURAL JOIN dc.sets"
116 " WHERE setname='local'"
117 " AND author=%(author)s"
118 " AND NOT deleted"
119 " ORDER BY title")
120
121
123 query = (
124 "SELECT title, description, authors,"
125 " to_char(dateUpdated, 'YYYY-MM-DD') as lastupdate,"
126 " referenceURL, accessURL"
127 " FROM dc.interfaces"
128 " NATURAL JOIN dc.sets"
129 " RIGHT OUTER JOIN dc.resources USING (sourcerd, resid)"
130 " WHERE setname='local'"
131 " AND resId=%(resId)s and sourceRd=%(sourceRD)s")
132
133
134 -class PortalPage(rend.Page):
142