Esempio n. 1
0
    def _constructFilterForProjectSelection(self, survey, params):
        """Returns the filter needed for the Project selection view.

    Returns a filter for all the valid projects for which the current user
    is a student. Of course only in the survey's scope.

    Args:
      survey: a Survey entity
      params: the params dict for the requesting view

    Returns:
      Dictionary that can be used as a input for a query.
    """

        from soc.logic.models.student import logic as student_logic

        survey_logic = params["logic"]

        user_entity = user_logic.getForCurrentAccount()

        # get the student entity for the current user and program
        fields = {"user": user_entity, "scope": survey_logic.getScope(survey), "status": "active"}

        student_entity = student_logic.getForFields(fields, unique=True)

        # TODO(ljvderijk) transform StudentProject to handle multiple surveys
        fields = {"student": student_entity, "status": "accepted"}

        return fields
Esempio n. 2
0
  def checkIsNotStudentForProgramOfOrg(self, django_args):
    """Checks if the current user has no active Student role for the program
       that the organization in the scope_path is participating in.

    Args:
      django_args: a dictionary with django's arguments

     Raises:
       AccessViolationResponse: if the current user is a student for the
                                program the organization is in.
    """

    if not django_args.get('scope_path'):
      raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_DENIED_MSG)

    org_entity = org_logic.getFromKeyNameOr404(django_args['scope_path'])
    user_entity = user_logic.getForCurrentAccount()

    filter = {'scope': org_entity.scope,
              'user': user_entity,
              'status': 'active'}

    student_role = student_logic.getForFields(filter=filter, unique=True)

    if student_role:
      raise out_of_band.AccessViolation(
          message_fmt=DEF_ALREADY_STUDENT_ROLE_MSG)

    return
Esempio n. 3
0
  def checkIsNotStudentForProgramInScope(self, django_args):
    """Checks if the current user is not a student for the given
       program in django_args.

    Args:
      django_args: a dictionary with django's arguments

     Raises:
       AccessViolationResponse: if the current user has a student
                                role for the given program.
    """

    if django_args.get('seed'):
      key_name = django_args['seed']['scope_path']
    else:
      key_name = django_args['scope_path']

    program_entity = program_logic.getFromKeyNameOr404(key_name)
    user_entity = user_logic.getForCurrentAccount()

    filter = {'user': user_entity,
              'scope': program_entity,
              'status': 'active'}

    # check if the current user is already a student for this program
    student_role = student_logic.getForFields(filter, unique=True)

    if student_role:
      raise out_of_band.AccessViolation(
          message_fmt=DEF_ALREADY_STUDENT_ROLE_MSG)

    return
Esempio n. 4
0
def runSchoolTypeUpdate(request, *args, **kwargs):
  """Appengine Task that adds school_type as University for existing
  Student entities in batches.

  Addition of required school_type property to Student model 
  requires addition of corresponding value to all the existing 
  Student entities in the datastore. Since this property is introduced
  during GSoC 2009 all students should be University students.
  This task sets the school_type value to "University" to
  all the existing entities.

  Args:
    request: Django Request object
  """

  from soc.logic.models.student import logic as student_logic

  fields = {}

  post_dict = request.POST

  start_key = post_dict.get('start_key')

  if start_key:
    # retrieve the last student entity that was converted
    start = student_logic.getFromKeyName(start_key)

    if not start:
      # invalid starting student key specified, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid Student Key specified: %s' %(start_key))

    fields['__key__ >'] = start.key()

  # get the first batch_size number of StudentProjects
  entities = student_logic.getForFields(fields, limit=DEF_BATCH_SIZE)

  for entity in entities:
    entity.school_type = 'University'

  db.put(entities)

  if len(entities) == DEF_BATCH_SIZE:
    # spawn new task starting from the last
    new_start = entities[DEF_BATCH_SIZE-1].key().id_or_name()

    # pass along these params as POST to the new task
    task_params = {'start_key': new_start}

    new_task = taskqueue.Task(params=task_params,
                              url=request.META['PATH_INFO'])
    new_task.add()

  # task completed, return OK
  return HttpResponse('OK')
