Example #1
0
    def _manageSetMentor(self, request, template, context, params, entity,
                         form):
        """Handles the POST request for changing a Projects's mentor.

    Args:
        template: the template used for this view
        entity: the student project entity
        form: instance of the form used to set the mentor
        rest: see base.View.public()
    """

        if not form.is_valid():
            context['mentor_edit_form'] = form

            # add an a fresh additional mentors form
            context['additional_mentor_form'] = params[
                'additional_mentor_form']()

            return responses.respond(request, template, context)

        _, fields = forms_helper.collectCleanedFields(form)

        # get the mentor from the form
        fields = {
            'link_id': fields['mentor_id'],
            'scope': entity.scope,
            'status': 'active'
        }
        mentor = mentor_logic.getForFields(fields, unique=True)

        # update the project with the assigned mentor
        fields = {'mentor': mentor}

        additional_mentors = entity.additional_mentors

        # pylint: disable=E1103
        if additional_mentors and mentor.key() in additional_mentors:
            # remove the mentor that is now becoming the primary mentor
            additional_mentors.remove(mentor.key())
            fields['additional_mentors'] = additional_mentors

        # update the project with the new mentor and possible
        # new set of additional mentors
        project_logic.updateEntityProperties(entity, fields)

        # redirect to the same page
        redirect = request.path
        return http.HttpResponseRedirect(redirect)
Example #2
0
  def stEditPost(self, request, context, params, entity, **kwargs):
    """Handles the POST request for the student's edit page.

    Args:
        entity: the student project entity
        rest: see base.View.public()
    """

    form = params['student_edit_form'](request.POST)

    if not form.is_valid():
      return self._constructResponse(request, entity, context, form, params)

    _, fields = forms_helper.collectCleanedFields(form)

    project_logic.updateEntityProperties(entity, fields)

    return self.stEditGet(request, context, params, entity, **kwargs)
Example #3
0
  def stEditPost(self, request, context, params, entity, **kwargs):
    """Handles the POST request for the student's edit page.

    Args:
        entity: the student project entity
        rest: see base.View.public()
    """

    form = params['student_edit_form'](request.POST)

    if not form.is_valid():
      return self._constructResponse(request, entity, context, form, params)

    _, fields = forms_helper.collectCleanedFields(form)

    project_logic.updateEntityProperties(entity, fields)

    return self.stEditGet(request, context, params, entity, **kwargs)
Example #4
0
  def _manageSetMentor(self, request, template, context, params, entity, form):
    """Handles the POST request for changing a Projects's mentor.

    Args:
        template: the template used for this view
        entity: the student project entity
        form: instance of the form used to set the mentor
        rest: see base.View.public()
    """

    if not form.is_valid():
      context['mentor_edit_form'] = form

      # add an a fresh additional mentors form
      context['additional_mentor_form'] = params['additional_mentor_form']()

      return responses.respond(request, template, context)

    _, fields = forms_helper.collectCleanedFields(form)

    # get the mentor from the form
    fields = {'link_id': fields['mentor_id'],
              'scope': entity.scope,
              'status': 'active'}
    mentor = mentor_logic.getForFields(fields, unique=True)

    # update the project with the assigned mentor
    fields = {'mentor': mentor}

    additional_mentors = entity.additional_mentors

    # pylint: disable=E1103
    if additional_mentors and mentor.key() in additional_mentors:
      # remove the mentor that is now becoming the primary mentor
      additional_mentors.remove(mentor.key())
      fields['additional_mentors'] = additional_mentors

    # update the project with the new mentor and possible 
    # new set of additional mentors
    project_logic.updateEntityProperties(entity, fields)

    # redirect to the same page
    redirect = request.path
    return http.HttpResponseRedirect(redirect)
Example #5
0
  def overviewPost(self, request, params, program):
    """Handles the POST request for the Program Admins overview page.

    Args:
      request: Django HTTPRequest object
      params: Params for this view
      program: GSoCProgram entity
    """

    project_logic = params['logic']

    post_dict = request.POST

    data = simplejson.loads(post_dict.get('data', '[]'))
    button_id = post_dict.get('button_id', '')

    if button_id not in ['withdraw', 'accept']:
      logging.warning('Invalid button ID found %s' %(button_id))
      return http.HttpResponse()

    project_keys = []

    for selected in data:
      project_keys.append(selected['key'])

    # get all projects and prefetch the program field
    projects = project_logic.getFromKeyName(project_keys)
    project_logic.prefetchField('program', projects)

    # filter out all projects not belonging to the current program
    projects = [p for p in projects if p.program.key() == program.key()]

    for p in projects:
      fields = {}
      if button_id == 'withdraw':
        fields['status'] = 'withdrawn'
      elif button_id == 'accept':
        fields['status'] = 'accepted'

      # update the project with the new status
      project_logic.updateEntityProperties(p, fields)

    # return a 200 response
    return http.HttpResponse()
Example #6
0
    def _manageAddAdditionalMentor(self, request, template, context, params,
                                   entity, form):
        """Handles the POST request for changing a Projects's additional mentors.

    Args:
        template: the template used for this view
        entity: the student project entity
        form: instance of the form used to add an additional mentor
        rest: see base.View.public()
    """

        if not form.is_valid():
            context['additional_mentor_form'] = form

            # add a fresh edit mentor form
            initial = {'mentor_id': entity.mentor.link_id}
            context['mentor_edit_form'] = params['mentor_edit_form'](
                initial=initial)

            return responses.respond(request, template, context)

        _, fields = forms_helper.collectCleanedFields(form)

        # get the mentor from the form
        fields = {
            'link_id': fields['mentor_id'],
            'scope': entity.scope,
            'status': 'active'
        }
        mentor = mentor_logic.getForFields(fields, unique=True)

        # add this mentor to the additional mentors
        if not entity.additional_mentors:
            additional_mentors = [mentor.key()]
        else:
            additional_mentors = entity.additional_mentors
            additional_mentors.append(mentor.key())

        fields = {'additional_mentors': additional_mentors}
        project_logic.updateEntityProperties(entity, fields)

        # redirect to the same page
        redirect = request.path
        return http.HttpResponseRedirect(redirect)
