31 |
31 |
32 from django import http |
32 from django import http |
33 |
33 |
34 from soc.logic.models.ranker_root import logic as ranker_root_logic |
34 from soc.logic.models.ranker_root import logic as ranker_root_logic |
35 from soc.logic import accounts |
35 from soc.logic import accounts |
|
36 from soc.logic import dicts |
36 from soc.models import student_proposal |
37 from soc.models import student_proposal |
37 from soc.models.document import Document |
38 from soc.models.document import Document |
38 from soc.models.host import Host |
39 from soc.models.host import Host |
39 from soc.models.mentor import Mentor |
40 from soc.models.mentor import Mentor |
40 from soc.models.notification import Notification |
41 from soc.models.notification import Notification |
47 from soc.models.sponsor import Sponsor |
48 from soc.models.sponsor import Sponsor |
48 from soc.models.timeline import Timeline |
49 from soc.models.timeline import Timeline |
49 from soc.models.user import User |
50 from soc.models.user import User |
50 |
51 |
51 |
52 |
|
53 class Error(Exception): |
|
54 pass |
|
55 |
|
56 |
|
57 def ensureUser(): |
|
58 """Returns the current user account and associated user object. |
|
59 """ |
|
60 |
|
61 account = accounts.getCurrentAccount() |
|
62 |
|
63 if not account: |
|
64 account = users.User(email='test@example.com') |
|
65 |
|
66 user_properties = { |
|
67 'key_name': 'test', |
|
68 'link_id': 'test', |
|
69 'account': account, |
|
70 'name': 'Test', |
|
71 } |
|
72 |
|
73 current_user = User(**user_properties) |
|
74 current_user.put() |
|
75 |
|
76 return account, current_user |
|
77 |
|
78 |
52 def seed(request, *args, **kwargs): |
79 def seed(request, *args, **kwargs): |
53 """Seeds the datastore with some default values. |
80 """Seeds the datastore with some default values. |
54 |
81 |
55 Understands the following GET args: |
82 Understands the following GET args: |
56 many_users: create 200 users instead of 15, out of which 100 have |
83 many_users: create 200 users instead of 15, out of which 100 have |
78 |
105 |
79 site = Site(**site_properties) |
106 site = Site(**site_properties) |
80 site.put() |
107 site.put() |
81 |
108 |
82 |
109 |
83 account = accounts.getCurrentAccount() |
110 account, current_user = ensureUser() |
84 |
111 |
85 if not account: |
112 |
86 account = users.User(email='test@example.com') |
113 for i in range(15): |
87 |
|
88 user_properties = { |
|
89 'key_name': 'test', |
|
90 'link_id': 'test', |
|
91 'account': account, |
|
92 'name': 'Test', |
|
93 } |
|
94 |
|
95 current_user = User(**user_properties) |
|
96 current_user.put() |
|
97 |
|
98 |
|
99 many_users = get_args.get('many_users') |
|
100 user_goal = int(get_args.get('user_goal', '0')) |
|
101 user_start = int(get_args.get('user_start', '0')) |
|
102 user_end = int(get_args.get('user_end', '0')) |
|
103 user_step = int(get_args.get('user_step', '15')) |
|
104 user_only = get_args.get('user_only') or user_goal |
|
105 |
|
106 for i in range(100 if many_users else 15): |
|
107 user_properties = { |
114 user_properties = { |
108 'key_name': 'user_%d' % i, |
115 'key_name': 'user_%d' % i, |
109 'link_id': 'user_%d' % i, |
116 'link_id': 'user_%d' % i, |
110 'account': users.User(email='user_%d@example.com' % i), |
117 'account': users.User(email='user_%d@example.com' % i), |
111 'name': 'User %d' % i, |
118 'name': 'User %d' % i, |
112 } |
119 } |
113 entity = User(**user_properties) |
120 entity = User(**user_properties) |
114 entity.put() |
121 entity.put() |
115 |
|
116 |
|
117 for i in range(100, 200) if many_users else []: |
|
118 user_properties = { |
|
119 'key_name': 'user_%d' % i, |
|
120 'link_id': 'user_%d' % i, |
|
121 'account': users.User(email='user_%d' % i), |
|
122 'name': 'User %d' % i, |
|
123 } |
|
124 entity = User(**user_properties) |
|
125 entity.put() |
|
126 |
|
127 |
|
128 for i in range(user_start, user_end) if (user_start and user_end) else []: |
|
129 user_properties = { |
|
130 'key_name': 'lots_user_%d' % i, |
|
131 'link_id': 'lots_user_%d' % i, |
|
132 'account': users.User(email='lots_user_%d@example.com' % i), |
|
133 'name': 'Lots User %d' % i, |
|
134 } |
|
135 entity = User(**user_properties) |
|
136 entity.put() |
|
137 |
|
138 |
|
139 if user_end < user_goal: |
|
140 url = '/seed_db?user_start=%d&user_end=%d&user_goal=%d' % ( |
|
141 user_start+user_step, user_end+user_step, user_goal) |
|
142 return http.HttpResponseRedirect(url) |
|
143 |
|
144 if user_only: |
|
145 return http.HttpResponse('Done with users') |
|
146 |
122 |
147 |
123 |
148 group_properties = { |
124 group_properties = { |
149 'key_name': 'google', |
125 'key_name': 'google', |
150 'link_id': 'google', |
126 'link_id': 'google', |
270 'encourage_contribs': 'We offer them cookies.', |
244 'encourage_contribs': 'We offer them cookies.', |
271 'continued_contribs': 'We promise them a cake.', |
245 'continued_contribs': 'We promise them a cake.', |
272 'agreed_to_admin_agreement': True, |
246 'agreed_to_admin_agreement': True, |
273 } |
247 } |
274 |
248 |
275 for i in range(200 if many_orgs else 10): |
249 for i in range(10): |
276 org_app_properties['key_name'] = 'google/gsoc2009/wannabe_%d' % i |
250 org_app_properties['key_name'] = 'google/gsoc2009/wannabe_%d' % i |
277 org_app_properties['link_id'] = 'wannabe_%d' % i |
251 org_app_properties['link_id'] = 'wannabe_%d' % i |
278 org_app_properties['name'] = 'Wannabe %d' % i |
252 org_app_properties['name'] = 'Wannabe %d' % i |
279 entity = OrgApplication(**org_app_properties) |
253 entity = OrgApplication(**org_app_properties) |
280 entity.put() |
254 entity.put() |
281 |
255 |
282 |
256 |
283 org_app_properties['status'] = 'pre-rejected' |
257 org_app_properties['status'] = 'pre-rejected' |
284 |
258 |
285 for i in range(200, 400) if many_orgs else []: |
259 for i in range(10, 20): |
286 org_app_properties['key_name'] = 'google/gsoc2009/loser_%d' % i |
260 org_app_properties['key_name'] = 'google/gsoc2009/loser_%d' % i |
287 org_app_properties['link_id'] = 'loser_%d' % i |
261 org_app_properties['link_id'] = 'loser_%d' % i |
288 org_app_properties['name'] = 'Loser %d' % i |
262 org_app_properties['name'] = 'Loser %d' % i |
289 entity = OrgApplication(**org_app_properties) |
263 entity = OrgApplication(**org_app_properties) |
290 entity.put() |
264 entity.put() |
313 group_properties.update({ |
287 group_properties.update({ |
314 'scope_path': 'google/gsoc2009', |
288 'scope_path': 'google/gsoc2009', |
315 'scope': gsoc2009, |
289 'scope': gsoc2009, |
316 }) |
290 }) |
317 |
291 |
318 for i in range(200 if many_orgs else 15): |
292 for i in range(15): |
319 group_properties.update({ |
293 group_properties.update({ |
320 'key_name': 'google/gsoc2009/org_%d' % i, |
294 'key_name': 'google/gsoc2009/org_%d' % i, |
321 'link_id': 'org_%d' % i, |
295 'link_id': 'org_%d' % i, |
322 'name': 'Organization %d' % i, |
296 'name': 'Organization %d' % i, |
323 'short_name': 'Org %d' % i, |
297 'short_name': 'Org %d' % i, |