app/soc/models/seed_db.py
changeset 2200 a1a7c262235d
parent 2184 a1bda9afa5d0
child 2351 73448b71aa07
equal deleted inserted replaced
2199:9e22f90ec781 2200:a1a7c262235d
    44 from soc.models.organization import Organization
    44 from soc.models.organization import Organization
    45 from soc.models.org_app import OrgApplication
    45 from soc.models.org_app import OrgApplication
    46 from soc.models.program import Program
    46 from soc.models.program import Program
    47 from soc.models.ranker_root import RankerRoot
    47 from soc.models.ranker_root import RankerRoot
    48 from soc.models.site import Site
    48 from soc.models.site import Site
       
    49 from soc.models.student import Student
    49 from soc.models.student_proposal import StudentProposal
    50 from soc.models.student_proposal import StudentProposal
    50 from soc.models.sponsor import Sponsor
    51 from soc.models.sponsor import Sponsor
    51 from soc.models.timeline import Timeline
    52 from soc.models.timeline import Timeline
    52 from soc.models.user import User
    53 from soc.models.user import User
    53 
    54 
   173 
   174 
   174     return dict(current_user=current_user,
   175     return dict(current_user=current_user,
   175                 gsoc2009=gsoc2009)
   176                 gsoc2009=gsoc2009)
   176 
   177 
   177 
   178 
   178 
       
   179 def seed(request, *args, **kwargs):
   179 def seed(request, *args, **kwargs):
   180   """Seeds the datastore with some default values.
   180   """Seeds the datastore with some default values.
   181   """
   181   """
   182 
   182 
   183   site_properties = {
   183   site_properties = {
   190 
   190 
   191 
   191 
   192   _, current_user = ensureUser()
   192   _, current_user = ensureUser()
   193 
   193 
   194 
   194 
   195   s = UserSeeder()
   195   seeder = UserSeeder()
   196   for i in range(15):
   196   for i in range(15):
   197     s.seed(i)
   197     seeder.seed(i)
   198 
   198 
   199   group_properties = {
   199   group_properties = {
   200        'key_name': 'google',
   200        'key_name': 'google',
   201        'link_id': 'google',
   201        'link_id': 'google',
   202        'name': 'Google Inc.',
   202        'name': 'Google Inc.',
   515 
   515 
   516   if not gsoc2009:
   516   if not gsoc2009:
   517     raise Error('Run seed_db first')
   517     raise Error('Run seed_db first')
   518 
   518 
   519   properties = {
   519   properties = {
   520       'key_name': 'google/gsoc2009/%d' % i,
   520       'key_name': 'google/gsoc2009/org_%d' % i,
   521       'link_id': 'org_%d' % i,
   521       'link_id': 'org_%d' % i,
   522       'name': 'Organization %d' % i,
   522       'name': 'Organization %d' % i,
   523       'short_name': 'Org %d' % i,
   523       'short_name': 'Org %d' % i,
   524       'founder': current_user,
   524       'founder': current_user,
   525       'scope_path': 'google/gsoc2009',
   525       'scope_path': 'google/gsoc2009',
   543 def seed_mentor(request, i):
   543 def seed_mentor(request, i):
   544   """Returns the properties of a new student proposal.
   544   """Returns the properties of a new student proposal.
   545   """
   545   """
   546 
   546 
   547   _, current_user = ensureUser()
   547   _, current_user = ensureUser()
   548   org = Organization.get_by_key_name('google/gsoc2009/%d' % i)
   548   org = Organization.get_by_key_name('google/gsoc2009/org_%d' % i)
   549 
   549 
   550   if not org:
   550   if not org:
   551     raise Error('Run seed_many for at least %d orgs first.' % i)
   551     raise Error('Run seed_many for at least %d orgs first.' % i)
   552 
   552 
   553   properties = {
   553   properties = {
   571       'program': org.scope,
   571       'program': org.scope,
   572       }
   572       }
   573 
   573 
   574   return properties
   574   return properties
   575 
   575 
       
   576 
       
   577 def seed_student(request, i):
       
   578   """Returns the properties for a new student entity.
       
   579   """
       
   580   
       
   581   gsoc2009 = Program.get_by_key_name('google/gsoc2009')
       
   582   user = User.get_by_key_name('user_%d' % i)
       
   583   
       
   584   if not gsoc2009:
       
   585     raise Error('Run seed_db first')
       
   586     
       
   587   if not user:
       
   588     raise Error('Run seed_many for at least %d users first.' % i)
       
   589     
       
   590   properties = {
       
   591       'key_name':'google/gsoc2009/student_%d' % i,
       
   592       'link_id': 'student_%d' % i,
       
   593       'scope_path': 'google/gsoc2009',
       
   594       'scope': gsoc2009,
       
   595       'user' : user,
       
   596       'given_name': 'Student %d' % i,
       
   597       'surname': 'Last Name',
       
   598       'name_on_documents': 'Test Example',
       
   599       'email': 'test@example.com',
       
   600       'res_street': 'Some Street',
       
   601       'res_city': 'Some City',
       
   602       'res_state': 'Some State',
       
   603       'res_country': 'United States',
       
   604       'res_postalcode': '12345',
       
   605       'phone': '1-555-BANANA',
       
   606       'birth_date': db.DateProperty.now(),
       
   607       'agreed_to_tos': True,
       
   608       'school_name': 'School %d' % i,
       
   609       'school_country': 'United States',
       
   610       'major': 'Computer Science',
       
   611       'degree': 'Undergraduate',
       
   612       'expected_graduation': 2012,
       
   613       'program_knowledge': 'Knowledge %d' % i,
       
   614       'school': None,
       
   615       'can_we_contact_you': True,
       
   616   }
       
   617 
       
   618   return properties
       
   619 
       
   620 
   576 def seed_student_proposal(request, i):
   621 def seed_student_proposal(request, i):
   577   """Returns the properties of a new student proposal.
   622   """Returns the properties of a new student proposal.
   578   """
   623   """
   579 
   624 
   580   _, current_user = ensureUser()
   625   ensureUser()
   581   org = Organization.get_by_key_name('google/gsoc2009/%d' % i)
   626   org = Organization.get_by_key_name('google/gsoc2009/org_%d' % i)
   582   mentor = Mentor.get_by_key_name('google/gsoc2009/org_%d/mentor' % i)
   627   mentor = Mentor.get_by_key_name('google/gsoc2009/org_%d/mentor' % i)
   583 
   628   user = User.get_by_key_name('user_%d' % i)
       
   629   student = Student.get_by_key_name('google/gsoc2009/student_%d' % i)
       
   630     
       
   631   if not user:
       
   632     raise Error('Run seed_many for at least %d users first.' % i)
       
   633 
       
   634   if not student:
       
   635     raise Error('Run seed_many for at least %d students first.' % i)
       
   636   
   584   if not org:
   637   if not org:
   585     raise Error('Run seed_many for at least %d orgs first.' % i)
   638     raise Error('Run seed_many for at least %d orgs first.' % i)
   586 
   639 
   587   if not mentor:
   640   if not mentor:
   588     raise Error('Run seed_many for at least %d mentors first.' % i)
   641     raise Error('Run seed_many for at least %d mentors first.' % i)
   589 
   642 
   590   all_properties = []
   643   all_properties = []
   591 
   644 
   592   for i in range(random.randint(5, 20)):
   645   for i in range(random.randint(5, 20)):
   593     link_id = 'proposal_%s_%d' % (org.key().id_or_name(), i)
   646     link_id = 'proposal_%s_%d' % (org.link_id, i)
   594     scope_path = current_user.key().id_or_name()
   647     scope_path = 'google/gsoc2009/' + user.link_id
   595 
   648 
   596     properties = {
   649     properties = {
   597         'link_id': link_id,
   650         'link_id': link_id,
   598         'scope_path': scope_path,
   651         'scope_path': scope_path,
   599         'scope': current_user,
   652         'scope': student,
   600         'key_name': '%s/%s' % (scope_path, link_id),
   653         'key_name': '%s/%s' % (scope_path, link_id),
   601         'title':'The Awesome Proposal',
   654         'title': 'The Awesome Proposal %s %d' % (user.link_id, i),
   602         'abstract': 'This is an Awesome Proposal, look at its awesomeness!',
   655         'abstract': 'This is an Awesome Proposal, look at its awesomeness!',
   603         'content': 'Sorry, too Awesome for you to read!',
   656         'content': 'Sorry, too Awesome for you to read!',
   604         'additional_info': 'http://www.zipit.com',
   657         'additional_info': 'http://www.zipit.com',
   605         'mentor': mentor,
   658         'mentor': mentor,
   606         'status': 'pending',
   659         'status': 'pending',
   711   seed_types = {
   764   seed_types = {
   712     'user': (seed_user, User),
   765     'user': (seed_user, User),
   713     'org': (seed_org, Organization),
   766     'org': (seed_org, Organization),
   714     'org_app': (seed_org_app, OrgApplication),
   767     'org_app': (seed_org_app, OrgApplication),
   715     'mentor': (seed_mentor, Mentor),
   768     'mentor': (seed_mentor, Mentor),
       
   769     'student': (seed_student, Student),
   716     'student_proposal': (seed_student_proposal, StudentProposal),
   770     'student_proposal': (seed_student_proposal, StudentProposal),
   717     }
   771     }
   718 
   772 
   719   goal = int(get_args['goal'])
   773   goal = int(get_args['goal'])
   720   start = int(get_args['start'])
   774   start = int(get_args['start'])
   768   # this method will not clear all instances.  Instead, it should continually
   822   # this method will not clear all instances.  Instead, it should continually
   769   # call .all(), delete all those, and loop until .all() is empty.
   823   # call .all(), delete all those, and loop until .all() is empty.
   770   entities = itertools.chain(*[
   824   entities = itertools.chain(*[
   771       Notification.all(),
   825       Notification.all(),
   772       Mentor.all(),
   826       Mentor.all(),
       
   827       Student.all(),
   773       OrgAdmin.all(),
   828       OrgAdmin.all(),
   774       ranker.all(),
   829       ranker.all(),
   775       RankerRoot.all(),
   830       RankerRoot.all(),
   776       StudentProposal.all(),
   831       StudentProposal.all(),
   777       Organization.all(),
   832       Organization.all(),