Ejemplo n.º 1
0
def spawnBulkCreateTasks(data, org, org_admin):
  """Spawns a task to bulk post the given data.

  The data given to this method should be in CSV format with the following
  columns:
      title, description, time_to_complete, mentors, difficulty, task_type,
      arbit_tag

  Fields where multiple values are allowed should be comma separated as well.
  These fields are task_type, arbit_tag and mentors. Rows of data which can not
  be properly resolved to form a valid Task will be safely ignored.

  Args:
    data: string with data in csv format
    org: GCIOrganization for which the tasks are created
    org_admin: GCIProfile of the org admin uploading these tasks
  """
  data = StringIO.StringIO(data.encode('UTF-8'))
  tasks = csv.DictReader(data, fieldnames=DATA_HEADERS, restval="")

  task_list = []
  for task in tasks:
    # pop any extra columns
    task.pop(None,None)
    task_list.append(db.Text(simplejson.dumps(task)))

  bulk_data = GCIBulkCreateData(
      tasks=task_list, org=org, created_by=org_admin,
      total_tasks=len(task_list))
  bulk_data.put()

  task_params = {
      'bulk_create_key': bulk_data.key()
      }

  logging.info('Enqueued bulk_create with: %s' % task_params)
  new_task = taskqueue.Task(params=task_params,
                            url=BULK_CREATE_URL)
  new_task.add()
Ejemplo n.º 2
0
def spawnBulkCreateTasks(data, org, org_admin):
    """Spawns a task to bulk post the given data.

  The data given to this method should be in CSV format with the following
  columns:
      title, description, time_to_complete, mentors, difficulty, task_type,
      arbit_tag

  Fields where multiple values are allowed should be comma separated as well.
  These fields are task_type, arbit_tag and mentors. Rows of data which can not
  be properly resolved to form a valid Task will be safely ignored.

  Args:
    data: string with data in csv format
    org: GCIOrganization for which the tasks are created
    org_admin: GCIProfile of the org admin uploading these tasks
  """
    data = StringIO.StringIO(data.encode('UTF-8'))
    tasks = csv.DictReader(data, fieldnames=DATA_HEADERS, restval="")

    task_list = []
    for task in tasks:
        # pop any extra columns
        task.pop(None, None)
        task_list.append(db.Text(json.dumps(task)))

    bulk_data = GCIBulkCreateData(tasks=task_list,
                                  org=org,
                                  created_by=org_admin.key.to_old_key(),
                                  total_tasks=len(task_list))
    bulk_data.put()

    task_params = {'bulk_create_key': bulk_data.key()}

    logging.info('Enqueued bulk_create with: %s', task_params)
    new_task = taskqueue.Task(params=task_params, url=BULK_CREATE_URL)
    new_task.add()