Ejemplo n.º 1
0
    def getListData(self):
        """Returns the list data as requested by the current request.

    If the lists as requested is not supported by this component None is
    returned.
    """
        if lists.getListIndex(self.data.request) != 1:
            return None

        q = GCITask.all()
        q.filter('program', self.data.program)
        q.filter(
            'org IN',
            map(lambda org_key: org_key.to_old_key(),
                self.data.ndb_profile.mentor_for))

        starter = lists.keyStarter
        # TODO(daniel): enable prefetching
        #prefetcher = lists.ListModelPrefetcher(
        #    GCITask, ['org', 'student', 'created_by', 'modified_by'], ['mentors'])

        response_builder = lists.RawQueryContentResponseBuilder(
            self.data.request, self._list_config, q, starter, prefetcher=None)

        return response_builder.build()
Ejemplo n.º 2
0
def getRemainingTaskQuota(org):
    """Returns the number of remaining tasks that the organization can publish.

  While calculating the remaining quota we consider all the tasks that
  were published including the closed tasks but not the deleted tasks.

  Args:
    org: The organization entity for which the quota must be calculated

  Returns:
    An integer which is the number of tasks the organization can publish yet
  """
    # TODO(Madhu): Refactor to create Open Tasks and Closed tasks variables
    # count all the tasks the organization has published till now.
    # This excludes tasks in Unapproved, Unpublished and Invalid states.
    valid_status = [
        "Open",
        "Reopened",
        "ClaimRequested",
        "Claimed",
        "ActionNeeded",
        "Closed",
        "AwaitingRegistration",
        "NeedsWork",
        "NeedsReview",
    ]

    q = GCITask.all()
    q.filter("org", org)
    q.filter("status IN", valid_status)

    return org.task_quota_limit - q.count()
Ejemplo n.º 3
0
    def context(self):
        context = {
            'user_email':
            accounts.denormalizeAccount(self.data.user.account).email(),
            'link_id':
            self.data.user.link_id,
            'logout_link':
            links.LINKER.logout(self.data.request),
            'dashboard_link':
            links.LINKER.program(self.data.program, 'gci_dashboard')
        }

        # TODO(daniel): simplify this if statement
        if self.data.ndb_profile:
            if (self.data.ndb_profile.is_student
                    and self.data.ndb_profile.status
                    == profile_model.Status.ACTIVE):
                q = GCITask.all()
                q.filter('student', self.data.ndb_profile.key.to_old_key())
                q.filter('status IN', ACTIVE_CLAIMED_TASK)
                task = q.get()
                if task:
                    context['task'] = task
                    context['time_left'] = self.getTimeLeftForTask(task)
                    task_url = self.data.redirect.id(
                        task.key().id()).urlOf('gci_view_task')
                    context['task_url'] = task_url
        return context
Ejemplo n.º 4
0
  def _processStudentEntity(self, entity, properties):
    query = GCITask.all()
    query.filter('student', entity)
    query.filter('status', 'Closed')
    no_of_tasks = query.count()

    properties['number_of_tasks_completed'] = no_of_tasks
Ejemplo n.º 5
0
  def recalculateForStudent(self, request, *args, **kwargs):
    """Recalculates GCI Student Ranking for the specified student.

    Args in POST:
      key: The string version of the key for the GCIProfile entity
           representing the student.
    """
    post_dict = request.POST
    key = db.Key(post_dict['key'])
    student = GCIProfile.get(key)

    if not student:
      logging.warning('Enqueued task to recalculate ranking for '
                      'non-existent student %s' %(key))
      return responses.terminateTask()

    # get all the tasks that the student has completed
    q = GCITask.all()
    q.filter('student', student)
    q.filter('status', 'Closed')
    tasks = q.fetch(1000)

    ranking_logic.calculateRankingForStudent(student, tasks)

    return responses.terminateTask()
Ejemplo n.º 6
0
    def recalculateForStudent(self, request, *args, **kwargs):
        """Recalculates GCI Student Ranking for the specified student.

    Args in POST:
      key: The string version of the key for the GCIProfile entity
           representing the student.
    """
        post_dict = request.POST
        key = db.Key(post_dict['key'])
        student = GCIProfile.get(key)

        if not student:
            logging.warning(
                'Enqueued task to recalculate ranking for '
                'non-existent student %s', key)
            return responses.terminateTask()

        # get all the tasks that the student has completed
        q = GCITask.all()
        q.filter('student', student)
        q.filter('status', 'Closed')
        tasks = q.fetch(1000)

        score_logic.calculateRankingForStudent(student, tasks)

        return responses.terminateTask()
