예제 #1
0
    def testStudentsInfoList(self):
        """Tests the studentsInfoList component of the dashboard.
    """
        student = GCIProfileHelper(
            self.gci,
            self.dev_test).createOtherUser('*****@*****.**').createStudent()
        info = student.student_info
        #We do this because currently the seeder can not seed the
        #BlobReference properties. What we do below is not correct in practice, but
        #is ok for testing purpose.
        consent_form = blobstore.BlobKey(
            'I cant allow u to participate in GCI :P')
        info.consent_form = consent_form
        info.put()

        score_properties = {
            'points': 5,
            'program': self.gci,
            'parent': student
        }
        score = GCIScore(**score_properties)
        score.put()

        idx = 1
        #Set the current user to be the host.
        self.data.createHost()
        response = self.get(self.url)
        self.assertStudentsInfoTemplatesUsed(response)

        response = self.getListResponse(self.url, idx)
        self.assertIsJsonResponse(response)

        data = self.getListData(self.url, idx)
        self.assertEqual(len(data), 1)

        #Only the consent form has been submitted.
        self.assertEqual(data[0]['columns']['consent_form'], 'Yes')
        self.assertEqual(data[0]['columns']['student_id_form'], 'No')

        #Case when both the forms have been submitted.
        student_id_form = blobstore.BlobKey('student_id')
        info.student_id_form = student_id_form
        info.put()
        data = self.getListData(self.url, idx)
        self.assertEqual(len(data), 1)
        self.assertEqual(data[0]['columns']['consent_form'], 'Yes')
        self.assertEqual(data[0]['columns']['student_id_form'], 'Yes')

        #Case when none of the two forms have been submitted.
        info.consent_form = None
        info.student_id_form = None
        info.put()
        data = self.getListData(self.url, idx)
        self.assertEqual(len(data), 1)
        list_fields = data[0]['columns']
        self.assertEqual(list_fields['consent_form'], 'No')
        self.assertEqual(list_fields['student_id_form'], 'No')
        self.assertEqual(list_fields['name'], student.name())
        self.assertEqual(list_fields['link_id'], student.link_id)
        self.assertEqual(list_fields['email'], student.email)
예제 #2
0
파일: ranking.py 프로젝트: adviti/melange
  def update_ranking_txn():
    logging.info("updateScore txn starts for task %s" % task_key.id())
    query = GCIScore.all().ancestor(student)
    score = query.get()

    # create a new GCIStore entity if one does not exist yet
    if not score:
      logging.info("score entity is being created")
      score = GCIScore(parent=student, program=program)

    # check if the task has been included in the score
    if task_key not in score.tasks:
      score.points += POINTS[task.difficulty_level]
      score.tasks.append(task_key)

    # TODO(dhans): optimize it; sometimes, put may not be needed
    logging.info("score put")
    score.put()
    logging.info("score put returned")

    query = GCIStudentInfo.all().ancestor(student)
    student_info = query.get()

    # set in student info that the student has completed a task
    if not student_info.task_closed:
      student_info.task_closed = True
      student_info.put()
예제 #3
0
  def testStudentsInfoList(self):
    """Tests the studentsInfoList component of the dashboard.
    """
    student = GCIProfileHelper(self.gci, self.dev_test).createOtherUser(
        '*****@*****.**').createStudent()
    info = student.student_info
    #We do this because currently the seeder can not seed the
    #BlobReference properties. What we do below is not correct in practice, but
    #is ok for testing purpose. 
    consent_form = blobstore.BlobKey('I cant allow u to participate in GCI :P')
    info.consent_form = consent_form
    info.put() 
    
    score_properties = {'points': 5, 'program': self.gci, 'parent': student}
    score = GCIScore(**score_properties)
    score.put()

    
    idx = 1
    #Set the current user to be the host.
    self.data.createHost()
    response = self.get(self.url)
    #print response
    self.assertStudentsInfoTemplatesUsed(response)
    response = self.getListResponse(self.url, idx)
    #print response
    
    self.assertIsJsonResponse(response)
    
    data = self.getListData(self.url, idx)
    #print data
    self.assertEqual(len(data), 1)
    #Only the consent form has been submitted.
    self.assertEqual(data[0]['columns']['consent_form'], 'Yes')
    self.assertEqual(data[0]['columns']['student_id_form'], 'No')
    
    #Case when both the forms have been submitted.
    student_id_form = blobstore.BlobKey('student_id')
    info.student_id_form = student_id_form
    info.put()
    data = self.getListData(self.url, idx)
    self.assertEqual(len(data), 1)
    self.assertEqual(data[0]['columns']['consent_form'], 'Yes')
    self.assertEqual(data[0]['columns']['student_id_form'], 'Yes')
    
    #Case when none of the two forms are submitted.
    info.consent_form = None
    info.student_id_form = None
    info.put()
    data = self.getListData(self.url, idx)
    self.assertEqual(len(data), 1)
    list_fields = data[0]['columns']
    self.assertEqual(list_fields['consent_form'], 'No')
    self.assertEqual(list_fields['student_id_form'], 'No')
    self.assertEqual(list_fields['name'], student.name())
    self.assertEqual(list_fields['link_id'], student.link_id)
    self.assertEqual(list_fields['email'], student.email)
예제 #4
0
  def testStudentsInfoList(self):
    """Tests the studentsInfoList component of the dashboard."""
    forms_helper = forms_to_submit_utils.FormsToSubmitHelper()
    student_data_properties = {
        'consent_form': forms_helper.createBlobStoreForm()
        }
    student = profile_utils.seedNDBStudent(
        self.program, student_data_properties=student_data_properties)

    score_properties = {
        'points': 5,
        'program': self.program,
        'parent': student.key.to_old_key()
        }
    score = GCIScore(**score_properties)
    score.put()

    # set the current user to be the host.
    user = profile_utils.seedNDBUser(host_for=[self.program])
    profile_utils.loginNDB(user)
    response = self.get(self.url)
    self.assertStudentsInfoTemplatesUsed(response)

    idx = 1
    response = self.getListResponse(self.url, idx)
    self.assertIsJsonResponse(response)

    data = self.getListData(self.url, idx)
    self.assertEqual(len(data), 1)

    # Only the consent form has been submitted.
    self.assertEqual(data[0]['columns']['consent_form'], 'Yes')
    self.assertEqual(data[0]['columns']['enrollment_form'], 'No')

    # Case when both the forms have been submitted.
    student.student_data.enrollment_form = forms_helper.createBlobStoreForm()
    student.put()

    data = self.getListData(self.url, idx)
    self.assertEqual(len(data), 1)
    self.assertEqual(data[0]['columns']['consent_form'], 'Yes')
    self.assertEqual(data[0]['columns']['enrollment_form'], 'Yes')

    # Case when none of the two forms have been submitted.
    student.student_data.enrollment_form = None
    student.student_data.consent_form = None
    student.put()

    data = self.getListData(self.url, idx)
    self.assertEqual(len(data), 1)
    list_fields = data[0]['columns']
    self.assertEqual(list_fields['consent_form'], 'No')
    self.assertEqual(list_fields['enrollment_form'], 'No')
    self.assertEqual(list_fields['public_name'], student.public_name)
    self.assertEqual(list_fields['profile_id'], student.profile_id)
    self.assertEqual(list_fields['email'], student.contact.email)
예제 #5
0
def convertGCIProfileDBEntityGroup(profile_key):
    """Converts DB based part of entity group associated with the specified
  profile.

  Args:
    profile_key: db.Key of the profile to process.
  """
    to_delete = []
    do_put = True

    org_scores = GCIOrgScore.all().ancestor(profile_key).fetch(1000)
    for org_score in org_scores:
        new_org_score = _convertParent(org_score)
        if do_put:
            new_org_score.put()
        to_delete.append(org_score)

    scores = GCIScore.all().ancestor(profile_key).fetch(1000)
    for score in scores:
        new_score = _convertParent(score)
        if do_put:
            new_score.put()
        to_delete.append(score)

    db.delete(to_delete)
예제 #6
0
  def getListData(self):
    idx = lists.getListIndex(self.request)

    if idx != self.idx:
      return None

    q = GCIScore.all()

    q.filter('program', self.data.program)

    starter = lists.keyStarter

    def prefetcher(entities):
      keys = []

      for entity in entities:
        key = entity.parent_key()
        if key:
          keys.append(key)
      
      entities = db.get(keys)
      sp = dict((i.key(), i) for i in entities if i)

      return ([sp], {})

    response_builder = lists.RawQueryContentResponseBuilder(
        self.request, self._list_config, q, starter, prefetcher=prefetcher)

    return response_builder.build()
