Exemplo n.º 1
0
  def context(self, data, check, mutator):
    """Handler for default HTTP GET request."""
    context = {'page_name': 'Student form upload'}

    form_data = {}
    if data.ndb_profile.student_data.consent_form:
      form_data['consent_form'] = blobstore.BlobInfo(
          data.ndb_profile.student_data.consent_form)
    if data.ndb_profile.student_data.enrollment_form:
      form_data['enrollment_form'] = blobstore.BlobInfo(
          data.ndb_profile.student_data.enrollment_form)

    upload_form = UploadForm(data, initial=form_data)

    if profile_logic.hasStudentFormsUploaded(data.ndb_profile):
      kwargs = dicts.filter(data.kwargs, ['sponsor', 'program'])
      claim_tasks_url = reverse('gci_list_tasks', kwargs=kwargs)
      context['form_instructions'] = CLAIM_TASKS_NOW % claim_tasks_url
    # TODO(ljvderijk): This can be removed when AppEngine supports 200 response
    # in the BlobStore API.
    if data.GET:
      for key, error in data.GET.iteritems():
        if not key.startswith('error_'):
          continue
        field_name = key.split('error_', 1)[1]
        upload_form.errors[field_name] = upload_form.error_class([error])

    context['form'] = upload_form
    context['form_verification_awaiting'] = (
        ci_profile_logic.isFormVerificationAwaiting(data.ndb_profile))

    return context
Exemplo n.º 2
0
    def context(self, data, check, mutator):
        """Handler for default HTTP GET request."""
        context = {'page_name': 'Student form upload'}

        form_data = {}
        if data.ndb_profile.student_data.consent_form:
            form_data['consent_form'] = blobstore.BlobInfo(
                data.ndb_profile.student_data.consent_form)
        if data.ndb_profile.student_data.enrollment_form:
            form_data['enrollment_form'] = blobstore.BlobInfo(
                data.ndb_profile.student_data.enrollment_form)

        upload_form = UploadForm(data, initial=form_data)

        if profile_logic.hasStudentFormsUploaded(data.ndb_profile):
            kwargs = dicts.filter(data.kwargs, ['sponsor', 'program'])
            claim_tasks_url = reverse('gci_list_tasks', kwargs=kwargs)
            context['form_instructions'] = CLAIM_TASKS_NOW % claim_tasks_url
        # TODO(ljvderijk): This can be removed when AppEngine supports 200 response
        # in the BlobStore API.
        if data.GET:
            for key, error in data.GET.iteritems():
                if not key.startswith('error_'):
                    continue
                field_name = key.split('error_', 1)[1]
                upload_form.errors[field_name] = upload_form.error_class(
                    [error])

        context['form'] = upload_form
        context['form_verification_awaiting'] = (
            ci_profile_logic.isFormVerificationAwaiting(data.ndb_profile))

        return context
Exemplo n.º 3
0
  def context(self, data, check, mutator):
    context = super(GCIProfilePage, self).context(data, check, mutator)

    if self.isCreateProfileRequest(data):
      if self.isStudentRequest(data):
        context['form_instructions'] = PARENTAL_CONSENT_ADVICE
    else:
      if data.is_student and \
          not profile_logic.hasStudentFormsUploaded(data.student_info):
        kwargs = dicts.filter(data.kwargs, ['sponsor', 'program'])
        upload_forms_url = reverse(
            url_names.GCI_STUDENT_FORM_UPLOAD, kwargs=kwargs)

        context['form_instructions'] = UPLOAD_FORMS_REMINDER % upload_forms_url
      context['edit_profile'] = True

    return context
Exemplo n.º 4
0
    def context(self, data, check, mutator):
        context = super(GCIProfilePage, self).context(data, check, mutator)

        if self.isCreateProfileRequest(data):
            if self.isStudentRequest(data):
                context['form_instructions'] = PARENTAL_CONSENT_ADVICE
        else:
            if data.is_student and \
                not profile_logic.hasStudentFormsUploaded(data.student_info):
                kwargs = dicts.filter(data.kwargs, ['sponsor', 'program'])
                upload_forms_url = reverse(url_names.GCI_STUDENT_FORM_UPLOAD,
                                           kwargs=kwargs)

                context[
                    'form_instructions'] = UPLOAD_FORMS_REMINDER % upload_forms_url
            context['edit_profile'] = True

        return context
Exemplo n.º 5
0
def canClaimRequestTask(task, profile):
    """Returns true if the given profile is allowed to claim the task.

  Args:
    task: The task_model.GCITask entity
    profile: The GCIProfile which we check whether it can claim the task.
  """
    # check if the task can be claimed at all
    if task.status not in task_model.CLAIMABLE:
        return False

    # check if the user is allowed to claim this task
    q = task_model.GCITask.all()
    q.filter("student", profile.key.to_old_key())
    q.filter("program", task.program)
    q.filter("status IN", task_model.ACTIVE_CLAIMED_TASK)

    max_tasks = task.program.nr_simultaneous_tasks
    count = q.count(max_tasks)

    has_forms = profile_logic.hasStudentFormsUploaded(profile)

    return count < max_tasks and has_forms
Exemplo n.º 6
0
def canClaimRequestTask(task, profile):
  """Returns true if the given profile is allowed to claim the task.

  Args:
    task: The task_model.GCITask entity
    profile: The GCIProfile which we check whether it can claim the task.
  """
  # check if the task can be claimed at all
  if task.status not in task_model.CLAIMABLE:
    return False

  # check if the user is allowed to claim this task
  q = task_model.GCITask.all()
  q.filter('student', profile.key.to_old_key())
  q.filter('program', task.program)
  q.filter('status IN', task_model.ACTIVE_CLAIMED_TASK)

  max_tasks = task.program.nr_simultaneous_tasks
  count = q.count(max_tasks)

  has_forms = profile_logic.hasStudentFormsUploaded(profile)

  return count < max_tasks and has_forms
Exemplo n.º 7
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)
Exemplo n.º 8
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)