Esempio n. 5
0
def runSchoolTypeUpdate(request, *args, **kwargs):
  """Appengine Task that adds school_type as University for existing
  Student entities in batches.

  Addition of required school_type property to Student model 
  requires addition of corresponding value to all the existing 
  Student entities in the datastore. Since this property is introduced
  during GSoC 2009 all students should be University students.
  This task sets the school_type value to "University" to
  all the existing entities.

  Args:
    request: Django Request object
  """

  from soc.logic.models.student import logic as student_logic

  fields = {}

  post_dict = request.POST

  start_key = post_dict.get('start_key')

  if start_key:
    # retrieve the last student entity that was converted
    start = student_logic.getFromKeyName(start_key)

    if not start:
      # invalid starting student key specified, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid Student Key specified: %s' %(start_key))

    fields['__key__ >'] = start.key()

  # get the first batch_size number of StudentProjects
  entities = student_logic.getForFields(fields, limit=DEF_BATCH_SIZE)

  for entity in entities:
    entity.school_type = 'University'

  db.put(entities)

  if len(entities) == DEF_BATCH_SIZE:
    # spawn new task starting from the last
    new_start = entities[DEF_BATCH_SIZE-1].key().id_or_name()

    # pass along these params as POST to the new task
    task_params = {'start_key': new_start}

    new_task = taskqueue.Task(params=task_params,
                              url=request.META['PATH_INFO'])
    new_task.add()

  # task completed, return OK
  return HttpResponse('OK')
Esempio n. 6
0
  def checkIsNotParticipatingInProgramInScope(self, django_args):
    """Checks if the current user has no roles for the given 
       program in django_args.

    Args:
      django_args: a dictionary with django's arguments

     Raises:
       AccessViolationResponse: if the current user has a student, mentor or
                                org admin role for the given program.
    """

    if not django_args.get('scope_path'):
      raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_DENIED_MSG)

    program_entity = program_logic.getFromKeyNameOr404(
        django_args['scope_path'])
    user_entity = user_logic.getForCurrentAccount()

    filter = {'user': user_entity,
              'scope': program_entity,
              'status': 'active'}

    # check if the current user is already a student for this program
    student_role = student_logic.getForFields(filter, unique=True)

    if student_role:
      raise out_of_band.AccessViolation(
          message_fmt=DEF_ALREADY_PARTICIPATING_MSG)

    # fill the role_list with all the mentor and org admin roles for this user
    # role_list = []

    filter = {'user': user_entity,
              'program': program_entity,
              'status': 'active'}

    mentor_role = mentor_logic.getForFields(filter, unique=True)
    if mentor_role:
      # the current user has a role for the given program
      raise out_of_band.AccessViolation(
            message_fmt=DEF_ALREADY_PARTICIPATING_MSG)

    org_admin_role = org_admin_logic.getForFields(filter, unique=True)
    if org_admin_role:
      # the current user has a role for the given program
      raise out_of_band.AccessViolation(
            message_fmt=DEF_ALREADY_PARTICIPATING_MSG)

    # no roles found, access granted
    return
Esempio n. 7
0
  def getStudentforProject(self, user, project):
    """Get student projects for a given User.

    params:
      user = survey taking user
      project = survey taker's student project
    """
    from soc.logic.models.student import logic as student_logic
    import soc.models.student

    # TODO this should be done per Student or Program
    # TODO filter for accepted, midterm_passed, etc?
    user_students = student_logic.getForFields({'user': user}) 
    if not user_students: return []
    return set([project.student for project in sum(
    (list(s.student_projects.run())
    for s in user_students), []) if project.key() == project.key()])