예제 #7
0
파일: ranking.py 프로젝트: adviti/melange
def allScoresForProgramQuery(program):
  """Returns the query to fetch all the scores for the specified program.

  Args:
    program: GCIProgram entity for which the query should filter the program 
  """
  return GCIScore.all().filter('program =', program)
예제 #8
0
def convertGCIProfileDBEntityGroup(profile_key):
  """Converts DB based part of entity group associated with the specified
  profile.

  Args:
    profile_key: db.Key of the profile to process.
  """
  to_delete = []
  do_put = True

  org_scores = GCIOrgScore.all().ancestor(profile_key).fetch(1000)
  for org_score in org_scores:
    new_org_score = _convertParent(org_score)
    if do_put:
      new_org_score.put()
    to_delete.append(org_score)

  scores = GCIScore.all().ancestor(profile_key).fetch(1000)
  for score in scores:
    new_score = _convertParent(score)
    if do_put:
      new_score.put()
    to_delete.append(score)

  db.delete(to_delete)
예제 #9
0
def allScoresForProgramQuery(program):
    """Returns the query to fetch all the scores for the specified program.

  Args:
    program: GCIProgram entity for which the query should filter the program
  """
    return GCIScore.all().filter('program =', program)
예제 #10
0
def get(profile):
    """Gets the score entity associated with the specified profile.

  Args:
    profile: GCIProfile entity to retrieve a score for
  """
    query = GCIScore.all().ancestor(profile)
    return query.get()
예제 #11
0
파일: ranking.py 프로젝트: adviti/melange
def get(profile):
  """Gets the score entity associated with the specified profile.

  Args:
    profile: GCIProfile entity to retrieve a score for
  """
  query = GCIScore.all().ancestor(profile)
  return query.get()
예제 #12
0
    def update_ranking_txn():
        logging.info("updateScore txn starts for task %s", task_key.id())
        query = GCIScore.all().ancestor(student)
        score = query.get()

        # create a new GCIStore entity if one does not exist yet
        if not score:
            score = GCIScore(parent=student, program=program)

        # check if the task has been included in the score
        if task_key not in score.tasks:
            if not task.points_invalidated:
                score.points += POINTS[task.difficulty_level]
            score.tasks.append(task_key)

        score.put()

        query = GCIStudentInfo.all().ancestor(student)
        student_info = query.get()

        # set in student info that the student has completed a task
        if not student_info.task_closed:
            student_info.task_closed = True
            student_info.put()
예제 #13
0
  def update_ranking_txn():
    logging.info("updateScore txn starts for task %s", task_key.id())
    query = GCIScore.all().ancestor(student)
    score = query.get()

    # create a new GCIStore entity if one does not exist yet
    if not score:
      score = GCIScore(parent=student, program=program)

    # check if the task has been included in the score
    if task_key not in score.tasks:
      if not task.points_invalidated:
        score.points += POINTS[task.difficulty_level]
      score.tasks.append(task_key)

    score.put()

    query = GCIStudentInfo.all().ancestor(student)
    student_info = query.get()

    # set in student info that the student has completed a task
    if not student_info.task_closed:
      student_info.task_closed = True
      student_info.put()
예제 #14
0
  def getListData(self):
    idx = lists.getListIndex(self.data.request)
    if idx == self.LEADERBOARD_LIST_IDX:
      q = GCIScore.all()
      q.filter('program', self.data.program)

      skipper = lambda entity, start: entity.points <= 0
      prefetcher = lists.ModelPrefetcher(GCIScore, [], True)

      response_builder = lists.RawQueryContentResponseBuilder(
          self.data.request, self._list_config, q, lists.keyStarter,
          skipper=skipper, prefetcher=prefetcher)

      return response_builder.build()
    else:
      return None
예제 #15
0
def clear(*args, **kwargs):
  """Removes all entities from the datastore.
  """

  # TODO(dbentley): If there are more than 1000 instances of any model,
  # this method will not clear all instances.  Instead, it should continually
  # call .all(), delete all those, and loop until .all() is empty.
  entities = itertools.chain(*[
      Survey.all(),
      SurveyRecord.all(),
      GCIOrganization.all(),
      GSoCTimeline.all(),
      GCITimeline.all(),
      GSoCProgram.all(),
      GSoCProject.all(),
      GSoCProposal.all(),
      GCIProgram.all(),
      GCIScore.all(),
      GSoCStudentInfo.all(),
      GCIStudentInfo.all(),
      GCITask.all(),
      Sponsor.all(),
      Site.all(),
      Document.all(),
      # The below models are all subclasses of ndb.Model and therefore must
      # use .query() to return all instances instead of .all().
      soc_org_model.SOCOrganization.query(),
      profile_model.Profile.query(),
      soc_profile.SOCStudentData.query(),
      user.User.query(),
      address.Address.query(),
      contact.Contact.query()
      ])

  try:
    for entity in entities:
      if isinstance(entity, ndb.Model):
        entity.key.delete()
      else:
        entity.delete()
  except db.Timeout:
    return http.HttpResponseRedirect('#')
  memcache.flush_all()

  return http.HttpResponse('Done')
예제 #16
0
def clear(*args, **kwargs):
    """Removes all entities from the datastore.
  """

    # TODO(dbentley): If there are more than 1000 instances of any model,
    # this method will not clear all instances.  Instead, it should continually
    # call .all(), delete all those, and loop until .all() is empty.
    entities = itertools.chain(*[
        Survey.all(),
        SurveyRecord.all(),
        GCIOrganization.all(),
        GSoCTimeline.all(),
        GCITimeline.all(),
        GSoCProgram.all(),
        GSoCProject.all(),
        GSoCProposal.all(),
        GCIProgram.all(),
        GCIScore.all(),
        GSoCStudentInfo.all(),
        GCIStudentInfo.all(),
        GCITask.all(),
        Sponsor.all(),
        Site.all(),
        Document.all(),
        # The below models are all subclasses of ndb.Model and therefore must
        # use .query() to return all instances instead of .all().
        soc_org_model.SOCOrganization.query(),
        profile_model.Profile.query(),
        soc_profile.SOCStudentData.query(),
        user.User.query(),
        address.Address.query(),
        contact.Contact.query()
    ])

    try:
        for entity in entities:
            if isinstance(entity, ndb.Model):
                entity.key.delete()
            else:
                entity.delete()
    except db.Timeout:
        return http.HttpResponseRedirect('#')
    memcache.flush_all()

    return http.HttpResponse('Done')
예제 #17
0
def winnersForProgram(data):
  """Returns the winners for the program.

  The number of winners chosen is configurable from the program edit page. The
  return datastructure is a dictionary with profile keys of winners as keys
  with values as dictionaries containing the name, number of task and the
  points scored.

  Args:
    data: The RequestData object.
  """
  program = data.program

  q = GCIScore.all()
  q.filter('program', program)
  q.filter('points >', 0)
  q.order('-points')
  scores = q.fetch(program.nr_winners)

  profile_keys = [s.parent_key() for s in scores]
  profiles = db.get(profile_keys)

  winners = SortedDict()
  for score in scores:
    winners[score.parent_key()] = {
        'score': score,
        }

  for profile in profiles:
    winner = winners[profile.key()]
    winner['profile'] = profile
    winner['completed_tasks_link'] = data.redirect.profile(
        profile.link_id).urlOf(url_names.GCI_STUDENT_TASKS)

    if profile.avatar:
      avatar_groups = re.findall(forms.RE_AVATAR_COLOR, profile.avatar)
      # Being a bit pessimistic
      if avatar_groups:
        # We only want the first match, so pick group[0]
        name, prefix = avatar_groups[0]
        winner['avatar_name'] = '%s-%s.jpg' % (name, prefix)
        winner['avatar_prefix'] = prefix

  return winners