Ejemplo n.º 7
0
  def getListData(self):
    """Returns the list data as requested by the current request.

    If the lists as requested is not supported by this component None is
    returned.
    """
    if lists.getListIndex(self.data.request) != 1:
      return None

    q = GCITask.all()
    q.filter('program', self.data.program)
    q.filter(
        'org IN',
        map(lambda org_key: org_key.to_old_key(),
            self.data.ndb_profile.mentor_for))

    starter = lists.keyStarter
    # TODO(daniel): enable prefetching
    #prefetcher = lists.ListModelPrefetcher(
    #    GCITask, ['org', 'student', 'created_by', 'modified_by'], ['mentors'])

    response_builder = lists.RawQueryContentResponseBuilder(
        self.data.request, self._list_config, q, starter,
        prefetcher=None)

    return response_builder.build()
Ejemplo n.º 8
0
def queryAllTasksClosedByStudent(profile, keys_only=False):
  """Returns a query for all the tasks that have been closed by the
  specified profile.
  """
  if not profile.student_info:
    raise ValueError('Only students can be queried for closed tasks.')

  return GCITask.all(keys_only=keys_only).filter(
      'student', profile).filter('status', 'Closed')
  
Ejemplo n.º 9
0
  def getListData(self):
    if lists.getListIndex(self.request) != 0:
      return None
    q = GCITask.all()
    q.filter('org', self.data.organization)
    q.filter('status IN', CLAIMABLE)
    starter = lists.keyStarter

    response_builder = lists.RawQueryContentResponseBuilder(
        self.request, self.list_config, q, starter)
    return response_builder.build()
Ejemplo n.º 10
0
    def getListData(self):
        if lists.getListIndex(self.data.request) != 1:
            return None
        q = GCITask.all()
        q.filter('org', self.data.organization)
        q.filter('status', 'Closed')
        starter = lists.keyStarter

        response_builder = lists.RawQueryContentResponseBuilder(
            self.data.request, self.list_config, q, starter)
        return response_builder.build()
Ejemplo n.º 11
0
    def getListData(self):
        idx = lists.getListIndex(self.data.request)
        if idx == 0:
            q = GCITask.all()
            q.filter('program', self.data.program)
            q.filter('status', 'Closed')

            response_builder = lists.RawQueryContentResponseBuilder(
                self.data.request, self._list_config, q, lists.keyStarter)

            return response_builder.build()
        else:
            return None
Ejemplo n.º 12
0
  def getListData(self):
    idx = lists.getListIndex(self.data.request)
    if idx == 0:
      q = GCITask.all()
      q.filter('program', self.data.program)
      q.filter('status', 'Closed')

      response_builder = lists.RawQueryContentResponseBuilder(
          self.data.request, self._list_config, q, lists.keyStarter)

      return response_builder.build()
    else:
      return None
Ejemplo n.º 13
0
    def recalculateGCIRanking(self, request, *args, **kwargs):
        """Recalculates student ranking for the entire program.

    Args in POST dict:
      cursor: Query cursor to figure out where we need to start processing
    """

        key_name = '%s/%s' % (kwargs['sponsor'], kwargs['program'])
        cursor = request.POST.get('cursor')

        program = GCIProgram.get_by_key_name(key_name)
        if not program:
            logging.warning(
                'Enqueued recalculate ranking task for non-existing program: %s',
                key_name)
            return responses.terminateTask()

        # Retrieve the students for the program
        q = GCIProfile.all()
        q.filter('program', program)
        q.filter('is_student', True)

        if cursor:
            q.with_cursor(cursor)

        students = q.fetch(25)

        for student in students:
            # get all the tasks that the student has completed
            task_q = GCITask.all()
            task_q.filter('student', student)
            task_q.filter('status', 'Closed')

            tasks = task_q.fetch(1000)

            # calculate score with all the tasks
            score_logic.calculateScore(student, tasks, program)

            # calculate org score with all the tasks
            db.run_in_transaction(org_score_logic.updateOrgScoresTxn(tasks))

        if students:
            # schedule task to do the rest of the students
            params = {
                'cursor': q.cursor(),
            }
            taskqueue.add(queue_name='gci-update',
                          url=request.path,
                          params=params)

        return responses.terminateTask()