Esempio n. 8
0
def setupStudentProposalMailing(job_entity):
  """Job that setup jobs that will mail students if they have been accepted in
  a program with a GSoC-like workflow.

  Args:
    job_entity: a Job entity with key_data set to 
                [program, last_completed_student]
  """

  from soc.cron.job import FatalJobError


  # retrieve the data we need to continue our work
  key_data = job_entity.key_data
  program_key = key_data[0]
  program_keyname = program_key.name()

  program_entity = program_logic.getFromKeyName(program_keyname)

  if not program_entity:
    raise FatalJobError('The program with key %s could not be found' % (
        program_keyname))

  student_fields = {'scope': program_entity}

  if len(key_data) >= 2:
    # start where we left off
    student_fields['__key__ >'] = key_data[1]

  students = student_logic.getForFields(student_fields,
                                        limit=DEF_STUDENT_STEP_SIZE)

  # set the default fields for the jobs we are going to create
  priority_group = priority_logic.getGroup(priority_logic.EMAIL)
  job_fields = {
      'priority_group': priority_group,
      'task_name': 'sendStudentProposalMail'}

  job_query_fields = job_fields.copy()

  while students:
    # for each student create a mailing job
    for student in students:

      job_query_fields['key_data'] = student.key()
      mail_job = job_logic.getForFields(job_query_fields, unique=True)

      if not mail_job:
        # this student did not receive mail yet
        job_fields['key_data'] = [student.key()]
        job_logic.updateOrCreateFromFields(job_fields)

    # update our own job
    last_student_key = students[-1].key()

    if len(key_data) >= 2:
      key_data[1] = last_student_key
    else:
      key_data.append(last_student_key)

    updated_job_fields = {'key_data': key_data}
    job_logic.updateEntityProperties(job_entity, updated_job_fields)

    # rinse and repeat
    student_fields['__key__ >'] = last_student_key
    students = student_logic.getForFields(student_fields,
                                          limit=DEF_STUDENT_STEP_SIZE)

  # we are finished
  return
Esempio n. 9
0
def setupStudentProposalMailing(job_entity):
    """Job that setup jobs that will mail students if they have been accepted in
  a program with a GSoC-like workflow.

  Args:
    job_entity: a Job entity with key_data set to 
                [program, last_completed_student]
  """

    from soc.cron.job import FatalJobError

    # retrieve the data we need to continue our work
    key_data = job_entity.key_data
    program_key = key_data[0]
    program_keyname = program_key.name()

    program_entity = program_logic.getFromKeyName(program_keyname)

    if not program_entity:
        raise FatalJobError('The program with key %s could not be found' %
                            (program_keyname))

    student_fields = {'scope': program_entity}

    if len(key_data) >= 2:
        # start where we left off
        student_fields['__key__ >'] = key_data[1]

    students = student_logic.getForFields(student_fields,
                                          limit=DEF_STUDENT_STEP_SIZE)

    # set the default fields for the jobs we are going to create
    priority_group = priority_logic.getGroup(priority_logic.EMAIL)
    job_fields = {
        'priority_group': priority_group,
        'task_name': 'sendStudentProposalMail'
    }

    job_query_fields = job_fields.copy()

    while students:
        # for each student create a mailing job
        for student in students:

            job_query_fields['key_data'] = student.key()
            mail_job = job_logic.getForFields(job_query_fields, unique=True)

            if not mail_job:
                # this student did not receive mail yet
                job_fields['key_data'] = [student.key()]
                job_logic.updateOrCreateFromFields(job_fields)

        # update our own job
        last_student_key = students[-1].key()

        if len(key_data) >= 2:
            key_data[1] = last_student_key
        else:
            key_data.append(last_student_key)

        updated_job_fields = {'key_data': key_data}
        job_logic.updateEntityProperties(job_entity, updated_job_fields)

        # rinse and repeat
        student_fields['__key__ >'] = last_student_key
        students = student_logic.getForFields(student_fields,
                                              limit=DEF_STUDENT_STEP_SIZE)

    # we are finished
    return