예제 #18
0
def winnersForProgram(data):
    """Returns the winners for the program.

  The number of winners chosen is configurable from the program edit page. The
  return datastructure is a dictionary with profile keys of winners as keys
  with values as dictionaries containing the name, number of task and the
  points scored.

  Args:
    data: The RequestData object.
  """
    program = data.program

    q = GCIScore.all()
    q.filter('program', program)
    q.filter('points >', 0)
    q.order('-points')
    scores = q.fetch(program.nr_winners)

    profile_keys = [s.parent_key() for s in scores]
    profiles = db.get(profile_keys)

    winners = SortedDict()
    for score in scores:
        winners[score.parent_key()] = {
            'score': score,
        }

    for profile in profiles:
        winner = winners[profile.key()]
        winner['profile'] = profile
        winner['completed_tasks_link'] = data.redirect.profile(
            profile.link_id).urlOf(url_names.GCI_STUDENT_TASKS)

        if profile.avatar:
            avatar_groups = re.findall(forms.RE_AVATAR_COLOR, profile.avatar)
            # Being a bit pessimistic
            if avatar_groups:
                # We only want the first match, so pick group[0]
                name, prefix = avatar_groups[0]
                winner['avatar_name'] = '%s-%s.jpg' % (name, prefix)
                winner['avatar_prefix'] = prefix

    return winners
예제 #19
0
    def calculate_score_txn():
        query = GCIScore.all().ancestor(student)
        score = query.get()

        # create a new GCIStore entity if one does not exist yet
        if not score:
            score = GCIScore(parent=student, program=program)

        score.points = points
        score.tasks = [task.key() for task in tasks]
        score.put()

        # set that the student closed a task in GCIStudentInfo
        query = GCIStudentInfo.all().ancestor(student)
        student_info = query.get()
        student_info.task_closed = True
        student_info.put()
예제 #20
0
    def clearGCIRanking(self, request, *args, **kwargs):
        """Clears student ranking for a program with the specified key_name.
    """
        key_name = "%s/%s" % (kwargs["sponsor"], kwargs["program"])

        program = GCIProgram.get_by_key_name(key_name)
        if not program:
            logging.warning("Enqueued recalculate ranking task for non-existing program: %s", key_name)
            return responses.terminateTask()

        q = GCIScore.all()
        q.filter("program", program)

        rankings = q.fetch(500)
        while rankings:
            db.delete(rankings)
            rankings = q.fetch(500)

        return responses.terminateTask()
예제 #21
0
파일: seed_db.py 프로젝트: adviti/melange
def clear(*args, **kwargs):
  """Removes all entities from the datastore.
  """

  # TODO(dbentley): If there are more than 1000 instances of any model,
  # this method will not clear all instances.  Instead, it should continually
  # call .all(), delete all those, and loop until .all() is empty.
  entities = itertools.chain(*[
      Notification.all(),
      GCIStudent.all(),
      Survey.all(),
      SurveyRecord.all(),
      StudentProposal.all(),
      GSoCOrganization.all(),
      GCIOrganization.all(),
      GSoCTimeline.all(),
      GCITimeline.all(),
      GSoCProgram.all(),
      GSoCProfile.all(),
      GCIProfile.all(),
      GSoCProposal.all(),
      GCIProgram.all(),
      GCIScore.all(),
      GSoCStudentInfo.all(),
      GCIStudentInfo.all(),
      GCITask.all(),
      Host.all(),
      Sponsor.all(),
      User.all(),
      Site.all(),
      Document.all(),
      ])

  try:
    for entity in entities:
      entity.delete()
  except db.Timeout:
    return http.HttpResponseRedirect('#')
  # pylint: disable=E1101
  memcache.flush_all()

  return http.HttpResponse('Done')
예제 #22
0
    def getListData(self):
        idx = lists.getListIndex(self.data.request)
        if idx == self.LEADERBOARD_LIST_IDX:
            q = GCIScore.all()
            q.filter('program', self.data.program)

            skipper = lambda entity, start: entity.points <= 0
            prefetcher = lists.ModelPrefetcher(GCIScore, [], True)

            response_builder = lists.RawQueryContentResponseBuilder(
                self.data.request,
                self._list_config,
                q,
                lists.keyStarter,
                skipper=skipper,
                prefetcher=prefetcher)

            return response_builder.build()
        else:
            return None
예제 #23
0
    def clearGCIRanking(self, request, *args, **kwargs):
        """Clears student ranking for a program with the specified key_name.
    """
        key_name = '%s/%s' % (kwargs['sponsor'], kwargs['program'])

        program = GCIProgram.get_by_key_name(key_name)
        if not program:
            logging.warning(
                'Enqueued recalculate ranking task for non-existing program: %s',
                key_name)
            return responses.terminateTask()

        q = GCIScore.all()
        q.filter('program', program)

        rankings = q.fetch(500)
        while rankings:
            db.delete(rankings)
            rankings = q.fetch(500)

        return responses.terminateTask()
예제 #24
0
파일: ranking.py 프로젝트: adviti/melange
  def calculate_score_txn():
    query = GCIScore.all().ancestor(student)
    score = query.get()

    # create a new GCIStore entity if one does not exist yet
    if not score:
      score = GCIScore(parent=student, program=program)

    score.points = points
    score.tasks = [task.key() for task in tasks]
    score.put()

    # set that the student closed a task in GCIStudentInfo
    query = GCIStudentInfo.all().ancestor(student)
    student_info = query.get()
    student_info.task_closed = True
    student_info.put()
예제 #25
0
def downloadStudentForms(options):
  from google.appengine.ext import db
  from soc.views.helper import lists as list_helper
  from soc.modules.gci.models.profile import GCIProfile
  from soc.modules.gci.models.profile import GCIStudentInfo
  from soc.modules.gci.models.program import GCIProgram
  from soc.modules.gci.models.score import GCIScore

  if not options.program_path:
    print "--program_path or -p option is required"
  program = GCIProgram.get_by_key_name(options.program_path)

  outputdir = os.path.abspath(options.outputdir)
  if not os.path.exists(outputdir):
    os.mkdir(outputdir)

  if not os.path.isdir(outputdir):
    print "Could not create output dir: %s" % outputdir

  q = lambda: GCIScore.all().filter("program =", program)
  print "Fetching GCIScore..."
  scores = list(i for i in interactive.deepFetch(q))

  keys = list_helper.collectParentKeys(scores)
  keys = list(set(keys))
  prefetched = {}

  print "Fetching Profile..."
  for i in xrange(0, len(keys), 100):
    chunk = keys[i:i+100]
    entities = db.get(chunk)
    prefetched.update(dict((i.key(), i) for i in entities if i))

  profiles = prefetched.values()
  list_helper.distributeParentKeys(scores, prefetched)

  keys = list_helper.collectKeys(GCIProfile.student_info, entities)
  keys = list(set(keys))
  prefetched = {}

  print "Fetching StudentInfo..."
  for i in xrange(0, len(keys), 100):
    chunk = keys[i:i+100]
    entities = db.get(chunk)
    prefetched.update(dict((i.key(), i) for i in entities if i))

  studentInfos = prefetched.values()
  list_helper.distributeKeys(GCIProfile.student_info, profiles, prefetched)

  i = 0
  while i < len(profiles):
    try:
      profile = profiles[i]
      consent_form = profile.student_info.consent_form
      student_id_form = profile.student_info.student_id_form
      if not consent_form or not student_id_form:
        print "At least one form missing from %s" % profile.link_id
      else:
        _saveForm(profile, consent_form, 'consent-form', outputdir)
        _saveForm(profile, consent_form, 'student-id-form', outputdir)
    except Exception, e:
      continue
    i += 1