Ejemplo n.º 14
0
  def recalculateGCIRanking(self, request, *args, **kwargs):
    """Recalculates student ranking for the entire program.

    Args in POST dict:
      cursor: Query cursor to figure out where we need to start processing
    """

    key_name = '%s/%s' % (kwargs['sponsor'], kwargs['program'])
    cursor = request.POST.get('cursor')

    program = GCIProgram.get_by_key_name(key_name)
    if not program:
      logging.warning(
          'Enqueued recalculate ranking task for non-existing '
          'program: %s' %key_name)
      return responses.terminateTask()

    # Retrieve the students for the program
    q = GCIProfile.all()
    q.filter('scope', program)
    q.filter('is_student', True)

    if cursor:
      q.with_cursor(cursor)

    students = q.fetch(25)

    for student in students:
      # get all the tasks that the student has completed
      task_q = GCITask.all()
      task_q.filter('student', student)
      task_q.filter('status', 'Closed')

      tasks = task_q.fetch(1000)

      # calculate ranking with all the tasks
     # ranking_logic.calculateRankingForStudent(student, tasks)
      ranking_logic.calculateScore(student, tasks, program)

    if students:
      # schedule task to do the rest of the students
      params = {
          'cursor': q.cursor(),
          }
      taskqueue.add(queue_name='gci-update', url=request.path, params=params)

    return responses.terminateTask()
Ejemplo n.º 15
0
def clear(*args, **kwargs):
    """Removes all entities from the datastore.
  """

    # TODO(dbentley): If there are more than 1000 instances of any model,
    # this method will not clear all instances.  Instead, it should continually
    # call .all(), delete all those, and loop until .all() is empty.
    entities = itertools.chain(*[
        Survey.all(),
        SurveyRecord.all(),
        GCIOrganization.all(),
        GSoCTimeline.all(),
        GCITimeline.all(),
        GSoCProgram.all(),
        GSoCProject.all(),
        GSoCProposal.all(),
        GCIProgram.all(),
        GCIScore.all(),
        GSoCStudentInfo.all(),
        GCIStudentInfo.all(),
        GCITask.all(),
        Sponsor.all(),
        Site.all(),
        Document.all(),
        # The below models are all subclasses of ndb.Model and therefore must
        # use .query() to return all instances instead of .all().
        soc_org_model.SOCOrganization.query(),
        profile_model.Profile.query(),
        soc_profile.SOCStudentData.query(),
        user.User.query(),
        address.Address.query(),
        contact.Contact.query()
    ])

    try:
        for entity in entities:
            if isinstance(entity, ndb.Model):
                entity.key.delete()
            else:
                entity.delete()
    except db.Timeout:
        return http.HttpResponseRedirect('#')
    memcache.flush_all()

    return http.HttpResponse('Done')
Ejemplo n.º 16
0
def clear(*args, **kwargs):
  """Removes all entities from the datastore.
  """

  # TODO(dbentley): If there are more than 1000 instances of any model,
  # this method will not clear all instances.  Instead, it should continually
  # call .all(), delete all those, and loop until .all() is empty.
  entities = itertools.chain(*[
      Survey.all(),
      SurveyRecord.all(),
      GCIOrganization.all(),
      GSoCTimeline.all(),
      GCITimeline.all(),
      GSoCProgram.all(),
      GSoCProject.all(),
      GSoCProposal.all(),
      GCIProgram.all(),
      GCIScore.all(),
      GSoCStudentInfo.all(),
      GCIStudentInfo.all(),
      GCITask.all(),
      Sponsor.all(),
      Site.all(),
      Document.all(),
      # The below models are all subclasses of ndb.Model and therefore must
      # use .query() to return all instances instead of .all().
      soc_org_model.SOCOrganization.query(),
      profile_model.Profile.query(),
      soc_profile.SOCStudentData.query(),
      user.User.query(),
      address.Address.query(),
      contact.Contact.query()
      ])

  try:
    for entity in entities:
      if isinstance(entity, ndb.Model):
        entity.key.delete()
      else:
        entity.delete()
  except db.Timeout:
    return http.HttpResponseRedirect('#')
  memcache.flush_all()

  return http.HttpResponse('Done')
Ejemplo n.º 17
0
    def recalculateGCIRanking(self, request, *args, **kwargs):
        """Recalculates student ranking for the entire program.

    Args in POST dict:
      cursor: Query cursor to figure out where we need to start processing
    """

        key_name = "%s/%s" % (kwargs["sponsor"], kwargs["program"])
        cursor = request.POST.get("cursor")

        program = GCIProgram.get_by_key_name(key_name)
        if not program:
            logging.warning("Enqueued recalculate ranking task for non-existing program: %s", key_name)
            return responses.terminateTask()

        # Retrieve the students for the program
        q = GCIProfile.all()
        q.filter("program", program)
        q.filter("is_student", True)

        if cursor:
            q.with_cursor(cursor)

        students = q.fetch(25)

        for student in students:
            # get all the tasks that the student has completed
            task_q = GCITask.all()
            task_q.filter("student", student)
            task_q.filter("status", "Closed")

            tasks = task_q.fetch(1000)

            # calculate score with all the tasks
            score_logic.calculateScore(student, tasks, program)

            # calculate org score with all the tasks
            db.run_in_transaction(org_score_logic.updateOrgScoresTxn(tasks))

        if students:
            # schedule task to do the rest of the students
            params = {"cursor": q.cursor()}
            taskqueue.add(queue_name="gci-update", url=request.path, params=params)

        return responses.terminateTask()
