20 __authors__ = [ |
20 __authors__ = [ |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
22 ] |
22 ] |
23 |
23 |
24 |
24 |
|
25 import datetime |
25 import itertools |
26 import itertools |
26 |
27 |
27 from google.appengine.ext.db import users |
28 from google.appengine.api import users |
|
29 from google.appengine.ext import db |
28 |
30 |
29 from soc.models.site import Site |
31 from soc.models.site import Site |
30 from soc.models.user import User |
32 from soc.models.user import User |
31 from soc.models.sponsor import Sponsor |
33 from soc.models.sponsor import Sponsor |
|
34 from soc.models.host import Host |
32 from soc.models.program import Program |
35 from soc.models.program import Program |
33 from soc.models.timeline import Timeline |
36 from soc.models.timeline import Timeline |
34 from soc.models.org_app import OrgApplication |
37 from soc.models.org_app import OrgApplication |
35 from soc.models.organization import Organization |
38 from soc.models.organization import Organization |
|
39 from soc.models.org_admin import OrgAdmin |
|
40 from soc.models.mentor import Mentor |
36 from soc.models.notification import Notification |
41 from soc.models.notification import Notification |
37 |
42 |
38 |
43 |
39 def seed(*args, **kwargs): |
44 def seed(*args, **kwargs): |
40 """Seeds the datastore with some default values. |
45 """Seeds the datastore with some default values. |
41 """ |
46 """ |
42 |
47 |
43 account = users.get_current_user() |
48 account = users.get_current_user() |
44 |
49 |
45 properties = { |
50 if not account: |
|
51 account = users.User(email='test@example.com') |
|
52 |
|
53 user_properties = { |
46 'key_name': 'test', |
54 'key_name': 'test', |
47 'link_id': 'test', |
55 'link_id': 'test', |
48 'account': account, |
56 'account': account, |
49 'agreed_to_tos': True, |
57 'agreed_to_tos': True, |
50 'name': 'Test', |
58 'name': 'Test', |
51 } |
59 } |
52 |
60 |
53 current_user = User(**properties) |
61 current_user = User(**user_properties) |
54 current_user.put() |
62 current_user.put() |
55 |
63 |
56 properties = { |
64 |
|
65 group_properties = { |
57 'key_name': 'google', |
66 'key_name': 'google', |
58 'link_id': 'google', |
67 'link_id': 'google', |
59 'name': 'Google Inc.', |
68 'name': 'Google Inc.', |
60 'short_name': 'Google', |
69 'short_name': 'Google', |
61 'founder': current_user, |
70 'founder': current_user, |
68 'contact_postalcode': '12345', |
77 'contact_postalcode': '12345', |
69 'phone': '1-555-BANANA', |
78 'phone': '1-555-BANANA', |
70 'status': 'active', |
79 'status': 'active', |
71 } |
80 } |
72 |
81 |
73 google = Sponsor(**properties) |
82 google = Sponsor(**group_properties) |
74 google.put() |
83 google.put() |
75 |
84 |
76 |
85 |
77 properties = { |
86 role_properties = { |
|
87 'key_name': 'google/test', |
|
88 'link_id': 'test', |
|
89 'scope': google, |
|
90 'scope_path': 'google', |
|
91 'user': current_user, |
|
92 'given_name': 'Test', |
|
93 'surname': 'Example', |
|
94 'name_on_documents': 'Test Example', |
|
95 'email': 'test@example.com', |
|
96 'res_street': 'Some Street', |
|
97 'res_city': 'Some City', |
|
98 'res_state': 'Some State', |
|
99 'res_country': 'United States', |
|
100 'res_postalcode': '12345', |
|
101 'phone': '1-555-BANANA', |
|
102 'birth_date': db.DateProperty.now(), |
|
103 'agreed_to_tos': True, |
|
104 } |
|
105 |
|
106 |
|
107 google_host = Host(**role_properties) |
|
108 google_host.put() |
|
109 |
|
110 |
|
111 timeline_properties = { |
78 'key_name': 'google/gsoc2009', |
112 'key_name': 'google/gsoc2009', |
79 'scope_path': 'google/gsoc2009', |
113 'scope_path': 'google/gsoc2009', |
80 } |
114 } |
81 |
115 |
82 gsoc2009_timeline = Timeline(**properties) |
116 gsoc2009_timeline = Timeline(**timeline_properties) |
83 gsoc2009_timeline.put() |
117 gsoc2009_timeline.put() |
84 |
118 |
85 |
119 |
86 properties = { |
120 program_properties = { |
87 'key_name': 'google/gsoc2009', |
121 'key_name': 'google/gsoc2009', |
88 'link_id': 'gsoc2009', |
122 'link_id': 'gsoc2009', |
89 'scope_path': 'google', |
123 'scope_path': 'google', |
90 'scope': google, |
124 'scope': google, |
91 'name': 'Google Summer of Code 2009', |
125 'name': 'Google Summer of Code 2009', |
97 'workflow': 'gsoc', |
131 'workflow': 'gsoc', |
98 'timeline': gsoc2009_timeline, |
132 'timeline': gsoc2009_timeline, |
99 'status': 'visible', |
133 'status': 'visible', |
100 } |
134 } |
101 |
135 |
102 gsoc2009 = Program(**properties) |
136 gsoc2009 = Program(**program_properties) |
103 gsoc2009.put() |
137 gsoc2009.put() |
104 |
138 |
105 properties = { |
139 |
|
140 org_app_properties = { |
106 'scope_path': 'google/gsoc2009', |
141 'scope_path': 'google/gsoc2009', |
107 'scope': gsoc2009, |
142 'scope': gsoc2009, |
108 'applicant': current_user, |
143 'applicant': current_user, |
109 'home_page': 'http://www.google.com', |
144 'home_page': 'http://www.google.com', |
110 'email': 'org@example.com', |
145 'email': 'org@example.com', |
120 'continued_contribs': 'We promise them a cake.', |
155 'continued_contribs': 'We promise them a cake.', |
121 'agreed_to_admin_agreement': True, |
156 'agreed_to_admin_agreement': True, |
122 } |
157 } |
123 |
158 |
124 for i in range(15): |
159 for i in range(15): |
125 properties['key_name'] = 'google/gsoc2009/org_%d' % i |
160 org_app_properties['key_name'] = 'google/gsoc2009/org_%d' % i |
126 properties['link_id'] = 'org_%d' % i |
161 org_app_properties['link_id'] = 'org_%d' % i |
127 properties['name'] = 'Organization %d' % i |
162 org_app_properties['name'] = 'Organization %d' % i |
128 entity = OrgApplication(**properties) |
163 entity = OrgApplication(**org_app_properties) |
129 entity.put() |
164 entity.put() |
130 |
165 |
131 properties = { |
166 |
|
167 group_properties.update({ |
132 'key_name': 'google/gsoc2009/melange', |
168 'key_name': 'google/gsoc2009/melange', |
133 'link_id': 'melange', |
169 'link_id': 'melange', |
134 'name': 'Melange Development Team', |
170 'name': 'Melange Development Team', |
135 'short_name': 'Melange', |
171 'short_name': 'Melange', |
136 'scope_path': 'google/gsoc2009', |
172 'scope_path': 'google/gsoc2009', |
137 'scope': gsoc2009, |
173 'scope': gsoc2009, |
138 'founder': current_user, |
|
139 'contact_street': 'Some Street', |
|
140 'contact_city': 'Some City', |
|
141 'contact_country': 'United States', |
|
142 'contact_postalcode': '12345', |
|
143 'phone': '1-555-BANANA', |
|
144 'home_page': 'http://code.google.com/p/soc', |
174 'home_page': 'http://code.google.com/p/soc', |
145 'email': 'ospo@google.com', |
|
146 'description': 'Melange, share the love!', |
175 'description': 'Melange, share the love!', |
147 'status': 'active', |
|
148 'license_name': 'Apache License', |
176 'license_name': 'Apache License', |
149 'ideas': 'http://code.google.com/p/soc/issues', |
177 'ideas': 'http://code.google.com/p/soc/issues', |
150 } |
178 }) |
151 |
179 |
152 melange = Organization(**properties) |
180 melange = Organization(**group_properties) |
153 melange.put() |
181 melange.put() |
|
182 |
|
183 |
|
184 role_properties.update({ |
|
185 'key_name': 'google/gsoc2009/melange/test', |
|
186 'link_id': 'test', |
|
187 'scope_path': 'google/gsoc2009/melange', |
|
188 'scope': melange, |
|
189 }) |
|
190 |
|
191 melange_admin = OrgAdmin(**role_properties) |
|
192 melange_admin.put() |
|
193 |
|
194 melange_mentor = Mentor(**role_properties) |
|
195 melange_mentor.put() |
154 |
196 |
155 return |
197 return |
156 |
198 |
157 |
199 |
158 def clear(*args, **kwargs): |
200 def clear(*args, **kwargs): |
159 """Removes all entities from the datastore. |
201 """Removes all entities from the datastore. |
160 """ |
202 """ |
161 |
203 |
162 entities = itertools.chain(*[ |
204 entities = itertools.chain(*[ |
163 Notification.all(), |
205 Notification.all(), |
|
206 Mentor.all(), |
|
207 OrgAdmin.all(), |
164 Organization.all(), |
208 Organization.all(), |
165 OrgApplication.all(), |
209 OrgApplication.all(), |
166 Timeline.all(), |
210 Timeline.all(), |
167 Program.all(), |
211 Program.all(), |
|
212 Host.all(), |
168 Sponsor.all(), |
213 Sponsor.all(), |
169 User.all(), |
214 User.all(), |
170 Site.all(), |
215 Site.all(), |
171 ]) |
216 ]) |
172 |
217 |