app/soc/models/seed_db.py
changeset 1905 8065fd1f3e4c
parent 1904 63b026919efd
child 1906 224f597846b5
equal deleted inserted replaced
1904:63b026919efd 1905:8065fd1f3e4c
    22   ]
    22   ]
    23 
    23 
    24 
    24 
    25 import datetime
    25 import datetime
    26 import itertools
    26 import itertools
       
    27 import random
    27 
    28 
    28 from google.appengine.api import users
    29 from google.appengine.api import users
    29 from google.appengine.api import memcache
    30 from google.appengine.api import memcache
    30 from google.appengine.ext import db
    31 from google.appengine.ext import db
    31 
    32 
    43 from soc.models.organization import Organization
    44 from soc.models.organization import Organization
    44 from soc.models.org_app import OrgApplication
    45 from soc.models.org_app import OrgApplication
    45 from soc.models.program import Program
    46 from soc.models.program import Program
    46 from soc.models.ranker_root import RankerRoot
    47 from soc.models.ranker_root import RankerRoot
    47 from soc.models.site import Site
    48 from soc.models.site import Site
       
    49 from soc.models.student_proposal import StudentProposal
    48 from soc.models.sponsor import Sponsor
    50 from soc.models.sponsor import Sponsor
    49 from soc.models.timeline import Timeline
    51 from soc.models.timeline import Timeline
    50 from soc.models.user import User
    52 from soc.models.user import User
    51 
    53 
    52 
    54 
   439       'program': org.scope,
   441       'program': org.scope,
   440       }
   442       }
   441 
   443 
   442   return properties
   444   return properties
   443 
   445 
       
   446 def seed_student_proposal(request, i):
       
   447   """Returns the properties of a new student proposal.
       
   448   """
       
   449 
       
   450   account, current_user = ensureUser()
       
   451   org = Organization.get_by_key_name('google/gsoc2009/%d' % i)
       
   452   mentor = Mentor.get_by_key_name('google/gsoc2009/org_%d/mentor' % i)
       
   453 
       
   454   if not org:
       
   455     raise Error('Run seed_many for at least %d orgs first.' % i)
       
   456 
       
   457   if not mentor:
       
   458     raise Error('Run seed_many for at least %d mentors first.' % i)
       
   459 
       
   460   all_properties = []
       
   461 
       
   462   for i in range(random.randint(5, 20)):
       
   463     link_id = 'proposal_%s_%d' % (org.key().name(), i)
       
   464     scope_path = current_user.key().name()
       
   465 
       
   466     properties = {
       
   467         'link_id': link_id,
       
   468         'scope_path': scope_path,
       
   469         'scope': current_user,
       
   470         'key_name': '%s/%s' % (scope_path, link_id),
       
   471         'title':'The Awesome Proposal',
       
   472         'abstract': 'This is an Awesome Proposal, look at its awesomeness!',
       
   473         'content': 'Sorry, too Awesome for you to read!',
       
   474         'additional_info': 'http://www.zipit.com',
       
   475         'mentor': mentor,
       
   476         'status': 'pending',
       
   477         'org': org,
       
   478         'program': org.scope,
       
   479         }
       
   480 
       
   481     all_properties.append(properties)
       
   482 
       
   483   return all_properties
   444 
   484 
   445 def seed_many(request, *args, **kwargs):
   485 def seed_many(request, *args, **kwargs):
   446   """Seeds many instances of the specified type.
   486   """Seeds many instances of the specified type.
   447   """
   487   """
   448 
   488 
   453 
   493 
   454   seed_types = {
   494   seed_types = {
   455     'user': (seed_user, User),
   495     'user': (seed_user, User),
   456     'org': (seed_org, Organization),
   496     'org': (seed_org, Organization),
   457     'mentor': (seed_mentor, Mentor),
   497     'mentor': (seed_mentor, Mentor),
       
   498     'student_proposal': (seed_student_proposal, StudentProposal),
   458     }
   499     }
   459 
   500 
   460   goal = int(get_args['goal'])
   501   goal = int(get_args['goal'])
   461   start = int(get_args['start'])
   502   start = int(get_args['start'])
   462   end = int(get_args['end'])
   503   end = int(get_args['end'])