Пример #1
0
  def checkIsStudent(self, django_args, key_location, status):
    """Checks if the current user is the given student.

    Args:
      django_args: a dictionary with django's arguments
      key_location: the key for django_args in which the key_name
                    from the student is stored
      status: the allowed status for the student
    """

    self.checkIsUser(django_args)

    if 'seed' in django_args:
      key_name = django_args['seed'][key_location]
    else:
      key_name = django_args[key_location]

    student_entity = student_logic.getFromKeyName(key_name)

    if not student_entity or student_entity.status not in status:
      raise out_of_band.AccessViolation(
        message_fmt=DEF_SIGN_UP_AS_STUDENT_MSG)

    if student_entity.user.key() != self.user.key():
      # this is not the page for the current user
      self.deny(django_args)

    return
Пример #2
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')
Пример #3
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')
Пример #4
0
  def checkCanStudentPropose(self, django_args, key_location, check_limit):
    """Checks if the program for this student accepts proposals.

    Args:
      django_args: a dictionary with django's arguments
      key_location: the key for django_args in which the key_name
                    from the student is stored
      check_limit: iff true checks if the student reached the apps_tasks_limit
                   for the given program.
    """

    self.checkIsUser(django_args)

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

    student_entity = student_logic.getFromKeyName(key_name)

    if not student_entity or student_entity.status == 'invalid':
      raise out_of_band.AccessViolation(
        message_fmt=DEF_SIGN_UP_AS_STUDENT_MSG)

    program_entity = student_entity.scope

    if not timeline_helper.isActivePeriod(program_entity.timeline,
                                          'student_signup'):
      raise out_of_band.AccessViolation(message_fmt=DEF_PAGE_INACTIVE_MSG)

    if check_limit:
      # count all studentproposals by the student
      fields = {'scope': student_entity}
      proposal_query = student_proposal_logic.getQueryForFields(fields)

      if proposal_query.count() >= program_entity.apps_tasks_limit:
        # too many proposals access denied
        raise out_of_band.AccessViolation(message_fmt=DEF_MAX_PROPOSALS_REACHED)

    return
Пример #5
0
def runStudentProposalUpdate(request, entities, context, *args, **kwargs):
  """AppEngine Task that updates StudentProposal entities.

  Args:
    request: Django Request object
    entities: list of StudentProposal entities to update
    context: the context of this task
  """

  from soc.modules.gsoc.logic.models.mentor import logic as mentor_logic
  from soc.modules.gsoc.logic.models.organization import logic as org_logic
  from soc.modules.gsoc.logic.models.program import logic as program_logic
  from soc.modules.gsoc.logic.models.student import logic as student_logic

  for entity in entities:
    entity.scope = student_logic.getFromKeyName(
        entity.scope.key().id_or_name())
    entity.org = org_logic.getFromKeyName(entity.org.key().id_or_name())
    entity.program = program_logic.getFromKeyName(
        entity.program.key().id_or_name())

    if entity.mentor:
      entity.mentor = mentor_logic.getFromKeyName(
          entity.mentor.key().id_or_name())

    old_mentors = entity.possible_mentors
    new_mentors = []

    for old_mentor in old_mentors:
      new_mentor = mentor_logic.getFromKeyName(old_mentor.id_or_name())
      new_mentors.append(new_mentor.key())

    entity.possible_mentors = new_mentors

  # store all StudentProposal
  db.put(entities)

  # task completed, return
  return
Пример #6
0
def runStudentProposalUpdate(request, entities, context, *args, **kwargs):
  """AppEngine Task that updates StudentProposal entities.

  Args:
    request: Django Request object
    entities: list of StudentProposal entities to update
    context: the context of this task
  """

  from soc.modules.gsoc.logic.models.mentor import logic as mentor_logic
  from soc.modules.gsoc.logic.models.organization import logic as org_logic
  from soc.modules.gsoc.logic.models.program import logic as program_logic
  from soc.modules.gsoc.logic.models.student import logic as student_logic

  for entity in entities:
    entity.scope = student_logic.getFromKeyName(
        entity.scope.key().id_or_name())
    entity.org = org_logic.getFromKeyName(entity.org.key().id_or_name())
    entity.program = program_logic.getFromKeyName(
        entity.program.key().id_or_name())

    if entity.mentor:
      entity.mentor = mentor_logic.getFromKeyName(
          entity.mentor.key().id_or_name())

    old_mentors = entity.possible_mentors
    new_mentors = []

    for old_mentor in old_mentors:
      new_mentor = mentor_logic.getFromKeyName(old_mentor.id_or_name())
      new_mentors.append(new_mentor.key())

    entity.possible_mentors = new_mentors

  # store all StudentProposal
  db.put(entities)

  # task completed, return
  return