예제 #26
0
def downloadStudentForms(options):
    from google.appengine.ext import db
    from soc.views.helper import lists as list_helper
    from soc.modules.gci.models.profile import GCIProfile
    from soc.modules.gci.models.profile import GCIStudentInfo
    from soc.modules.gci.models.program import GCIProgram
    from soc.modules.gci.models.score import GCIScore

    if not options.program_path:
        print "--program_path or -p option is required"
    program = GCIProgram.get_by_key_name(options.program_path)

    outputdir = os.path.abspath(options.outputdir)
    if not os.path.exists(outputdir):
        os.mkdir(outputdir)

    if not os.path.isdir(outputdir):
        print "Could not create output dir: %s" % outputdir

    q = lambda: GCIScore.all().filter("program =", program)
    print "Fetching GCIScore..."
    scores = list(i for i in interactive.deepFetch(q))

    keys = list_helper.collectParentKeys(scores)
    keys = list(set(keys))
    prefetched = {}

    print "Fetching Profile..."
    for i in xrange(0, len(keys), 100):
        chunk = keys[i:i + 100]
        entities = db.get(chunk)
        prefetched.update(dict((i.key(), i) for i in entities if i))

    profiles = prefetched.values()
    list_helper.distributeParentKeys(scores, prefetched)

    keys = list_helper.collectKeys(GCIProfile.student_info, entities)
    keys = list(set(keys))
    prefetched = {}

    print "Fetching StudentInfo..."
    for i in xrange(0, len(keys), 100):
        chunk = keys[i:i + 100]
        entities = db.get(chunk)
        prefetched.update(dict((i.key(), i) for i in entities if i))

    studentInfos = prefetched.values()
    list_helper.distributeKeys(GCIProfile.student_info, profiles, prefetched)

    i = 0
    while i < len(profiles):
        try:
            profile = profiles[i]
            consent_form = profile.student_info.consent_form
            student_id_form = profile.student_info.student_id_form
            if not consent_form or not student_id_form:
                print "At least one form missing from %s" % profile.link_id
            else:
                _saveForm(profile, consent_form, 'consent-form', outputdir)
                _saveForm(profile, consent_form, 'student-id-form', outputdir)
        except Exception, e:
            continue
        i += 1
예제 #27
0
def seed(request, *args, **kwargs):
    """Seeds the datastore with some default values.
  """

    site_properties = {
        'key_name': 'site',
        'latest_gsoc': 'google/gsoc2014',
        'latest_gci': 'google/gci2013',
    }
    site = Site(**site_properties)
    site.put()

    account = accounts.getCurrentAccount()

    if not account:
        account = users.User(email='*****@*****.**')

    user_properties = {
        'id': 'test',
        'account_id': account.user_id(),
        'account': account,
    }
    current_user = user.User(**user_properties)
    current_user.put()

    group_properties = {
        'key_name': 'google',
        'link_id': 'google',
        'name': 'Google Inc.',
        'short_name': 'Google',
        'home_page': 'http://www.google.com',
        'email': '*****@*****.**',
        'description': 'This is the profile for Google.',
        'contact_street': 'Some Street',
        'contact_city': 'Some City',
        'contact_country': 'United States',
        'contact_postalcode': '12345',
        'phone': '15551110000',
        'status': 'active',
    }
    google = Sponsor(**group_properties)
    google.put()

    now = datetime.datetime.now()
    before = now - datetime.timedelta(365)
    after = now + datetime.timedelta(365)
    past_before = before - datetime.timedelta(2 * 365)
    past_after = after - datetime.timedelta(2 * 365)

    timeline_properties = {
        'key_name': 'google/gsoc2014',
        'link_id': 'gsoc2014',
        'scope': google,
        'program_start': before,
        'program_end': after,
        'accepted_organization_announced_deadline': before,
        'accepted_students_announced_deadline': after,
        'student_signup_start': before,
        'student_signup_end': after,
        'application_review_deadline': after,
        'student_application_matched_deadline': after,
        'accepted_students_announced_deadline': after,
        'form_submission_start': before,
    }
    gsoc2014_timeline = GSoCTimeline(**timeline_properties)
    gsoc2014_timeline.put()

    program_properties = {
        'key_name': 'google/gsoc2014',
        'link_id': 'gsoc2014',
        'program_id': 'gsoc2014',
        'sponsor': google,
        'scope': google,
        'name': 'Google Summer of Code 2014',
        'short_name': 'GSoC 2014',
        'description': 'This is the program for GSoC 2014.',
        'apps_tasks_limit': 42,
        'slots': 42,
        'timeline': gsoc2014_timeline,
        'status': program_model.STATUS_VISIBLE,
    }
    gsoc2014 = GSoCProgram(**program_properties)
    gsoc2014.put()

    timeline_properties.update({
        'key_name': 'google/gsoc2010',
        'link_id': 'gsoc2010',
        'program_start': past_before,
        'program_end': past_after,
        'accepted_organization_announced_deadline': past_before,
        'accepted_students_announced_deadline': past_after,
        'student_signup_start': past_before,
        'student_signup_end': past_after,
        'application_review_deadline': past_after,
        'student_application_matched_deadline': past_after,
        'accepted_students_announced_deadline': past_after,
        'form_submission_start': past_before,
    })
    gsoc2010_timeline = GSoCTimeline(**timeline_properties)
    gsoc2010_timeline.put()

    program_properties.update({
        'key_name': 'google/gsoc2010',
        'link_id': 'gsoc2010',
        'program_id': 'gsoc2010',
        'name': 'Google Summer of Code 2010',
        'description': 'This is the program for GSoC 2010.',
        'short_name': 'GSoC 2010',
        'timeline': gsoc2010_timeline,
    })
    gsoc2010 = GSoCProgram(**program_properties)
    gsoc2010.put()

    # TODO(drew): Replace gsoc2014.prefix with whatever its replacement becomes
    # once prefix is removed from program and no longer used in the query for
    # OrgAppSurvey in soc.views.helper.RequestData._getProgramWideFields().
    org_app_survey_properties = {
        'key_name': '%s/%s/orgapp' % (gsoc2014.prefix, gsoc2014.key().name()),
        'program': gsoc2014,
        'title': 'Org App Survey',
        'content': 'Here is some content.',
        'modified_by': current_user.key.to_old_key(),
        'survey_start': before,
        'survey_end': after
    }
    org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put()

    org_app_survey_properties['key_name'] = (
        '%s/%s/orgapp' % (gsoc2010.prefix, gsoc2010.key().name()))
    org_app_survey_properties['program'] = gsoc2010
    org_app_survey_properties['survey_start'] = past_before
    org_app_survey_properties['survey_end'] = past_after
    org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put()

    timeline_properties = {
        'key_name': 'google/gci2013',
        'link_id': 'gci2013',
        'scope': google,
        'program_start': before,
        'program_end': after,
        'accepted_organization_announced_deadline': before,
        'student_signup_start': before,
        'student_signup_end': after,
        'tasks_publicly_visible': before,
        'task_claim_deadline': after,
        'stop_all_work_deadline': after,
    }
    gci2013_timeline = GCITimeline(**timeline_properties)
    gci2013_timeline.put()

    program_properties.update({
        'key_name': 'google/gci2013',
        'link_id': 'gci2013',
        'program_id': 'gci2013',
        'name': 'Google Code In Contest 2013',
        'short_name': 'GCI 2009',
        'description': 'This is the program for GCI 2013.',
        'timeline': gci2013_timeline,
    })
    gci2013 = GCIProgram(**program_properties)
    gci2013.put()

    site.active_program = gci2013
    site.put()

    current_user.host_for = [
        ndb.Key.from_old_key(gsoc2010.key()),
        ndb.Key.from_old_key(gsoc2014.key()),
        ndb.Key.from_old_key(gci2013.key())
    ]
    current_user.put()

    group_properties.update({
        'key_name': 'google/gci2013/melange',
        'link_id': 'melange',
        'name': 'Melange Development Team',
        'short_name': 'Melange',
        'scope': gci2013,
        'program': gci2013,
        'sponsor': google,
        'home_page': 'http://code.google.com/p/soc',
        'description': 'Melange, share the love!',
        'license_name': 'Apache License',
        'ideas': 'http://code.google.com/p/soc/issues',
    })
    melange = GCIOrganization(**group_properties)
    melange.put()

    group_properties.update({
        'scope': gsoc2014,
        'program': gsoc2014,
    })

    address_properties = address.Address(street='1 Test St.',
                                         city='Some City',
                                         country='United States',
                                         postal_code='12345')
    address_properties.put()

    contact_info = contact.Contact(email='*****@*****.**')
    contact_info.put()

    gsoc_delta = datetime.timedelta(days=(365 * 18))

    profile_properties = {
        'id': gsoc2014.key().name() + '/' + current_user.key.id(),
        'parent': current_user.key,
        'public_name': 'test',
        'program': ndb.Key.from_old_key(gsoc2014.key()),
        'first_name': 'Test',
        'last_name': 'Example',
        'contact': contact_info,
        'residential_address': address_properties,
        'shipping_address': address_properties,
        'birth_date': datetime.date.today() - gsoc_delta,
        'program_knowledge': 'Friend referral',
    }
    profile = profile_model.Profile(**profile_properties)

    ndb_orgs = []
    for i in range(15):
        group_properties.update({
            'key_name': 'google/gsoc2014/org_%d' % i,
            'link_id': 'org_%d' % i,
            'name': 'Organization %d' % i,
            'short_name': 'Org %d' % i,
            'description': 'Organization %d!' % i,
        })

        org_properties = {
            'name': 'Organization %d' % i,
            'org_id': 'org_%d' % i,
            'program': ndb.Key.from_old_key(gsoc2014.key()),
            'description': 'Organization %d!' % i,
        }
        org = soc_org_model.SOCOrganization(id='google/gsoc2014/org_%d' % i,
                                            **org_properties)
        org.put()
        ndb_orgs.append(org)

        # Admin (and thus mentor) for the first org
        if i == 0:
            profile.admin_for.append(org.key)
            profile.mentor_for.append(org.key)
            profile.put()

        # Mentor for the second org
        if i == 1:
            profile.mentor_for.append(org.key)
            profile.put()

    profile_properties.update({
        'id':
        gci2013.key().name() + '/' + current_user.key.id(),
        'parent':
        current_user.key,
        'program':
        ndb.Key.from_old_key(gci2013.key()),
        'admin_for': [ndb.Key.from_old_key(melange.key())],
        'mentor_for': [ndb.Key.from_old_key(melange.key())],
    })
    melange_admin = profile_model.Profile(**profile_properties)
    # TODO: add GCI orgs
    melange_admin.put()

    task_properties = {
        'status': 'Open',
        'modified_by': melange_admin.key.to_old_key(),
        'subscribers': [melange_admin.key.to_old_key()],
        'title': 'Awesomeness',
        'created_by': melange_admin.key.to_old_key(),
        'created_on': now,
        'program': gci2013,
        'time_to_complete': 1337,
        'modified_on': now,
        'org': melange.key(),
        'description': '<p>AWESOME</p>',
        'difficulty_level': DifficultyLevel.MEDIUM,
        'types': ['Code']
    }
    gci_task = GCITask(**task_properties)
    gci_task.put()

    user_properties = {
        'id': 'student',
        'account_id': '12345',
        'account': users.User(email='*****@*****.**'),
    }
    student_user = user.User(**user_properties)
    student_user.put()

    gci_delta = datetime.timedelta(days=(365 * 14))

    contact_properties = contact.Contact(email='*****@*****.**',
                                         web_page='http://www.homepage.com/',
                                         blog='http://www.blog.com/',
                                         phone='1650253000')
    contact_properties.put()

    graduation_year = datetime.date.today() + datetime.timedelta(days=365)

    student_data = soc_profile.SOCStudentData(education=education.Education(
        school_id="123",
        school_country="United States",
        expected_graduation=int(graduation_year.strftime('%Y')),
        major='Some Major',
        degree=education.Degree.UNDERGRADUATE))
    student_data.put()

    student_id = 'student'
    student_properties = {
        'id': gsoc2014.key().name() + "/" + student_id,
        'parent': student_user.key,
        'program': ndb.Key.from_old_key(gsoc2014.key()),
        'public_name': 'Student',
        'first_name': 'Student',
        'last_name': 'Student',
        'contact': contact_properties,
        'residential_address': address_properties,
        'shipping_address': address_properties,
        'birth_date': datetime.date.today() - gci_delta,
        'tee_size': profile_model.TeeSize.L,
        'tee_style': profile_model.TeeStyle.MALE,
        'gender': profile_model.Gender.MALE,
        'program_knowledge': 'Friend referral.',
        'student_data': student_data,
    }
    melange_student = profile_model.Profile(**student_properties)
    melange_student.put()

    student_id = 'student2'
    user_properties = {
        'id': student_id,
        'account_id': 'student2',
        'account': users.User(email='*****@*****.**'),
    }
    student_user2 = user.User(**user_properties)
    student_user2.put()

    student_properties.update({
        'id': gsoc2014.key().name() + "/" + student_id,
        'parent': student_user2.key,
        'first_name': 'Student 2',
        'last_name': 'Example'
    })
    melange_student2 = profile_model.Profile(**student_properties)
    melange_student2.put()

    proposal_properties = {
        'parent': melange_student.key.to_old_key(),
        'program': gsoc2014,
        'title': 'test proposal',
        'abstract': 'test abstract',
        'content': 'test content',
        'mentor': profile.key.to_old_key(),
        'status': 'accepted',
        'has_mentor': True,
        'org': ndb_orgs[0].key.to_old_key(),
        'possible_mentors': [profile.key.to_old_key()]
    }
    melange_proposal = GSoCProposal(**proposal_properties)
    melange_proposal.put()

    project_properties = {
        'title': 'test project',
        'abstract': 'test abstract',
        'status': 'accepted',
        'parent': melange_student.key.to_old_key(),
        'mentors': [profile.key.to_old_key()],
        'program': gsoc2014,
        'org': ndb_orgs[0].key.to_old_key(),
        'proposal': melange_proposal.key(),
    }
    melange_project = GSoCProject(**project_properties)
    melange_project.put()
    ndb_orgs[1].slot_allocation = 1
    ndb_orgs[1].put()

    student_data.number_of_projects = 1
    student_data.number_of_proposals = 1
    student_data.project_for_orgs = [ndb_orgs[1].key]

    melange_student.put()
    melange_student2.put()

    project_properties.update({
        'student': melange_student2,
        'title': 'test project2'
    })
    melange_project2 = GSoCProject(**project_properties)
    melange_project2.put()
    ndb_orgs[1].slot_allocation += 1
    ndb_orgs[1].put()

    student_id = 'student'
    student_properties.update({
        'id': gci2013.key().name() + '/' + student_id,
        'parent': student_user.key,
        'program': ndb.Key.from_old_key(gci2013.key()),
    })
    gci_student = profile_model.Profile(**student_properties)
    gci_student.put()

    score_properties = {
        'parent': gci_student.key.to_old_key(),
        'program': gci2013,
        'points': 5,
        'tasks': [gci_task.key()]
    }
    score = GCIScore(**score_properties)
    score.put()

    document_properties = {
        'key_name': 'site/site/home',
        'link_id': 'home',
        'scope': site,
        'prefix': 'site',
        'author': current_user.key.to_old_key(),
        'title': 'Home Page',
        'content': 'This is the Home Page',
        'modified_by': current_user.key.to_old_key(),
    }
    home_document = Document(**document_properties)
    home_document.put()

    document_properties = {
        'key_name': 'user/test/notes',
        'link_id': 'notes',
        'scope': current_user.key.to_old_key(),
        'prefix': 'user',
        'author': current_user.key.to_old_key(),
        'title': 'My Notes',
        'content': 'These are my notes',
        'modified_by': current_user.key.to_old_key(),
    }
    notes_document = Document(**document_properties)
    notes_document.put()

    site.home = home_document
    site.put()

    memcache.flush_all()

    return http.HttpResponse('Done')
