71 |
71 |
72 result = target.copy() |
72 result = target.copy() |
73 result['%s_key' % fieldname] = target[fieldname].key().name() |
73 result['%s_key' % fieldname] = target[fieldname].key().name() |
74 return result |
74 return result |
75 |
75 |
76 def getOrgs(): |
76 |
77 """Returns all orgs as dictionary. |
77 def getEntities(model): |
78 """ |
78 """Returns all users as dictionary. |
79 |
79 """ |
80 from soc.models.organization import Organization |
80 |
81 |
81 def wrapped(): |
82 gen = lambda: Organization.all() |
82 gen = lambda: model.all() |
83 it = interactive.deepFetch(gen) |
83 it = interactive.deepFetch(gen) |
84 |
84 |
85 orgs = [(i.key().name(), i) for i in it] |
85 entities = [(i.key().name(), i) for i in it] |
86 return dict(orgs) |
86 return dict(entities) |
87 |
87 |
88 |
88 return wrapped |
89 def getUsers(): |
|
90 """Returns all Users as dictionary. |
|
91 """ |
|
92 |
|
93 from soc.models.user import User |
|
94 |
|
95 gen = lambda: User.all() |
|
96 it = interactive.deepFetch(gen) |
|
97 |
|
98 users = [(i.key().name(), i) for i in it] |
|
99 return dict(users) |
|
100 |
|
101 |
|
102 def getStudents(): |
|
103 """Returns all Students as dictionary. |
|
104 """ |
|
105 |
|
106 from soc.models.student import Student |
|
107 |
|
108 gen = lambda: Student.all() |
|
109 it = interactive.deepFetch(gen) |
|
110 |
|
111 students = [(i.key().name(), i) for i in it] |
|
112 return dict(students) |
|
113 |
|
114 |
|
115 def getMentors(): |
|
116 """Returns all Mentors as dictionary. |
|
117 """ |
|
118 |
|
119 from soc.models.mentor import Mentor |
|
120 |
|
121 gen = lambda: Mentor.all() |
|
122 it = interactive.deepFetch(gen) |
|
123 |
|
124 mentors = [(i.key().name(), i) for i in it] |
|
125 return dict(mentors) |
|
126 |
|
127 |
|
128 def getOrgAdmins(): |
|
129 """Returns all Organization Administrators as dictionary. |
|
130 """ |
|
131 |
|
132 from soc.models.org_admin import OrgAdmin |
|
133 |
|
134 gen = lambda: OrgAdmin.all() |
|
135 it = interactive.deepFetch(gen) |
|
136 |
|
137 orgAdmins = [(i.key().name(), i) for i in it] |
|
138 return dict(orgAdmins) |
|
139 |
89 |
140 |
90 |
141 def getProps(): |
91 def getProps(): |
142 """Returns all proposals as a list of dictionaries. |
92 """Returns all proposals as a list of dictionaries. |
143 """ |
93 """ |
155 proposals = [i.toDict(key_order) for i in it] |
105 proposals = [i.toDict(key_order) for i in it] |
156 |
106 |
157 return proposals |
107 return proposals |
158 |
108 |
159 |
109 |
160 def getStudentProposals(): |
|
161 """Returns all Student Proposals as dictionary. |
|
162 """ |
|
163 |
|
164 from soc.models.student_proposal import StudentProposal |
|
165 |
|
166 gen = lambda: StudentProposal.all() |
|
167 it = interactive.deepFetch(gen) |
|
168 |
|
169 studentProposals = [(i.key().name(), i) for i in it] |
|
170 |
|
171 return dict(studentProposals) |
|
172 |
|
173 |
|
174 def orgStats(target): |
110 def orgStats(target): |
175 """Retrieves org stats. |
111 """Retrieves org stats. |
176 """ |
112 """ |
177 |
113 |
178 from soc.logic import dicts |
114 from soc.logic import dicts |
185 |
121 |
186 |
122 |
187 def countStudentsWithProposals(): |
123 def countStudentsWithProposals(): |
188 """Retrieves number of Students who have submitted at least one Student Proposal. |
124 """Retrieves number of Students who have submitted at least one Student Proposal. |
189 """ |
125 """ |
190 |
126 |
191 proposals = getStudentProposals() |
127 proposals = getStudentProposals() |
192 students = {} |
128 students = {} |
193 |
129 |
194 for proposal_key in proposals.keys(): |
130 for proposal_key in proposals.keys(): |
195 students[proposals[proposal_key].scope_path] = True |
131 students[proposals[proposal_key].scope_path] = True |
196 |
132 |
197 return len(students) |
133 return len(students) |
198 |
134 |
199 |
135 |
200 def printPopularity(popularity): |
136 def printPopularity(popularity): |
201 """Prints the popularity for the specified proposals. |
137 """Prints the popularity for the specified proposals. |
247 def main(args): |
183 def main(args): |
248 """Main routine. |
184 """Main routine. |
249 """ |
185 """ |
250 |
186 |
251 interactive.setup() |
187 interactive.setup() |
|
188 |
|
189 from soc.models.organization import Organization |
|
190 from soc.models.user import User |
|
191 from soc.models.student import Student |
|
192 from soc.models.mentor import Mentor |
|
193 from soc.models.org_admin import OrgAdmin |
252 |
194 |
253 context = { |
195 context = { |
254 'load': loadPickle, |
196 'load': loadPickle, |
255 'dump': dumpPickle, |
197 'dump': dumpPickle, |
256 'orgStats': orgStats, |
198 'orgStats': orgStats, |
257 'printPopularity': printPopularity, |
199 'printPopularity': printPopularity, |
258 'savePopularity': savePopularity, |
200 'savePopularity': savePopularity, |
259 'getOrgs': getOrgs, |
201 'getOrgs': getEntities(Organization), |
|
202 'getUsers': getEntities(User), |
|
203 'getStudents': getEntities(Student), |
|
204 'getMentors': getEntities(Mentor), |
|
205 'getOrgAdmins': getEntities(OrgAdmins), |
260 'getProps': getProps, |
206 'getProps': getProps, |
261 'getStudents': getStudents, |
207 'countStudentsWithProposals': countStudentsWithProposals, |
262 'getMentors': getMentors, |
|
263 'getOrgAdmins': getOrgAdmins, |
|
264 'getUsers': getUsers, |
|
265 'getStudentProposals': getStudentProposals, |
|
266 'countStudentsWithProposals': countStudentsWithProposals |
|
267 } |
208 } |
268 |
209 |
269 interactive.remote(args, context) |
210 interactive.remote(args, context) |
270 |
211 |
271 if __name__ == '__main__': |
212 if __name__ == '__main__': |