Пример #7
0
def sendStudentProposalMail(job_entity):
  """Job that will send out an email to a student that sent in a proposal
  that either got accepted or rejected.

  Args:
    job_entity: a Job entity with key_data set to [student_key]
  """

  from soc.cron.job import FatalJobError


  student_keyname = job_entity.key_data[0].name()
  student_entity = student_logic.getFromKeyName(student_keyname)

  if not student_entity:
    raise FatalJobError('The student with keyname %s does not exist!' % (
        student_keyname))

  # only students who have sent in a proposal will be mailed
  fields = {'scope': student_entity}
  proposal = proposal_logic.getForFields(fields, unique=True)

  if proposal:
    # a proposal has been found we must sent out an email
    default_sender = mail_dispatcher.getDefaultMailSender()

    if not default_sender:
      # no default sender abort
      raise FatalJobError('No valid sender address could be found, try '
                          'setting a no-reply address on the site settings '
                          'page')
    else:
      (sender_name, sender) = default_sender

    # construct the contents of the email
    student_entity = proposal.scope
    program_entity = proposal.program

    context = {
        'to': student_entity.email,
        'to_name': student_entity.given_name,
        'sender': sender,
        'sender_name': sender_name,
        'program_name': program_entity.name,
    }

    # check if the student has an accepted proposal
    fields['status'] = 'accepted'
    accepted_proposal = proposal_logic.getForFields(fields, unique=True)

    if accepted_proposal:
      org_entity = accepted_proposal.org
      # use the accepted template and subject
      template = DEF_ACCEPTED_MAIL_TEMPLATE
      context['subject'] = 'Congratulations!'
      context['proposal_title'] = accepted_proposal.title
      context['org_name'] = accepted_proposal.org.name
    else:
      # use the rejected template and subject
      template = DEF_REJECTED_MAIL_TEMPLATE
      context['subject'] = 'Thank you for applying to %s' % (
          program_entity.name)

    # send out the constructed email
    mail_dispatcher.sendMailFromTemplate(template, context)

  # we are done here
  return
Пример #8
0
def sendStudentProposalMail(job_entity):
    """Job that will send out an email to a student that sent in a proposal
  that either got accepted or rejected.

  Args:
    job_entity: a Job entity with key_data set to [student_key]
  """

    from soc.cron.job import FatalJobError

    student_keyname = job_entity.key_data[0].name()
    student_entity = student_logic.getFromKeyName(student_keyname)

    if not student_entity:
        raise FatalJobError('The student with keyname %s does not exist!' %
                            (student_keyname))

    # only students who have sent in a proposal will be mailed
    fields = {'scope': student_entity}
    proposal = proposal_logic.getForFields(fields, unique=True)

    if proposal:
        # a proposal has been found we must sent out an email
        default_sender = mail_dispatcher.getDefaultMailSender()

        if not default_sender:
            # no default sender abort
            raise FatalJobError(
                'No valid sender address could be found, try '
                'setting a no-reply address on the site settings '
                'page')
        else:
            (sender_name, sender) = default_sender

        # construct the contents of the email
        # pylint: disable-msg=E1103
        student_entity = proposal.scope
        program_entity = proposal.program

        context = {
            'to': student_entity.email,
            'to_name': student_entity.given_name,
            'sender': sender,
            'sender_name': sender_name,
            'program_name': program_entity.name,
        }

        # check if the student has an accepted proposal
        fields['status'] = 'accepted'
        accepted_proposal = proposal_logic.getForFields(fields, unique=True)

        if accepted_proposal:
            # use the accepted template and subject
            template = DEF_ACCEPTED_MAIL_TEMPLATE
            context['subject'] = 'Congratulations!'
            context['proposal_title'] = accepted_proposal.title
            context['org_name'] = accepted_proposal.org.name
        else:
            # use the rejected template and subject
            template = DEF_REJECTED_MAIL_TEMPLATE
            context['subject'] = 'Thank you for applying to %s' % (
                program_entity.name)

        # send out the constructed email
        mail_dispatcher.sendMailFromTemplate(template, context)

    # we are done here
    return