Exemplo n.º 1
0
def downloadStudentForms(options):
  from google.appengine.ext import db
  from soc.views.helper import lists as list_helper
  from soc.modules.gsoc.models.profile import GSoCStudentInfo


  q = lambda: GSoCStudentInfo.all().filter('number_of_projects', 1)

  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

  print "Fetching StudentInfo..."
  students = list(i for i in interactive.deepFetch(q) if i.tax_form)

  keys = list_helper.collectParentKeys(students)
  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))

  list_helper.distributeParentKeys(students, prefetched)

  countries = ['United States']
  us_students = [i for i in students if i.parent().res_country in countries]

  for student in us_students:
    form = student.tax_form
    _, ext = os.path.splitext(form.filename)
    path = os.path.join(outputdir, student.parent().link_id + ext)
    dst = open(path, "w")
    src = form.open()
    shutil.copyfileobj(src, dst)
    print "Downloading form to '%s'..." % path

  print "Done."
Exemplo n.º 2
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.º 3
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.º 4
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')