예제 #28
0
파일: seed_db.py 프로젝트: adviti/melange
def seed(request, *args, **kwargs):
  """Seeds the datastore with some default values.
  """

  site_properties = {
      'key_name': 'site',
      'link_id': 'site',
      }

  site = Site(**site_properties)
  site.put()

  account = accounts.getCurrentAccount()

  if not account:
    account = users.User(email='*****@*****.**')

  user_properties = {
      'key_name': 'test',
      'link_id': 'test',
      'account': account,
      'name': 'Test',
      }

  current_user = User(**user_properties)
  current_user.put()

  group_properties = {
       'key_name': 'google',
       'link_id': 'google',
       'name': 'Google Inc.',
       'short_name': 'Google',
       'founder': current_user,
       'home_page': 'http://www.google.com',
       'email': '*****@*****.**',
       'description': 'This is the profile for Google.',
       'contact_street': 'Some Street',
       'contact_city': 'Some City',
       'contact_country': 'United States',
       'contact_postalcode': '12345',
       'phone': '1-555-BANANA',
       'status': 'active',
       }

  google = Sponsor(**group_properties)
  google.put()


  role_properties = {
      'key_name': 'google/test',
      'link_id': 'test',
      'public_name': 'test',
      'scope': google,
      'scope_path': 'google',
      'user': current_user,
      'given_name': 'Test',
      'surname': 'Example',
      'name_on_documents': 'Test Example',
      'email': '*****@*****.**',
      'res_street': 'Some Street',
      'res_city': 'Some City',
      'res_state': 'Some State',
      'res_country': 'United States',
      'res_postalcode': '12345',
      'phone': '1-555-BANANA',
      'birth_date': db.DateProperty.now(),
      'agreed_to_tos': True,
      'is_org_admin': True,
      'is_mentor': True,
      }


  current_user.host_for = [google.key()]
  current_user.put()

  google_host = Host(**role_properties)
  google_host.put()

  from datetime import datetime
  from datetime import timedelta

  now = datetime.now()
  before = now - timedelta(365)
  after = now + timedelta(365)

  timeline_properties = {
      'key_name': 'google/gsoc2009',
      'link_id': 'gsoc2009',
      'scope_path': 'google',
      'scope': google,
      'program_start': before,
      'program_end': after,
      'accepted_organization_announced_deadline': before,
      'student_signup_start': before,
      'student_signup_end': after,
  }

  gsoc2009_timeline = GSoCTimeline(**timeline_properties)
  gsoc2009_timeline.put()


  program_properties = {
      'key_name': 'google/gsoc2009',
      'link_id': 'gsoc2009',
      'scope_path': 'google',
      'scope': google,
      'name': 'Google Summer of Code 2009',
      'short_name': 'GSoC 2009',
      'group_label': 'GSOC',
      'description': 'This is the program for GSoC 2009.',
      'apps_tasks_limit': 42,
      'slots': 42,
      'timeline': gsoc2009_timeline,
      'status': 'visible',
      }

  gsoc2009 = GSoCProgram(**program_properties)
  gsoc2009.put()


  timeline_properties.update({
      'key_name': 'google/gsoc2010',
      'link_id': 'gsoc2010',
  })

  gsoc2010_timeline = GSoCTimeline(**timeline_properties)
  gsoc2010_timeline.put()

  program_properties.update({
      'key_name': 'google/gsoc2010',
      'link_id': 'gsoc2010',
      'name': 'Google Summer of Code 2010',
      'description': 'This is the program for GSoC 2010.',
      'short_name': 'GSoC 2010',
      'timeline': gsoc2010_timeline,
  })

  gsoc2010 = GSoCProgram(**program_properties)
  gsoc2010.put()

  timeline_properties = {
        'key_name': 'google/gci2009',
        'link_id': 'gci2009',
        'scope_path': 'google',
        'scope': google,
        'program_start': before,
        'program_end': after,
        'accepted_organization_announced_deadline': before,
        'student_signup_start': before,
        'student_signup_end': after,
        'tasks_publicly_visible': before,
        'task_claim_deadline': after,
        'stop_all_work_deadline': after,
  }

  gci2009_timeline = GCITimeline(**timeline_properties)
  gci2009_timeline.put()


  program_properties.update({
      'key_name': 'google/gci2009',
      'link_id': 'gci2009',
      'name': 'Google Code In Contest 2009',
      'short_name': 'GCI 2009',
      'group_label': 'GCI',
      'description': 'This is the program for GCI 2009.',
      'timeline': gci2009_timeline,
      })

  gci2009 = GCIProgram(**program_properties)
  gci2009.put()

  site.active_program = gci2009
  site.put()


  group_properties.update({
    'key_name': 'google/gci2009/melange',
    'link_id': 'melange',
    'name': 'Melange Development Team',
    'short_name': 'Melange',
    'scope_path': 'google/gci2009',
    'scope': gci2009,
    'home_page': 'http://code.google.com/p/soc',
    'description': 'Melange, share the love!',
    'license_name': 'Apache License',
    'ideas': 'http://code.google.com/p/soc/issues',
    })

  melange = GCIOrganization(**group_properties)
  melange.put()

  group_properties.update({
    'scope_path': 'google/gsoc2009',
    'scope': gsoc2009,
    })

  role_properties.update({
      'key_name': 'google/gsoc2009/test',
      'link_id': 'test',
      'scope_path': 'google/gsoc2009',
      'scope': gsoc2009,
      'program': gsoc2009,
      'parent': current_user,
      })

  profile = GSoCProfile(**role_properties)
  role_properties.pop('parent')

  orgs = []
  for i in range(15):
    group_properties.update({
        'key_name': 'google/gsoc2009/org_%d' % i,
        'link_id': 'org_%d' % i,
        'name': 'Organization %d' % i,
        'short_name': 'Org %d' % i,
        'description': 'Organization %d!' % i,
        })

    entity = GSoCOrganization(**group_properties)
    orgs.append(entity)
    entity.put()

    # Admin (and thus mentor) for the first org
    if i == 0:
      profile.org_admin_for.append(entity.key())
      profile.mentor_for.append(entity.key())
      profile.is_mentor = True
      profile.is_org_admin = True
      profile.put()

    # Mentor for the second org
    if i == 1:
      profile.mentor_for.append(entity.key())
      profile.is_mentor = True
      profile.put()

  role_properties.update({
      'key_name': 'google/gci2009/test',
      'link_id': 'test',
      'scope_path': 'google/gci2009',
      'scope': gci2009,
      'program': gci2009,
      'org_admin_for': [melange.key()],
      'mentor_for': [melange.key()],
      'parent': current_user,
      })

  melange_admin = GCIProfile(**role_properties)
  # TODO: add GCI orgs
  melange_admin.put()

  task_properties = {
      'status': 'Open',
      'modified_by': melange_admin.key(),
      'subscribers': [melange_admin.key()],
      'title': 'Awesomeness',
      'created_by': melange_admin.key(),
      'created_on': now,
      'program': gci2009,
      'time_to_complete': 1337,
      'modified_on': now,
      'org': melange.key(),
      'description': '<p>AWESOME</p>',
      'difficulty_level': DifficultyLevel.MEDIUM,
      'types': ['Code']
  }

  gci_task = GCITask(**task_properties)
  gci_task.put()

  user_properties = {
      'key_name': 'student',
      'link_id': 'student',
      'account': users.User(email='*****@*****.**'),
      'name': 'Student',
      }

  student_user = User(**user_properties)
  student_user.put()

  student_id = 'student'
  student_properties = {
      'key_name': gsoc2009.key().name() + "/" + student_id,
      'link_id': student_id, 
      'scope_path': gsoc2009.key().name(),
      'parent': student_user,
      'scope': gsoc2009,
      'program': gsoc2009,
      'user': student_user,
      'is_student': True,
      'public_name': 'Student',
      'given_name': 'Student',
      'surname': 'Student',
      'birth_date': db.DateProperty.now(),
      'email': '*****@*****.**',
      'im_handle': 'student_im_handle',
      'major': 'test major',
      'name_on_documents': 'Student',
      'res_country': 'United States',
      'res_city': 'city',
      'res_street': 'test street',
      'res_postalcode': '12345',
      'publish_location': True,
      'blog': 'http://www.blog.com/',
      'home_page': 'http://www.homepage.com/',
      'photo_url': 'http://www.photosite.com/thumbnail.png',
      'ship_state': None,
      'tshirt_size': 'XS',
      'tshirt_style': 'male',
      'degree': 'Undergraduate',
      'phone': '1650253000',
      'can_we_contact_you': True, 
      'program_knowledge': 'I heard about this program through a friend.'
      }

  melange_student = GSoCProfile(**student_properties)

  student_info_properties = {
      'key_name': melange_student.key().name(),
      'parent': melange_student,
      'expected_graduation': 2009,
      'program': gsoc2009,
      'school_country': 'United States',
      'school_name': 'Test School',
      'school_home_page': 'http://www.example.com',
      'program': gsoc2009,
  }
  student_info = GSoCStudentInfo(**student_info_properties)
  student_info.put()

  melange_student.student_info = student_info
  melange_student.put()

  user_properties = {
      'key_name': 'student2',
      'link_id': 'student2',
      'account': users.User(email='*****@*****.**'),
      'name': 'Student 2',
      }

  student_user2 = User(**user_properties)
  student_user2.put()
  student_id = 'student2'
  student_properties.update({
      'key_name': gsoc2009.key().name() + "/" + student_id,
      'link_id': student_id,
      'user': student_user2,
      'parent': student_user2,
  })

  melange_student2 = GSoCProfile(**student_properties)
  melange_student2.put()

  project_id = 'test_project'
  project_properties = {
      'key_name':  gsoc2009.key().name() + "/org_1/" + project_id,
      'link_id': project_id, 
      'scope_path': gsoc2009.key().name() + "/org_1",
      'scope': orgs[1].key(),

      'title': 'test project',
      'abstract': 'test abstract',
      'status': 'accepted',
      'student': melange_student,
      'mentor': profile,
      'program':  gsoc2009
       }

  melange_project = StudentProject(**project_properties)
  melange_project.put()
  student_info_properties.update({'number_of_projects': 1,
                                  'project_for_orgs': [orgs[1].key()]})
  student_info = GSoCStudentInfo(**student_info_properties)
  student_info.put()

  melange_student.student_info = student_info
  melange_student.put()

  project_id = 'test_project2'
  project_properties.update({
      'key_name':  gsoc2009.key().name() + "/org_1/" + project_id,
      'link_id': project_id,
      'student': melange_student2,
      'title': 'test project2'
      })
      
  student_info_properties.update({
      'key_name': gsoc2009.key().name() + "/" + student_id,
      'link_id': student_id,
      'parent': melange_student2,
  })
  student_info2 = GSoCStudentInfo(**student_info_properties)
  student_info2.put()

  melange_student2.student_info = student_info2
  melange_student2.put()

  melange_project2 = StudentProject(**project_properties)
  melange_project2.put()

  student_id = 'student'
  student_properties.update({
      'key_name': gci2009.key().name() + '/' + student_id,
      'parent': student_user,
      'scope': gci2009,
      'scope_path': gci2009.key().name(),
  })
  gci_student = GCIProfile(**student_properties)
  gci_student.put()

  student_info_properties.update({
      'key_name': gci_student.key().name(),
      'parent': gci_student,
      'program': gci2009,
  })
  student_info = GCIStudentInfo(**student_info_properties)
  student_info.put()
  gci_student.student_info = student_info
  gci_student.put()

  score_properties = {
      'parent': gci_student,
      'program': gci2009,
      'points': 5,
      'tasks': [gci_task.key()]
      }
  score = GCIScore(**score_properties)
  score.put()

  document_properties = {
      'key_name': 'site/site/home',
      'link_id': 'home',
      'scope_path': 'site',
      'scope': site,
      'prefix': 'site',
      'author': current_user,
      'title': 'Home Page',
      'short_name': 'Home',
      'content': 'This is the Home Page',
      'modified_by': current_user,
      }

  home_document = Document(**document_properties)
  home_document.put()


  document_properties = {
      'key_name': 'user/test/notes',
      'link_id': 'notes',
      'scope_path': 'test',
      'scope': current_user,
      'prefix': 'user',
      'author': current_user,
      'title': 'My Notes',
      'short_name': 'Notes',
      'content': 'These are my notes',
      'modified_by': current_user,
      }

  notes_document = Document(**document_properties)
  notes_document.put()

  site.home = home_document
  site.put()
  # pylint: disable=E1101
  memcache.flush_all()

  return http.HttpResponse('Done')
