Exemple #1
0
def closeTask(task, profile):
  """Closes the task.

  Args:
    task: task_model.GCITask entity.
    profile: GCIProfile of the user that closes the task.
  """
  from soc.modules.gci.tasks.ranking_update import startUpdatingTask

  task.status = 'Closed'
  task.closed_on = datetime.datetime.now()
  task.deadline = None

  comment_props = {
      'parent': task,
      'title': DEF_CLOSED_TITLE,
      'content': DEF_CLOSED,
      'created_by': profile.key.parent().to_old_key()
  }
  comment = GCIComment(**comment_props)

  comment_txn = comment_logic.storeAndNotifyTxn(comment)

  student_key = ndb.Key.from_old_key(
      task_model.GCITask.student.get_value_for_datastore(task))
  student = student_key.get()

  # student, who worked on the task, should receive a confirmation
  # having submitted his or her first task
  query = queryAllTasksClosedByStudent(student, keys_only=True)
  if query.get() is None: # this is the first task
    confirmation = profile_logic.sendFirstTaskConfirmationTxn(student, task)
  else:
    confirmation = lambda: None

  org_score_txn = org_score_logic.updateOrgScoreTxn(task, student)

  @db.transactional(xg=True)
  def closeTaskTxn():
    task.put()
    comment_txn()
    startUpdatingTask(task, transactional=True)
    confirmation()
    org_score_txn()

  # TODO(daniel): move this to a transaction when other models are NDB
  student = student_key.get()
  student.student_data.number_of_completed_tasks += 1
  student.put()

  return closeTaskTxn()
Exemple #2
0
def closeTask(task, profile):
    """Closes the task.

  Args:
    task: task_model.GCITask entity.
    profile: GCIProfile of the user that closes the task.
  """
    from soc.modules.gci.tasks.ranking_update import startUpdatingTask

    task.status = "Closed"
    task.closed_on = datetime.datetime.now()
    task.deadline = None

    comment_props = {
        "parent": task,
        "title": DEF_CLOSED_TITLE,
        "content": DEF_CLOSED,
        "created_by": profile.key.parent().to_old_key(),
    }
    comment = GCIComment(**comment_props)

    comment_txn = comment_logic.storeAndNotifyTxn(comment)

    student_key = ndb.Key.from_old_key(task_model.GCITask.student.get_value_for_datastore(task))
    student = student_key.get()

    # student, who worked on the task, should receive a confirmation
    # having submitted his or her first task
    query = queryAllTasksClosedByStudent(student, keys_only=True)
    if query.get() is None:  # this is the first task
        confirmation = profile_logic.sendFirstTaskConfirmationTxn(student, task)
    else:
        confirmation = lambda: None

    org_score_txn = org_score_logic.updateOrgScoreTxn(task, student)

    @db.transactional(xg=True)
    def closeTaskTxn():
        task.put()
        comment_txn()
        startUpdatingTask(task, transactional=True)
        confirmation()
        org_score_txn()

    # TODO(daniel): move this to a transaction when other models are NDB
    student = student_key.get()
    student.student_data.number_of_completed_tasks += 1
    student.put()

    return closeTaskTxn()
Exemple #3
0
def closeTask(task, profile):
  """Closes the task.

  Args:
    task: GCITask entity.
    profile: GCIProfile of the user that closes the task.
  """
  from soc.modules.gci.tasks.ranking_update import startUpdatingTask

  task.status = 'Closed'
  task.closed_on = datetime.datetime.now()
  task.deadline = None

  comment_props = {
      'parent': task,
      'title': DEF_CLOSED_TITLE,
      'content': DEF_CLOSED,
      'created_by': profile.user
  }
  comment = GCIComment(**comment_props)

  comment_txn = comment_logic.storeAndNotifyTxn(comment)

  student = task.student

  # student, who worked on the task, should receive a confirmation
  # having submitted his first task
  query = queryAllTasksClosedByStudent(student, keys_only=True)
  if query.get() is None: # this is the first task
    confirmation = profile_logic.sendFirstTaskConfirmationTxn(student, task)
  else:
    confirmation = lambda: None
  
  def closeTaskTxn():
    task.put()
    comment_txn()
    startUpdatingTask(task, transactional=True)
    confirmation()

  return db.run_in_transaction(closeTaskTxn)