Ejemplo n.º 18
0
def clear(*args, **kwargs):
  """Removes all entities from the datastore.
  """

  # TODO(dbentley): If there are more than 1000 instances of any model,
  # this method will not clear all instances.  Instead, it should continually
  # call .all(), delete all those, and loop until .all() is empty.
  entities = itertools.chain(*[
      Notification.all(),
      GCIStudent.all(),
      Survey.all(),
      SurveyRecord.all(),
      StudentProposal.all(),
      GSoCOrganization.all(),
      GCIOrganization.all(),
      GSoCTimeline.all(),
      GCITimeline.all(),
      GSoCProgram.all(),
      GSoCProfile.all(),
      GCIProfile.all(),
      GSoCProposal.all(),
      GCIProgram.all(),
      GCIScore.all(),
      GSoCStudentInfo.all(),
      GCIStudentInfo.all(),
      GCITask.all(),
      Host.all(),
      Sponsor.all(),
      User.all(),
      Site.all(),
      Document.all(),
      ])

  try:
    for entity in entities:
      entity.delete()
  except db.Timeout:
    return http.HttpResponseRedirect('#')
  # pylint: disable=E1101
  memcache.flush_all()

  return http.HttpResponse('Done')
Ejemplo n.º 19
0
def canClaimRequestTask(task, profile):
  """Returns true if the given profile is allowed to claim the task.

  Args:
    task: The 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 CLAIMABLE:
    return False

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

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

  return count < max_tasks
Ejemplo n.º 20
0
    def getListData(self):
        """Returns the list data as requested by the current request.

    If the lists as requested is not supported by this component None is
    returned.
    """
        if lists.getListIndex(self.request) != 1:
            return None

        q = GCITask.all()
        q.filter("program", self.data.program)
        q.filter("org IN", self.data.mentor_for)

        starter = lists.keyStarter
        prefetcher = lists.listModelPrefetcher(GCITask, ["org", "student", "created_by", "modified_by"], ["mentors"])

        response_builder = lists.RawQueryContentResponseBuilder(
            self.request, self._list_config, q, starter, prefetcher=prefetcher
        )

        return response_builder.build()
Ejemplo n.º 21
0
  def context(self):
    context = {
        'user_email': accounts.denormalizeAccount(self.data.user.account).email(),
        'link_id': self.data.user.link_id,
        'logout_link': self.data.redirect.logout().url(),
        'dashboard_link': self.data.redirect.dashboard().url()
    }

    if self.data.profile:
      if self.data.is_student and self.data.profile.status == 'active':
        q = GCITask.all()
        q.filter('student', self.data.profile)
        q.filter('status IN', ACTIVE_CLAIMED_TASK)
        task = q.get()
        if task:
          context['task'] = task
          context['time_left'] = self.getTimeLeftForTask(task)
          task_url = self.data.redirect.id(
              task.key().id()).urlOf('gci_view_task')
          context['task_url'] = task_url
    return context
Ejemplo n.º 22
0
  def context(self):
    context = {
        'user_email': accounts.denormalizeAccount(self.data.user.account).email(),
        'link_id': self.data.user.link_id,
        'logout_link': links.LINKER.logout(self.data.request),
        'dashboard_link': links.LINKER.program(
            self.data.program, 'gci_dashboard')
    }

    # TODO(daniel): simplify this if statement
    if self.data.ndb_profile:
      if (self.data.ndb_profile.is_student
          and self.data.ndb_profile.status == profile_model.Status.ACTIVE):
        q = GCITask.all()
        q.filter('student', self.data.ndb_profile.key.to_old_key())
        q.filter('status IN', ACTIVE_CLAIMED_TASK)
        task = q.get()
        if task:
          context['task'] = task
          context['time_left'] = self.getTimeLeftForTask(task)
          task_url = self.data.redirect.id(
              task.key().id()).urlOf('gci_view_task')
          context['task_url'] = task_url
    return context
Ejemplo n.º 23
0
def new_task_for_old(task):
  q = GCITask.all(keys_only=True)
  q.filter('org', task.scope)
  q.filter('link_id', task.link_id)
  return q.get()
Ejemplo n.º 24
0
  def queryForTask():
    query = GCITask.all()
    query.filter('is_featured', True)
    query.filter('program', program)

    return query
Ejemplo n.º 25
0
def queryClaimableTasksForProgram(program):
  q = GCITask.all()
  q.filter('program', program)
  q.filter('status IN', CLAIMABLE)
  return q