Beispiel #1
0
  def setButtonControls(self, context):
    """Enables buttons on the TaskInformation block based on status and the
    user.

    Args:
      context: Context dictionary which to write to.
    """
    profile = self.data.profile
    if not profile:
      # no buttons for someone without a profile
      return

    if self.data.timeline.allReviewsStopped():
      # no buttons after all reviews has stopped
      return

    task = self.data.task

    is_org_admin = self.data.orgAdminFor(task.org)
    is_mentor = self.data.mentorFor(task.org)
    is_student = self.data.is_student
    is_owner = task_logic.isOwnerOfTask(task, profile)

    if is_org_admin:
      can_unpublish = (task.status in CLAIMABLE) and not task.student
      context['button_unpublish'] = can_unpublish
      context['button_delete'] = not task.student

    if is_mentor:
      context['button_edit'] = task.status in \
          UNPUBLISHED + CLAIMABLE + ACTIVE_CLAIMED_TASK
      context['button_assign'] = task.status == 'ClaimRequested'
      context['button_unassign'] = task.status in ACTIVE_CLAIMED_TASK
      context['button_close'] = task.status == 'NeedsReview'
      context['button_needs_work'] = task.status == 'NeedsReview'
      context['button_extend_deadline'] = task.status in TASK_IN_PROGRESS

    if is_student:
      if not self.data.timeline.tasksClaimEnded():
        context['button_claim'] = task_logic.canClaimRequestTask(
            task, profile)

    if is_owner:
      if not self.data.timeline.tasksClaimEnded():
        context['button_unclaim'] = task.status in ACTIVE_CLAIMED_TASK

    if task.status != 'Closed':
      context['button_subscribe'] = not profile.key() in task.subscribers
      context['button_unsubscribe'] = profile.key() in task.subscribers
Beispiel #2
0
    def setButtonControls(self, context):
        """Enables buttons on the TaskInformation block based on status and the
    user.

    Args:
      context: Context dictionary which to write to.
    """
        if not self.data.ndb_profile:
            # no buttons for someone without a profile
            return

        if self.data.timeline.allReviewsStopped():
            # no buttons after all reviews has stopped
            return

        task = self.data.task

        is_org_admin = self.data.orgAdminFor(task.org.key())
        is_mentor = self.data.mentorFor(task.org.key())
        is_student = self.data.ndb_profile.is_student
        is_owner = task_logic.isOwnerOfTask(task, self.data.ndb_profile)

        if is_org_admin:
            can_unpublish = task.status == task_model.OPEN and not task.student
            context['button_unpublish'] = can_unpublish

            can_publish = task.status in task_model.UNAVAILABLE
            context['button_publish'] = can_publish

            context['button_delete'] = not task.student

        if is_mentor:
            context['button_edit'] = task.status in \
                task_model.UNAVAILABLE + CLAIMABLE + ACTIVE_CLAIMED_TASK
            context['button_assign'] = task.status == 'ClaimRequested'
            context['button_unassign'] = task.status in ACTIVE_CLAIMED_TASK
            context['button_close'] = task.status == 'NeedsReview'
            context['button_needs_work'] = task.status == 'NeedsReview'
            context['button_extend_deadline'] = task.status in TASK_IN_PROGRESS

        if is_student:
            if not self.data.timeline.tasksClaimEnded():
                if not profile_logic.hasStudentFormsUploaded(
                        self.data.ndb_profile):
                    # TODO(nathaniel): make this .program() call unnecessary.
                    self.data.redirect.program()

                    context['student_forms_link'] = self.data.redirect.urlOf(
                        url_names.GCI_STUDENT_FORM_UPLOAD)
                # TODO(lennie): Separate the access check out in to different
                # methods and add a context variable to show separate messages.'
                context['button_claim'] = task_logic.canClaimRequestTask(
                    task, self.data.ndb_profile)

        if is_owner:
            if not self.data.timeline.tasksClaimEnded():
                context['button_unclaim'] = task.status in ACTIVE_CLAIMED_TASK

        if task.status != 'Closed':
            task_subscribers_keys = map(ndb.Key.from_old_key, task.subscribers)
            context['button_subscribe'] = (not self.data.ndb_profile.key
                                           in task_subscribers_keys)
            context['button_unsubscribe'] = (not self.data.ndb_profile.key
                                             in task.subscribers)
Beispiel #3
0
  def setButtonControls(self, context):
    """Enables buttons on the TaskInformation block based on status and the
    user.

    Args:
      context: Context dictionary which to write to.
    """
    if not self.data.ndb_profile:
      # no buttons for someone without a profile
      return

    if self.data.timeline.allReviewsStopped():
      # no buttons after all reviews has stopped
      return

    task = self.data.task

    is_org_admin = self.data.orgAdminFor(task.org.key())
    is_mentor = self.data.mentorFor(task.org.key())
    is_student = self.data.ndb_profile.is_student
    is_owner = task_logic.isOwnerOfTask(task, self.data.ndb_profile)

    if is_org_admin:
      can_unpublish = task.status == task_model.OPEN and not task.student
      context['button_unpublish'] = can_unpublish

      can_publish = task.status in task_model.UNAVAILABLE
      context['button_publish'] = can_publish

      context['button_delete'] = not task.student

    if is_mentor:
      context['button_edit'] = task.status in \
          task_model.UNAVAILABLE + CLAIMABLE + ACTIVE_CLAIMED_TASK
      context['button_assign'] = task.status == 'ClaimRequested'
      context['button_unassign'] = task.status in ACTIVE_CLAIMED_TASK
      context['button_close'] = task.status == 'NeedsReview'
      context['button_needs_work'] = task.status == 'NeedsReview'
      context['button_extend_deadline'] = task.status in TASK_IN_PROGRESS

    if is_student:
      if not self.data.timeline.tasksClaimEnded():
        if not profile_logic.hasStudentFormsUploaded(self.data.ndb_profile):
          # TODO(nathaniel): make this .program() call unnecessary.
          self.data.redirect.program()

          context['student_forms_link'] = self.data.redirect.urlOf(
              url_names.GCI_STUDENT_FORM_UPLOAD)
        # TODO(lennie): Separate the access check out in to different
        # methods and add a context variable to show separate messages.'
        context['button_claim'] = task_logic.canClaimRequestTask(
            task, self.data.ndb_profile)

    if is_owner:
      if not self.data.timeline.tasksClaimEnded():
        context['button_unclaim'] = task.status in ACTIVE_CLAIMED_TASK

    if task.status != 'Closed':
      task_subscribers_keys = map(ndb.Key.from_old_key, task.subscribers)
      context['button_subscribe'] = (
          not self.data.ndb_profile.key in task_subscribers_keys)
      context['button_unsubscribe'] = (
          not self.data.ndb_profile.key in task.subscribers)