|
1 import itertools |
|
2 |
|
3 from google.appengine.ext.db import users |
|
4 |
|
5 from soc.models.site import Site |
|
6 from soc.models.user import User |
|
7 from soc.models.sponsor import Sponsor |
|
8 from soc.models.program import Program |
|
9 from soc.models.timeline import Timeline |
|
10 from soc.models.org_app import OrgApplication |
|
11 from soc.models.notification import Notification |
|
12 |
|
13 |
|
14 def seed(*args, **kwargs): |
|
15 """Seeds the datastore with some default values. |
|
16 """ |
|
17 |
|
18 account = users.get_current_user() |
|
19 |
|
20 properties = { |
|
21 'key_name': 'test', |
|
22 'link_id': 'test', |
|
23 'account': account, |
|
24 'agreed_to_tos': True, |
|
25 'name': 'Test', |
|
26 } |
|
27 |
|
28 current_user = User(**properties) |
|
29 current_user.put() |
|
30 |
|
31 properties = { |
|
32 'key_name': 'google', |
|
33 'link_id': 'google', |
|
34 'name': 'Google Inc.', |
|
35 'short_name': 'Google', |
|
36 'founder': current_user, |
|
37 'home_page': 'http://www.google.com', |
|
38 'email': 'ospo@google.com', |
|
39 'description': 'This is the profile for Google.', |
|
40 'contact_street': 'Some Street', |
|
41 'contact_city': 'Some City', |
|
42 'contact_country': 'United States', |
|
43 'contact_postalcode': '12345', |
|
44 'phone': '1-555-BANANA', |
|
45 'status': 'active', |
|
46 } |
|
47 |
|
48 google = Sponsor(**properties) |
|
49 google.put() |
|
50 |
|
51 |
|
52 properties = { |
|
53 'key_name': 'google/gsoc2009', |
|
54 'scope_path': 'google/gsoc2009', |
|
55 } |
|
56 |
|
57 gsoc2009_timeline = Timeline(**properties) |
|
58 gsoc2009_timeline.put() |
|
59 |
|
60 |
|
61 properties = { |
|
62 'key_name': 'google/gsoc2009', |
|
63 'link_id': 'gsoc2009', |
|
64 'scope_path': 'google', |
|
65 'scope': google, |
|
66 'name': 'Google Summer of Code 2009', |
|
67 'short_name': 'GSoC 2009', |
|
68 'group_label': 'GSOC', |
|
69 'description': 'This is the program for GSoC 2009.', |
|
70 'apps_tasks_limit': 42, |
|
71 'slots': 42, |
|
72 'workflow': 'gsoc', |
|
73 'timeline': gsoc2009_timeline, |
|
74 'status': 'visible', |
|
75 } |
|
76 |
|
77 gsoc2009 = Program(**properties) |
|
78 gsoc2009.put() |
|
79 |
|
80 properties = { |
|
81 'scope_path': 'google/gsoc2009', |
|
82 'scope': gsoc2009, |
|
83 'applicant': current_user, |
|
84 'home_page': 'http://www.google.com', |
|
85 'email': 'org@example.com', |
|
86 'description': 'This is an awesome org!', |
|
87 'why_applying': 'Because we can', |
|
88 'member_criteria': 'They need to be awesome', |
|
89 'status': 'pre-accepted', |
|
90 'license_name': 'WTFPL', |
|
91 'ideas': 'http://code.google.com/p/soc/issues', |
|
92 'contrib_disappears': 'We use google to find them', |
|
93 'member_disappears': 'See above', |
|
94 'encourage_contribs': 'We offer them cookies.', |
|
95 'continued_contribs': 'We promise them a cake.', |
|
96 'agreed_to_admin_agreement': True, |
|
97 } |
|
98 |
|
99 for i in range(15): |
|
100 properties['key_name'] = 'google/gsoc2009/org_%d' % i |
|
101 properties['link_id'] = 'org_%d' % i |
|
102 properties['name'] = 'Organization %d' % i |
|
103 entity = OrgApplication(**properties) |
|
104 entity.put() |
|
105 |
|
106 return |
|
107 |
|
108 |
|
109 def clear(*args, **kwargs): |
|
110 """Removes all entities from the datastore. |
|
111 """ |
|
112 |
|
113 entities = itertools.chain(*[ |
|
114 Notification.all(), |
|
115 OrgApplication.all(), |
|
116 Timeline.all(), |
|
117 Program.all(), |
|
118 Sponsor.all(), |
|
119 User.all(), |
|
120 Site.all(), |
|
121 ]) |
|
122 |
|
123 for entity in entities: |
|
124 entity.delete() |
|
125 |
|
126 return |
|
127 |
|
128 def reseed(*args, **kwargs): |
|
129 """Clears and seeds the datastore. |
|
130 """ |
|
131 |
|
132 clear(*args, **kwargs) |
|
133 seed(*args, **kwargs) |