Exemplo n.º 1
0
  def programs(self):
    """Memoizes and returns a list of all programs.
    """
    from soc.modules.gsoc.models.program import GSoCProgram
    if not self._programs:
      self._programs = list(GSoCProgram.all())

    return self._programs
Exemplo n.º 2
0
  def registerWithProgramMap(self):
    """Called by the server when program_map entries should be registered.
    """

    self.core.requireUniqueService('registerWithProgramMap')

    from soc.modules.gsoc.models.program import GSoCProgram
    program_entities = GSoCProgram.all().fetch(1000)
    map = ('GSoC Programs', [
        (str(e.key()), e.name) for e in program_entities])

    self.core.registerProgramEntry(map)
Exemplo n.º 3
0
def clear(*args, **kwargs):
    """Removes all entities from the datastore.
  """

    # there no explicit ranker model anywhere, so make one for
    # our own convenience to delete all rankers
    class ranker(db.Model):
        """ranker model used with ranklist module.
    """
        pass

    # 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(),
        GSoCMentor.all(),
        GHOPMentor.all(),
        GSoCStudent.all(),
        GHOPStudent.all(),
        Survey.all(),
        SurveyContent.all(),
        SurveyRecord.all(),
        GSoCOrgAdmin.all(),
        GHOPOrgAdmin.all(),
        ranker.all(),
        RankerRoot.all(),
        StudentProposal.all(),
        GSoCOrganization.all(),
        GHOPOrganization.all(),
        OrgApplication.all(),
        GSoCTimeline.all(),
        GHOPTimeline.all(),
        GSoCProgram.all(),
        GHOPProgram.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-msg=E1101
    memcache.flush_all()

    return http.HttpResponse('Done')
Exemplo n.º 4
0
def clear(*args, **kwargs):
  """Removes all entities from the datastore.
  """

  # there no explicit ranker model anywhere, so make one for
  # our own convenience to delete all rankers
  class ranker(db.Model):
    """ranker model used with ranklist module.
    """
    pass

  # 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(),
      GSoCMentor.all(),
      GCIMentor.all(),
      GSoCStudent.all(),
      GCIStudent.all(),
      Survey.all(),
      SurveyContent.all(),
      SurveyRecord.all(),
      GSoCOrgAdmin.all(),
      GCIOrgAdmin.all(),
      ranker.all(),
      RankerRoot.all(),
      StudentProposal.all(),
      GSoCOrganization.all(),
      GCIOrganization.all(),
      GSoCTimeline.all(),
      GCITimeline.all(),
      GSoCProgram.all(),
      GCIProgram.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')
Exemplo n.º 5
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')
Exemplo n.º 6
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')
Exemplo n.º 7
0
def convertUser(user_key):
    """Converts the specified user by creating a new user entity that inherits
  from the newly added NewUser model.

  Args:
    user_key: User key.
  """
    user = User.get(user_key)

    entity_id = user.key().name()
    account_id = user.user_id or 'unset'

    if user.status == 'valid':
        status = user_model.Status.ACTIVE
    elif user.status == 'invalid':
        status = user_model.Status.BANNED
    else:
        operation.counters.Increment('Bad status')
        logging.warning('Invalid status %s for user %s', user.status,
                        user.key().name())
        return

    host_for = []
    for sponsor_key in user.host_for:
        host_for.extend(
            map(
                ndb.Key.from_old_key,
                GSoCProgram.all(keys_only=True).filter(
                    'sponsor', sponsor_key).fetch(1000)))
        host_for.extend(
            map(
                ndb.Key.from_old_key,
                GCIProgram.all(keys_only=True).filter(
                    'sponsor', sponsor_key).fetch(1000)))

    account = user.account

    new_user = NewUser(id=entity_id,
                       account_id=account_id,
                       status=status,
                       host_for=host_for,
                       account=account)
    _createUserTxn(new_user)
Exemplo n.º 8
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(*[
      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')
Exemplo n.º 9
0
def convertUser(user_key):
  """Converts the specified user by creating a new user entity that inherits
  from the newly added NewUser model.

  Args:
    user_key: User key.
  """
  user = User.get(user_key)

  entity_id = user.key().name()
  account_id = user.user_id or 'unset'

  if user.status == 'valid':
    status = user_model.Status.ACTIVE
  elif user.status == 'invalid':
    status = user_model.Status.BANNED
  else:
    operation.counters.Increment('Bad status')
    logging.warning(
        'Invalid status %s for user %s', user.status, user.key().name())
    return

  host_for = []
  for sponsor_key in user.host_for:
    host_for.extend(map(
        ndb.Key.from_old_key,
        GSoCProgram.all(keys_only=True)
            .filter('sponsor', sponsor_key).fetch(1000)))
    host_for.extend(map(
        ndb.Key.from_old_key,
        GCIProgram.all(keys_only=True)
            .filter('sponsor', sponsor_key).fetch(1000)))

  account = user.account

  new_user = NewUser(
      id=entity_id, account_id=account_id, status=status, host_for=host_for,
      account=account)
  _createUserTxn(new_user)
Exemplo n.º 10
0
 def __init__(self):
   self.programs = GSoCProgram.all().fetch(1000)