Example #7
0
    def overviewPost(self, request, params, program):
        """Handles the POST request for the Program Admins overview page.

    Args:
      request: Django HTTPRequest object
      params: Params for this view
      program: GSoCProgram entity
    """

        project_logic = params['logic']

        post_dict = request.POST

        data = simplejson.loads(post_dict.get('data', '[]'))
        button_id = post_dict.get('button_id', '')

        if button_id not in ['withdraw', 'accept']:
            logging.warning('Invalid button ID found %s' % (button_id))
            return http.HttpResponse()

        project_keys = []

        for selected in data:
            project_keys.append(selected['key'])

        # get all projects and prefetch the program field
        projects = project_logic.getFromKeyName(project_keys)
        project_logic.prefetchField('program', projects)

        # filter out all projects not belonging to the current program
        projects = [p for p in projects if p.program.key() == program.key()]

        for p in projects:
            fields = {}
            if button_id == 'withdraw':
                fields['status'] = 'withdrawn'
            elif button_id == 'accept':
                fields['status'] = 'accepted'

            # update the project with the new status
            project_logic.updateEntityProperties(p, fields)

        # return a 200 response
        return http.HttpResponse()
Example #8
0
  def _manageAddAdditionalMentor(self, request, template, 
                                 context, params, entity, form):
    """Handles the POST request for changing a Projects's additional mentors.

    Args:
        template: the template used for this view
        entity: the student project entity
        form: instance of the form used to add an additional mentor
        rest: see base.View.public()
    """

    if not form.is_valid():
      context['additional_mentor_form'] = form

      # add a fresh edit mentor form
      initial = {'mentor_id': entity.mentor.link_id}
      context['mentor_edit_form'] = params['mentor_edit_form'](initial=initial)

      return responses.respond(request, template, context)

    _, fields = forms_helper.collectCleanedFields(form)

    # get the mentor from the form
    fields = {'link_id': fields['mentor_id'],
              'scope': entity.scope,
              'status': 'active'}
    mentor = mentor_logic.getForFields(fields, unique=True)

    # add this mentor to the additional mentors
    if not entity.additional_mentors:
      additional_mentors = [mentor.key()]
    else:
      additional_mentors = entity.additional_mentors
      additional_mentors.append(mentor.key())

    fields = {'additional_mentors': additional_mentors}
    project_logic.updateEntityProperties(entity, fields)

    # redirect to the same page
    redirect = request.path
    return http.HttpResponseRedirect(redirect)
Example #9
0
    def manageGet(self, request, template, context, params, entity, **kwargs):
        """Handles the GET request for the project's manage page.

    Args:
        template: the template used for this view
        entity: the student project entity
        rest: see base.View.public()
    """

        get_dict = request.GET

        if 'remove' in get_dict and entity.status == 'accepted':
            # get the mentor to remove
            fields = {'link_id': get_dict['remove'], 'scope': entity.scope}
            mentor = mentor_logic.getForFields(fields, unique=True)

            additional_mentors = entity.additional_mentors
            # pylint: disable=E1103
            if additional_mentors and mentor.key() in additional_mentors:
                # remove the mentor from the additional mentors list
                additional_mentors.remove(mentor.key())
                fields = {'additional_mentors': additional_mentors}
                project_logic.updateEntityProperties(entity, fields)

            # redirect to the same page without GET arguments
            redirect = request.path
            return http.HttpResponseRedirect(redirect)

        if project_logic.canChangeMentors(entity):
            # populate forms with the current mentors set
            initial = {'mentor_id': entity.mentor.link_id}
            context['mentor_edit_form'] = params['mentor_edit_form'](
                initial=initial)
            context['additional_mentor_form'] = params[
                'additional_mentor_form']()

        return responses.respond(request, template, context)
Example #10
0
  def manageGet(self, request, template, context, params, entity, **kwargs):
    """Handles the GET request for the project's manage page.

    Args:
        template: the template used for this view
        entity: the student project entity
        rest: see base.View.public()
    """

    get_dict = request.GET

    if 'remove' in get_dict and entity.status == 'accepted':
      # get the mentor to remove
      fields = {'link_id': get_dict['remove'],
                'scope': entity.scope}
      mentor = mentor_logic.getForFields(fields, unique=True)

      additional_mentors = entity.additional_mentors
      # pylint: disable=E1103
      if additional_mentors and mentor.key() in additional_mentors:
        # remove the mentor from the additional mentors list
        additional_mentors.remove(mentor.key())
        fields = {'additional_mentors': additional_mentors}
        project_logic.updateEntityProperties(entity, fields)

      # redirect to the same page without GET arguments
      redirect = request.path
      return http.HttpResponseRedirect(redirect)

    if project_logic.canChangeMentors(entity):
      # populate forms with the current mentors set
      initial = {'mentor_id': entity.mentor.link_id}
      context['mentor_edit_form'] = params['mentor_edit_form'](initial=initial)
      context['additional_mentor_form'] = params['additional_mentor_form']()

    return responses.respond(request, template, context)