예제 #29
0
def seed(request, *args, **kwargs):
  """Seeds the datastore with some default values.
  """

  site_properties = {
      'key_name': 'site',
      'latest_gsoc': 'google/gsoc2014',
      'latest_gci': 'google/gci2013',
      }
  site = Site(**site_properties)
  site.put()

  account = accounts.getCurrentAccount()

  if not account:
    account = users.User(email='*****@*****.**')

  user_properties = {
      'id': 'test',
      'account_id': account.user_id(),
      'account': account,
      }
  current_user = user.User(**user_properties)
  current_user.put()

  group_properties = {
       'key_name': 'google',
       'link_id': 'google',
       'name': 'Google Inc.',
       'short_name': 'Google',
       'home_page': 'http://www.google.com',
       'email': '*****@*****.**',
       'description': 'This is the profile for Google.',
       'contact_street': 'Some Street',
       'contact_city': 'Some City',
       'contact_country': 'United States',
       'contact_postalcode': '12345',
       'phone': '15551110000',
       'status': 'active',
       }
  google = Sponsor(**group_properties)
  google.put()

  now = datetime.datetime.now()
  before = now - datetime.timedelta(365)
  after = now + datetime.timedelta(365)
  past_before = before - datetime.timedelta(2 * 365)
  past_after = after - datetime.timedelta(2 * 365)

  timeline_properties = {
      'key_name': 'google/gsoc2014',
      'link_id': 'gsoc2014',
      'scope': google,
      'program_start': before,
      'program_end': after,
      'accepted_organization_announced_deadline': before,
      'accepted_students_announced_deadline' : after,
      'student_signup_start': before,
      'student_signup_end': after,
      'application_review_deadline': after,
      'student_application_matched_deadline': after,
      'accepted_students_announced_deadline': after,
      'form_submission_start': before,
  }
  gsoc2014_timeline = GSoCTimeline(**timeline_properties)
  gsoc2014_timeline.put()

  program_properties = {
      'key_name': 'google/gsoc2014',
      'link_id': 'gsoc2014',
      'program_id': 'gsoc2014',
      'sponsor': google,
      'scope': google,
      'name': 'Google Summer of Code 2014',
      'short_name': 'GSoC 2014',
      'description': 'This is the program for GSoC 2014.',
      'apps_tasks_limit': 42,
      'slots': 42,
      'timeline': gsoc2014_timeline,
      'status': program_model.STATUS_VISIBLE,
      }
  gsoc2014 = GSoCProgram(**program_properties)
  gsoc2014.put()

  timeline_properties.update({
      'key_name': 'google/gsoc2010',
      'link_id': 'gsoc2010',
      'program_start': past_before,
      'program_end': past_after,
      'accepted_organization_announced_deadline': past_before,
      'accepted_students_announced_deadline' : past_after,
      'student_signup_start': past_before,
      'student_signup_end': past_after,
      'application_review_deadline': past_after,
      'student_application_matched_deadline': past_after,
      'accepted_students_announced_deadline': past_after,
      'form_submission_start': past_before,
  })
  gsoc2010_timeline = GSoCTimeline(**timeline_properties)
  gsoc2010_timeline.put()

  program_properties.update({
      'key_name': 'google/gsoc2010',
      'link_id': 'gsoc2010',
      'program_id': 'gsoc2010',
      'name': 'Google Summer of Code 2010',
      'description': 'This is the program for GSoC 2010.',
      'short_name': 'GSoC 2010',
      'timeline': gsoc2010_timeline,
  })
  gsoc2010 = GSoCProgram(**program_properties)
  gsoc2010.put()

  # TODO(drew): Replace gsoc2014.prefix with whatever its replacement becomes
  # once prefix is removed from program and no longer used in the query for
  # OrgAppSurvey in soc.views.helper.RequestData._getProgramWideFields().
  org_app_survey_properties = {
    'key_name' : '%s/%s/orgapp' % (gsoc2014.prefix, gsoc2014.key().name()),
    'program' : gsoc2014,
    'title' : 'Org App Survey',
    'content' : 'Here is some content.',
    'modified_by' : current_user.key.to_old_key(),
    'survey_start' : before,
    'survey_end' : after
  }
  org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put()

  org_app_survey_properties['key_name'] = ('%s/%s/orgapp' % (
      gsoc2010.prefix, gsoc2010.key().name()))
  org_app_survey_properties['program'] = gsoc2010
  org_app_survey_properties['survey_start'] = past_before
  org_app_survey_properties['survey_end'] = past_after
  org_app_survey_model.OrgAppSurvey(**org_app_survey_properties).put()

  timeline_properties = {
        'key_name': 'google/gci2013',
        'link_id': 'gci2013',
        'scope': google,
        'program_start': before,
        'program_end': after,
        'accepted_organization_announced_deadline': before,
        'student_signup_start': before,
        'student_signup_end': after,
        'tasks_publicly_visible': before,
        'task_claim_deadline': after,
        'stop_all_work_deadline': after,
  }
  gci2013_timeline = GCITimeline(**timeline_properties)
  gci2013_timeline.put()

  program_properties.update({
      'key_name': 'google/gci2013',
      'link_id': 'gci2013',
      'program_id': 'gci2013',
      'name': 'Google Code In Contest 2013',
      'short_name': 'GCI 2009',
      'description': 'This is the program for GCI 2013.',
      'timeline': gci2013_timeline,
      })
  gci2013 = GCIProgram(**program_properties)
  gci2013.put()

  site.active_program = gci2013
  site.put()

  current_user.host_for = [
      ndb.Key.from_old_key(gsoc2010.key()),
      ndb.Key.from_old_key(gsoc2014.key()),
      ndb.Key.from_old_key(gci2013.key())]
  current_user.put()

  group_properties.update({
    'key_name': 'google/gci2013/melange',
    'link_id': 'melange',
    'name': 'Melange Development Team',
    'short_name': 'Melange',
    'scope': gci2013,
    'program': gci2013,
    'sponsor': google,
    'home_page': 'http://code.google.com/p/soc',
    'description': 'Melange, share the love!',
    'license_name': 'Apache License',
    'ideas': 'http://code.google.com/p/soc/issues',
    })
  melange = GCIOrganization(**group_properties)
  melange.put()

  group_properties.update({
    'scope': gsoc2014,
    'program': gsoc2014,
    })

  address_properties = address.Address(
      street='1 Test St.',
      city='Some City',
      country='United States',
      postal_code='12345')
  address_properties.put()

  contact_info = contact.Contact(email='*****@*****.**')
  contact_info.put()

  gsoc_delta = datetime.timedelta(days=(365 * 18))

  profile_properties = {
      'id': gsoc2014.key().name() + '/' + current_user.key.id(),
      'parent': current_user.key,
      'public_name': 'test',
      'program': ndb.Key.from_old_key(gsoc2014.key()),
      'first_name': 'Test',
      'last_name': 'Example',
      'contact' : contact_info,
      'residential_address' : address_properties,
      'shipping_address' : address_properties,
      'birth_date' : datetime.date.today() - gsoc_delta,
      'program_knowledge' : 'Friend referral',
      }
  profile = profile_model.Profile(**profile_properties)

  ndb_orgs = []
  for i in range(15):
    group_properties.update({
        'key_name': 'google/gsoc2014/org_%d' % i,
        'link_id': 'org_%d' % i,
        'name': 'Organization %d' % i,
        'short_name': 'Org %d' % i,
        'description': 'Organization %d!' % i,
        })

    org_properties = {
        'name': 'Organization %d' % i,
        'org_id': 'org_%d' % i,
        'program': ndb.Key.from_old_key(gsoc2014.key()),
        'description': 'Organization %d!' % i,
        }
    org = soc_org_model.SOCOrganization(
        id='google/gsoc2014/org_%d' % i, **org_properties)
    org.put()
    ndb_orgs.append(org)

    # Admin (and thus mentor) for the first org
    if i == 0:
      profile.admin_for.append(org.key)
      profile.mentor_for.append(org.key)
      profile.put()

    # Mentor for the second org
    if i == 1:
      profile.mentor_for.append(org.key)
      profile.put()

  profile_properties.update({
      'id': gci2013.key().name() + '/' + current_user.key.id(),
      'parent': current_user.key,
      'program': ndb.Key.from_old_key(gci2013.key()),
      'admin_for': [ndb.Key.from_old_key(melange.key())],
      'mentor_for': [ndb.Key.from_old_key(melange.key())],
      })
  melange_admin = profile_model.Profile(**profile_properties)
  # TODO: add GCI orgs
  melange_admin.put()

  task_properties = {
      'status': 'Open',
      'modified_by': melange_admin.key.to_old_key(),
      'subscribers': [melange_admin.key.to_old_key()],
      'title': 'Awesomeness',
      'created_by': melange_admin.key.to_old_key(),
      'created_on': now,
      'program': gci2013,
      'time_to_complete': 1337,
      'modified_on': now,
      'org': melange.key(),
      'description': '<p>AWESOME</p>',
      'difficulty_level': DifficultyLevel.MEDIUM,
      'types': ['Code']
  }
  gci_task = GCITask(**task_properties)
  gci_task.put()

  user_properties = {
      'id': 'student',
      'account_id': '12345',
      'account': users.User(email='*****@*****.**'),
      }
  student_user = user.User(**user_properties)
  student_user.put()

  gci_delta = datetime.timedelta(days=(365 * 14))

  contact_properties = contact.Contact(
      email='*****@*****.**',
      web_page='http://www.homepage.com/',
      blog='http://www.blog.com/',
      phone='1650253000')
  contact_properties.put()

  graduation_year = datetime.date.today() + datetime.timedelta(days=365)

  student_data = soc_profile.SOCStudentData(
      education=education.Education(
          school_id="123",
          school_country="United States",
          expected_graduation=int(graduation_year.strftime('%Y')),
          major='Some Major',
          degree=education.Degree.UNDERGRADUATE)
      )
  student_data.put()

  student_id = 'student'
  student_properties = {
      'id': gsoc2014.key().name() + "/" + student_id,
      'parent': student_user.key,
      'program': ndb.Key.from_old_key(gsoc2014.key()),
      'public_name': 'Student',
      'first_name': 'Student',
      'last_name': 'Student',
      'contact' : contact_properties,
      'residential_address' : address_properties,
      'shipping_address' : address_properties,
      'birth_date': datetime.date.today() - gci_delta,
      'tee_size': profile_model.TeeSize.L,
      'tee_style': profile_model.TeeStyle.MALE,
      'gender' : profile_model.Gender.MALE,
      'program_knowledge': 'Friend referral.',
      'student_data' : student_data,
      }
  melange_student = profile_model.Profile(**student_properties)
  melange_student.put()

  student_id = 'student2'
  user_properties = {
      'id': student_id,
      'account_id': 'student2',
      'account': users.User(email='*****@*****.**'),
      }
  student_user2 = user.User(**user_properties)
  student_user2.put()

  student_properties.update({
      'id': gsoc2014.key().name() + "/" + student_id,
      'parent': student_user2.key,
      'first_name' : 'Student 2',
      'last_name' : 'Example'
  })
  melange_student2 = profile_model.Profile(**student_properties)
  melange_student2.put()

  proposal_properties = {
      'parent': melange_student.key.to_old_key(),
      'program': gsoc2014,
      'title': 'test proposal',
      'abstract': 'test abstract',
      'content': 'test content',
      'mentor': profile.key.to_old_key(),
      'status': 'accepted',
      'has_mentor': True,
      'org': ndb_orgs[0].key.to_old_key(),
      'possible_mentors': [profile.key.to_old_key()]
      }
  melange_proposal = GSoCProposal(**proposal_properties)
  melange_proposal.put()

  project_properties = {
      'title': 'test project',
      'abstract': 'test abstract',
      'status': 'accepted',
      'parent': melange_student.key.to_old_key(),
      'mentors': [profile.key.to_old_key()],
      'program':  gsoc2014,
      'org': ndb_orgs[0].key.to_old_key(),
      'proposal' : melange_proposal.key(),
       }
  melange_project = GSoCProject(**project_properties)
  melange_project.put()
  ndb_orgs[1].slot_allocation = 1
  ndb_orgs[1].put()

  student_data.number_of_projects = 1
  student_data.number_of_proposals = 1
  student_data.project_for_orgs = [ndb_orgs[1].key]

  melange_student.put()
  melange_student2.put()

  project_properties.update({
      'student': melange_student2,
      'title': 'test project2'
      })
  melange_project2 = GSoCProject(**project_properties)
  melange_project2.put()
  ndb_orgs[1].slot_allocation += 1
  ndb_orgs[1].put()

  student_id = 'student'
  student_properties.update({
      'id': gci2013.key().name() + '/' + student_id,
      'parent': student_user.key,
      'program': ndb.Key.from_old_key(gci2013.key()),
  })
  gci_student = profile_model.Profile(**student_properties)
  gci_student.put()

  score_properties = {
      'parent': gci_student.key.to_old_key(),
      'program': gci2013,
      'points': 5,
      'tasks': [gci_task.key()]
      }
  score = GCIScore(**score_properties)
  score.put()

  document_properties = {
      'key_name': 'site/site/home',
      'link_id': 'home',
      'scope': site,
      'prefix': 'site',
      'author': current_user.key.to_old_key(),
      'title': 'Home Page',
      'content': 'This is the Home Page',
      'modified_by': current_user.key.to_old_key(),
      }
  home_document = Document(**document_properties)
  home_document.put()

  document_properties = {
      'key_name': 'user/test/notes',
      'link_id': 'notes',
      'scope': current_user.key.to_old_key(),
      'prefix': 'user',
      'author': current_user.key.to_old_key(),
      'title': 'My Notes',
      'content': 'These are my notes',
      'modified_by': current_user.key.to_old_key(),
      }
  notes_document = Document(**document_properties)
  notes_document.put()

  site.home = home_document
  site.put()

  memcache.flush_all()

  return http.HttpResponse('Done')