Add Organization Application seeding.
authorDan Bentley <dbentley@google.com>
Mon, 25 May 2009 16:23:16 -0700
changeset 2351 73448b71aa07
parent 2350 a6764395c7e9
child 2352 33ff03da52b6
Add Organization Application seeding. Fix the seeding in seed_db so that a consistent linkid for organization applications is used. Use the last entry in the split array instead of the 2nd.
app/soc/models/seed_db.py
--- a/app/soc/models/seed_db.py	Tue May 26 00:51:33 2009 +0200
+++ b/app/soc/models/seed_db.py	Mon May 25 16:23:16 2009 -0700
@@ -176,6 +176,58 @@
                 gsoc2009=gsoc2009)
 
 
+class OrgApplicationSeeder(Seeder):
+  def type(self):
+    return OrgApplication
+
+  def commonSeedArgs(self, request):
+    _, current_user = ensureUser()
+    gsoc2009 = Program.get_by_key_name('google/gsoc2009')
+
+    if not gsoc2009:
+      raise Error('Run seed_db first')
+
+    status = request.GET.get('status', 'pre-accepted')
+
+    return dict(current_user=current_user,
+                gsoc2009=gsoc2009,
+                status=status)
+
+
+  def seed(self, i, entities=None, current_user=None, gsoc2009=None,
+           status=None):
+    properties = {
+        'key_name': 'google/gsoc2009/org_app_%04d' % i,
+        'link_id': 'org_app_%04d' % i,
+        'name': 'Org App %04d' % i,
+        'scope_path': 'google/gsoc2009',
+        'scope': gsoc2009,
+        'status': status,
+        'applicant': current_user,
+        'home_page': 'http://www.google.com',
+        'email': 'org@example.com',
+        'irc_channel': '#care',
+        'pub_mailing_list': 'http://groups.google.com',
+        'dev_mailing_list': 'http://groups.google.com',
+        'description': 'This is an awesome org!',
+        'why_applying': 'Because we can',
+        'member_criteria': 'They need to be awesome',
+        'license_name': 'Apache License, 2.0',
+        'ideas': 'http://code.google.com/p/soc/issues',
+        'contrib_disappears': 'We use google to find them',
+        'member_disappears': 'See above',
+        'encourage_contribs': 'We offer them cookies.',
+        'continued_contribs': 'We promise them a cake.',
+        'agreed_to_admin_agreement': True,
+        }
+
+    org_application = OrgApplication(**properties)
+    if entities is None:
+      org_application.put()
+    else:
+      entities.append(org_application)
+
+
 def seed(request, *args, **kwargs):
   """Seeds the datastore with some default values.
   """
@@ -322,9 +374,9 @@
     }
 
   for i in range(10):
-    org_app_properties['key_name'] = 'google/gsoc2009/wannabe_%d' % i
-    org_app_properties['link_id'] = 'wannabe_%d' % i
-    org_app_properties['name'] = 'Wannabe %d' % i
+    org_app_properties['key_name'] = 'google/gsoc2009/org_app_%04d' % i
+    org_app_properties['link_id'] = 'org_app_%04d' % i
+    org_app_properties['name'] = 'Org App %04d' % i
     entity = OrgApplication(**org_app_properties)
     entity.put()
 
@@ -577,16 +629,16 @@
 def seed_student(request, i):
   """Returns the properties for a new student entity.
   """
-  
+
   gsoc2009 = Program.get_by_key_name('google/gsoc2009')
   user = User.get_by_key_name('user_%d' % i)
-  
+
   if not gsoc2009:
     raise Error('Run seed_db first')
-    
+
   if not user:
     raise Error('Run seed_many for at least %d users first.' % i)
-    
+
   properties = {
       'key_name':'google/gsoc2009/student_%d' % i,
       'link_id': 'student_%d' % i,
@@ -627,13 +679,13 @@
   mentor = Mentor.get_by_key_name('google/gsoc2009/org_%d/mentor' % i)
   user = User.get_by_key_name('user_%d' % i)
   student = Student.get_by_key_name('google/gsoc2009/student_%d' % i)
-    
+
   if not user:
     raise Error('Run seed_many for at least %d users first.' % i)
 
   if not student:
     raise Error('Run seed_many for at least %d students first.' % i)
-  
+
   if not org:
     raise Error('Run seed_many for at least %d orgs first.' % i)
 
@@ -669,6 +721,7 @@
 SEEDABLE_MODEL_TYPES = {
     'user' : UserSeeder(),
     'organization' : OrganizationSeeder(),
+    'org_application' : OrgApplicationSeeder(),
     }
 
 
@@ -716,7 +769,7 @@
     # so, we look for what's after the _ and turn it into an int.
     link_id = highest_instance.link_id
     if '_' in link_id:
-      start_index = int(link_id.split('_')[1]) + 1
+      start_index = int(link_id.split('_')[-1]) + 1
     else:
       # couldn't find seeded_entities; guessing there are none
       start_index = 0