예제 #1
0
    def _postButton(self, data):
        """Handles the POST call for any of the control buttons on the task page.
    """
        button_name = self._buttonName(data)
        task = data.task
        task_key = task.key()

        if button_name == 'button_unpublish':
            task_logic.unpublishTask(task, data.ndb_profile)
        elif button_name == 'button_publish':
            task_logic.publishTask(task, data.ndb_profile)
        elif button_name == 'button_edit':
            data.redirect.id(id=task.key().id_or_name())
            return data.redirect.to('gci_edit_task')
        elif button_name == 'button_delete':
            task_logic.delete(task)
            url = links.LINKER.program(data.program, 'gci_homepage')
            return http.HttpResponseRedirect(url)
        elif button_name == 'button_assign':
            student_key = ndb.Key.from_old_key(
                task_model.GCITask.student.get_value_for_datastore(task))
            task_logic.assignTask(task, student_key, data.ndb_profile)
        elif button_name == 'button_unassign':
            task_logic.unassignTask(task, data.ndb_profile)
        elif button_name == 'button_close':
            task_logic.closeTask(task, data.ndb_profile)
        elif button_name == 'button_needs_work':
            task_logic.needsWorkTask(task, data.ndb_profile)
        elif button_name == 'button_extend_deadline':
            hours = data.POST.get('hours', '')
            hours = int(hours) if hours.isdigit() else 0
            if hours > 0:
                delta = datetime.timedelta(hours=hours)
                task_logic.extendDeadline(task, delta, data.ndb_profile)
        elif button_name == 'button_claim':
            task_logic.claimRequestTask(task, data.ndb_profile)
        elif button_name == 'button_unclaim':
            task_logic.unclaimTask(task)
        elif button_name == 'button_subscribe':

            def txn():
                task = db.get(task_key)
                if data.ndb_profile.key.to_old_key() not in task.subscribers:
                    task.subscribers.append(data.ndb_profile.key.to_old_key())
                    task.put()

            db.run_in_transaction(txn)
        elif button_name == 'button_unsubscribe':

            def txn():
                task = db.get(task_key)
                if data.ndb_profile.key.to_old_key() in task.subscribers:
                    task.subscribers.remove(data.ndb_profile.key.to_old_key())
                    task.put()

            db.run_in_transaction(txn)

        return data.redirect.id().to(url_names.GCI_VIEW_TASK)
예제 #2
0
파일: task.py 프로젝트: adviti/melange
  def _postButton(self):
    """Handles the POST call for any of the control buttons on the task page.
    """
    button_name = self._buttonName()
    task = self.data.task
    task_key = task.key()

    if button_name == 'button_unpublish':
      def txn():
        task = db.get(task_key)
        task.status = 'Unpublished'
        task.put()
      db.run_in_transaction(txn)
    elif button_name == 'button_edit':
      r = self.redirect.id(id=task.key().id_or_name())
      r.to('gci_edit_task')
      return
    elif button_name == 'button_delete':
      task_logic.delete(task)
      self.redirect.homepage().to()
      return
    elif button_name == 'button_assign':
      task_logic.assignTask(task, task.student, self.data.profile)
    elif button_name == 'button_unassign':
      task_logic.unassignTask(task, self.data.profile)
    elif button_name == 'button_close':
      task_logic.closeTask(task, self.data.profile)
    elif button_name == 'button_needs_work':
      task_logic.needsWorkTask(task, self.data.profile)
    elif button_name == 'button_extend_deadline':
      hours = self.data.POST.get('hours', '')
      hours = int(hours) if hours.isdigit() else 0
      if hours > 0:
        delta = datetime.timedelta(hours=hours)
        task_logic.extendDeadline(task, delta, self.data.profile)
    elif button_name == 'button_claim':
      task_logic.claimRequestTask(task, self.data.profile)
    elif button_name == 'button_unclaim':
      task_logic.unclaimTask(task)
    elif button_name == 'button_subscribe':
      profile_key = self.data.profile.key()
      def txn():
        task = db.get(task_key)
        if profile_key not in task.subscribers:
          task.subscribers.append(profile_key)
          task.put()
      db.run_in_transaction(txn)
    elif button_name == 'button_unsubscribe':
      profile_key = self.data.profile.key()
      def txn():
        task = db.get(task_key)
        if profile_key in task.subscribers:
          task.subscribers.remove(profile_key)
          task.put()
      db.run_in_transaction(txn)

    self.redirect.id().to('gci_view_task')
예제 #3
0
파일: task.py 프로젝트: rhyolight/nupic.son
  def _postButton(self, data):
    """Handles the POST call for any of the control buttons on the task page.
    """
    button_name = self._buttonName(data)
    task = data.task
    task_key = task.key()

    if button_name == 'button_unpublish':
      task_logic.unpublishTask(task, data.ndb_profile)
    elif button_name == 'button_publish':
      task_logic.publishTask(task, data.ndb_profile)
    elif button_name == 'button_edit':
      data.redirect.id(id=task.key().id_or_name())
      return data.redirect.to('gci_edit_task')
    elif button_name == 'button_delete':
      task_logic.delete(task)
      url = links.LINKER.program(data.program, 'gci_homepage')
      return http.HttpResponseRedirect(url)
    elif button_name == 'button_assign':
      student_key = ndb.Key.from_old_key(
          task_model.GCITask.student.get_value_for_datastore(task))
      task_logic.assignTask(task, student_key, data.ndb_profile)
    elif button_name == 'button_unassign':
      task_logic.unassignTask(task, data.ndb_profile)
    elif button_name == 'button_close':
      task_logic.closeTask(task, data.ndb_profile)
    elif button_name == 'button_needs_work':
      task_logic.needsWorkTask(task, data.ndb_profile)
    elif button_name == 'button_extend_deadline':
      hours = data.POST.get('hours', '')
      hours = int(hours) if hours.isdigit() else 0
      if hours > 0:
        delta = datetime.timedelta(hours=hours)
        task_logic.extendDeadline(task, delta, data.ndb_profile)
    elif button_name == 'button_claim':
      task_logic.claimRequestTask(task, data.ndb_profile)
    elif button_name == 'button_unclaim':
      task_logic.unclaimTask(task)
    elif button_name == 'button_subscribe':
      def txn():
        task = db.get(task_key)
        if data.ndb_profile.key.to_old_key() not in task.subscribers:
          task.subscribers.append(data.ndb_profile.key.to_old_key())
          task.put()
      db.run_in_transaction(txn)
    elif button_name == 'button_unsubscribe':
      def txn():
        task = db.get(task_key)
        if data.ndb_profile.key.to_old_key() in task.subscribers:
          task.subscribers.remove(data.ndb_profile.key.to_old_key())
          task.put()
      db.run_in_transaction(txn)

    return data.redirect.id().to(url_names.GCI_VIEW_TASK)