Beispiel #1
0
  def _getStudentEntries(self, program_entity, student_entity,
                         params, id, user, prefix):
    """Returns a list with menu items for students in a specific program.
    """

    items = []

    if timeline_helper.isBeforeEvent(program_entity.timeline, 'program_end') \
        and student_entity.status == 'active':
      items += [(redirects.getEditRedirect(student_entity,
          {'url_name': prefix + '/student'}),
          "Edit my Student Profile", 'any_access')]

    return items
Beispiel #2
0
    def _getStudentEntries(self, program_entity, student_entity, params, id,
                           user, prefix):
        """Returns a list with menu items for students in a specific program.
    """

        items = []

        if timeline_helper.isBeforeEvent(program_entity.timeline, 'program_end') \
            and student_entity.status == 'active':
            items += [
                (redirects.getEditRedirect(student_entity,
                                           {'url_name': prefix + '/student'}),
                 "Edit my Student Profile", 'any_access')
            ]

        return items
Beispiel #3
0
    def _getStudentEntries(self, program_entity, student_entity, params, id,
                           user, prefix):
        """Returns a list with menu items for students in a specific program.
    """

        items = []

        timeline_entity = program_entity.timeline

        if timeline_helper.isActivePeriod(timeline_entity, 'student_signup') and \
            student_entity.status == 'active':
            items += [('/gsoc/student_proposal/list_orgs/%s' %
                       (student_entity.key().id_or_name()),
                       "Submit your Student Proposal", 'any_access')]

        if timeline_helper.isAfterEvent(timeline_entity,
                                        'student_signup_start'):
            items += [(redirects.getListSelfRedirect(
                student_entity, {'url_name': prefix + '/student_proposal'}),
                       "List my Student Proposals", 'any_access')]

        if timeline_helper.isAfterEvent(
                timeline_entity, 'accepted_students_announced_deadline'):
            # add a link to show all projects
            items += [(redirects.getListProjectsRedirect(
                program_entity, {'url_name': prefix + '/student'}),
                       "List my Student Projects", 'any_access')]

        if timeline_helper.isBeforeEvent(program_entity.timeline, 'program_end') \
            and student_entity.status == 'active':
            items += [(redirects.getManageRedirect(
                student_entity, {'url_name': prefix + '/student'}),
                       "Resign as a Student", 'any_access')]

        items += super(View,
                       self)._getStudentEntries(program_entity, student_entity,
                                                params, id, user, prefix)

        return items
Beispiel #4
0
  def _getStudentEntries(self, program_entity, student_entity,
                         params, id, user, prefix):
    """Returns a list with menu items for students in a specific program.
    """

    items = []

    timeline_entity = program_entity.timeline

    if timeline_helper.isActivePeriod(timeline_entity, 'student_signup') and \
        student_entity.status == 'active':
      items += [('/gsoc/student_proposal/list_orgs/%s' % (
          student_entity.key().id_or_name()),
          "Submit your Student Proposal", 'any_access')]

    if timeline_helper.isAfterEvent(timeline_entity, 'student_signup_start'):
      items += [(redirects.getListSelfRedirect(student_entity,
          {'url_name': prefix + '/student_proposal'}),
          "List my Student Proposals", 'any_access')]

    if timeline_helper.isAfterEvent(timeline_entity,
                                   'accepted_students_announced_deadline'):
      # add a link to show all projects
      items += [(redirects.getListProjectsRedirect(program_entity,
          {'url_name': prefix + '/student'}),
          "List my Student Projects", 'any_access')]

    if timeline_helper.isBeforeEvent(program_entity.timeline, 'program_end') \
        and student_entity.status == 'active':
      items += [(redirects.getManageRedirect(student_entity,
          {'url_name': prefix + '/student'}),
          "Resign as a Student", 'any_access')]

    items += super(View, self)._getStudentEntries(program_entity,
        student_entity, params, id, user, prefix)

    return items
    def testIsBeforeEvent(self):
        """Tests if a correct bool is returned if current DateTime 
    is before a given event.
    """
        #program has not started.
        self.timeline.program_start = datetime.utcnow() + timedelta(20)
        self.assertTrue(timeline.isBeforeEvent(self.timeline, 'program_start'))

        #program has already started.
        self.timeline.program_start = datetime.utcnow() - timedelta(20)
        self.assertFalse(timeline.isBeforeEvent(self.timeline,
                                                'program_start'))

        #program has not ended.
        self.timeline.program_end = datetime.utcnow() + timedelta(20)
        self.assertTrue(timeline.isBeforeEvent(self.timeline, 'program_end'))

        #program has ended.
        self.timeline.program_end = datetime.utcnow() - timedelta(20)
        self.assertFalse(timeline.isBeforeEvent(self.timeline, 'program_end'))

        #the deadline to announce accepted organizations has not passed.
        self.timeline.accepted_organization_announced_deadline = (
            datetime.utcnow() + timedelta(20))
        self.assertTrue(
            timeline.isBeforeEvent(self.timeline,
                                   "accepted_organization_announced_deadline"))

        #the deadline to announce accepted organizations has been passed.
        self.timeline.accepted_organization_announced_deadline = (
            datetime.utcnow() - timedelta(20))
        self.assertFalse(
            timeline.isBeforeEvent(self.timeline,
                                   "accepted_organization_announced_deadline"))

        #student sign up period has not started.
        self.timeline.student_signup_start = datetime.utcnow() + timedelta(20)
        self.assertTrue(
            timeline.isBeforeEvent(self.timeline, 'student_signup_start'))

        #student sign up period has already started.
        self.timeline.student_signup_start = datetime.utcnow() - timedelta(20)
        self.assertFalse(
            timeline.isBeforeEvent(self.timeline, 'student_signup_start'))

        #student sign up period has not ended.
        self.timeline.student_signup_end = datetime.utcnow() + timedelta(20)
        self.assertTrue(
            timeline.isBeforeEvent(self.timeline, 'student_signup_end'))

        #student sign up period has already ended.
        self.timeline.student_signup_end = datetime.utcnow() - timedelta(20)
        self.assertFalse(
            timeline.isBeforeEvent(self.timeline, 'student_signup_end'))
        #event not in the timeline.
        self.assertFalse(timeline.isBeforeEvent(self.timeline, 'other_event'))
def start(request, *args, **kwargs):
    """Starts the task to find all duplicate proposals which are about to be
  accepted for a single GSoCProgram.

  Expects the following to be present in the POST dict:
    program_key: Specifies the program key name for which to find the
                 duplicate proposals
    repeat: Specifies if a new task that must be performed again an hour
            later, with the same POST data

  Args:
    request: Django Request object
  """

    from soc.logic.helper import timeline as timeline_helper

    post_dict = request.POST

    # retrieve the program_key and survey_key from POST data
    program_key = post_dict.get('program_key')
    repeat = post_dict.get('repeat')

    if not (program_key and repeat):
        # invalid task data, log and return OK
        return error_handler.logErrorAndReturnOK('Invalid task data: %s' %
                                                 post_dict)

    # get the program for the given keyname
    program_entity = program_logic.getFromKeyName(program_key)

    if not program_entity:
        # invalid program specified, log and return OK
        return error_handler.logErrorAndReturnOK(
            'Invalid program specified: %s' % program_key)

    # obtain the proposal duplicate status
    pds_entity = pds_logic.getOrCreateForProgram(program_entity)

    if pds_entity.status == 'idle':
        # delete all old duplicates
        prop_duplicates = pd_logic.deleteAllForProgram(program_entity)

        # pass these data along params as POST to the new task
        task_params = {'program_key': program_key}
        task_url = '/tasks/gsoc/proposal_duplicates/calculate'

        new_task = taskqueue.Task(params=task_params, url=task_url)
        # add a new task that performs duplicate calculation per
        # organization
        new_task.add()

        # update the status of the PDS entity to processing
        fields = {'status': 'processing'}
        pds_logic.updateEntityProperties(pds_entity, fields)

    # Add a new clone of this task that must be performed an hour later because
    # the current task is part of the task that repeatedly runs but repeat
    # it before accepted students are announced only.
    if repeat == 'yes' and timeline_helper.isBeforeEvent(
            program_entity.timeline, 'accepted_students_announced_deadline'):
        # pass along these params as POST to the new task
        task_params = {'program_key': program_key, 'repeat': 'yes'}
        task_url = '/tasks/gsoc/proposal_duplicates/start'

        new_task = taskqueue.Task(params=task_params,
                                  url=task_url,
                                  countdown=3600)
        new_task.add()

    # return OK
    return http.HttpResponse()
Beispiel #7
0
  def start(self, request, *args, **kwargs):
    """Starts the task to find all duplicate proposals which are about to be
    accepted for a single GSoCProgram.

    Expects the following to be present in the POST dict:
      program_key: Specifies the program key name for which to find the
                   duplicate proposals
      repeat: Specifies if a new task that must be performed again an hour
              later, with the same POST data

    Args:
      request: Django Request object
    """

    from soc.logic.helper import timeline as timeline_helper

    post_dict = request.POST

    # retrieve the program_key and repeat option from POST data
    program_key = post_dict.get('program_key')
    repeat = post_dict.get('repeat')

    if not (program_key and repeat):
      # invalid task data, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid task data: %s' % post_dict)

    # get the program for the given keyname
    program_entity = GSoCProgram.get_by_key_name(program_key)

    if not program_entity:
      # invalid program specified, log and return OK
      return error_handler.logErrorAndReturnOK(
          'Invalid program specified: %s' % program_key)

    # obtain the proposal duplicate status
    pds_entity = duplicates_logic.getOrCreateStatusForProgram(program_entity)

    if pds_entity.status == 'idle':
      # delete all old duplicates
      duplicates_logic.deleteAllForProgram(program_entity)

      # pass these data along params as POST to the new task
      task_params = {'program_key': program_key}
      task_url = '/tasks/gsoc/proposal_duplicates/calculate'

      new_task = taskqueue.Task(params=task_params, url=task_url)

      def txn():
        # add a new task that performs duplicate calculation per
        # organization
        new_task.add(transactional=True)

        # update the status of the PDS entity to processing
        pds_entity.status = 'processing'
        pds_entity.put()

      db.RunInTransaction(txn)

    # Add a new clone of this task that must be performed an hour later because
    # the current task is part of the task that repeatedly runs but repeat
    # it before accepted students are announced only.
    if repeat == 'yes' and timeline_helper.isBeforeEvent(
        program_entity.timeline, 'accepted_students_announced_deadline'):
      # pass along these params as POST to the new task
      task_params = {'program_key': program_key,
                     'repeat': 'yes'}
      task_url = '/tasks/gsoc/proposal_duplicates/start'

      new_task = taskqueue.Task(params=task_params, url=task_url,
                                countdown=3600)
      new_task.add()

    # return OK
    return http.HttpResponse()
Beispiel #8
0
    def testIsBeforeEvent(self):
        """Tests if a correct bool is returned if current DateTime
    is before a given event.
    """
        # program has not started.
        self.timeline.program_start = datetime.utcnow() + timedelta(20)
        self.assertTrue(timeline.isBeforeEvent(self.timeline, "program_start"))

        # program has already started.
        self.timeline.program_start = datetime.utcnow() - timedelta(20)
        self.assertFalse(timeline.isBeforeEvent(self.timeline, "program_start"))

        # program has not ended.
        self.timeline.program_end = datetime.utcnow() + timedelta(20)
        self.assertTrue(timeline.isBeforeEvent(self.timeline, "program_end"))

        # program has ended.
        self.timeline.program_end = datetime.utcnow() - timedelta(20)
        self.assertFalse(timeline.isBeforeEvent(self.timeline, "program_end"))

        # the deadline to announce accepted organizations has not passed.
        self.timeline.accepted_organization_announced_deadline = datetime.utcnow() + timedelta(20)
        self.assertTrue(timeline.isBeforeEvent(self.timeline, "accepted_organization_announced_deadline"))

        # the deadline to announce accepted organizations has been passed.
        self.timeline.accepted_organization_announced_deadline = datetime.utcnow() - timedelta(20)
        self.assertFalse(timeline.isBeforeEvent(self.timeline, "accepted_organization_announced_deadline"))

        # student sign up period has not started.
        self.timeline.student_signup_start = datetime.utcnow() + timedelta(20)
        self.assertTrue(timeline.isBeforeEvent(self.timeline, "student_signup_start"))

        # student sign up period has already started.
        self.timeline.student_signup_start = datetime.utcnow() - timedelta(20)
        self.assertFalse(timeline.isBeforeEvent(self.timeline, "student_signup_start"))

        # student sign up period has not ended.
        self.timeline.student_signup_end = datetime.utcnow() + timedelta(20)
        self.assertTrue(timeline.isBeforeEvent(self.timeline, "student_signup_end"))

        # student sign up period has already ended.
        self.timeline.student_signup_end = datetime.utcnow() - timedelta(20)
        self.assertFalse(timeline.isBeforeEvent(self.timeline, "student_signup_end"))
        # event not in the timeline.
        self.assertFalse(timeline.isBeforeEvent(self.timeline, "other_event"))
Beispiel #9
0
    def _getTimeDependentEntries(self, gci_program_entity, params, id, user):
        """Returns a list with time dependent menu items.
    """

        items = []

        timeline_entity = gci_program_entity.timeline

        # add show ranking item
        if timeline_helper.isAfterEvent(timeline_entity,
                                        'tasks_publicly_visible'):
            items += [(gci_redirects.getShowRankingRedirect(
                gci_program_entity,
                {'url_name': 'gci/program'}), 'Show Ranking', 'any_access')]

        mentor_entity = None
        org_admin_entity = None

        org_app_survey = org_app_logic.getForProgram(gci_program_entity)

        if org_app_survey and \
            timeline_helper.isActivePeriod(org_app_survey, 'survey'):
            # add the organization signup link
            items += [
                (redirects.getTakeSurveyRedirect(org_app_survey,
                                                 {'url_name': 'gci/org_app'}),
                 "Apply to become an Organization", 'any_access')
            ]

        if user and org_app_survey and timeline_helper.isAfterEvent(
                org_app_survey, 'survey_start'):

            main_admin_fields = {
                'main_admin': user,
                'survey': org_app_survey,
            }

            backup_admin_fields = {
                'backup_admin': user,
                'survey': org_app_survey
            }

            org_app_record_logic = org_app_logic.getRecordLogic()

            if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \
                org_app_record_logic.getForFields(backup_admin_fields, unique=True):
                # add the 'List my Organization Applications' link
                items += [(redirects.getListSelfRedirect(
                    org_app_survey, {'url_name': 'gci/org_app'}),
                           "List My Organization Applications", 'any_access')]

        # get the student entity for this user and program
        filter = {
            'user': user,
            'scope': gci_program_entity,
            'status': ['active', 'inactive']
        }
        student_entity = gci_student_logic.logic.getForFields(filter,
                                                              unique=True)

        # students can register after successfully completing their first
        # task. So if a user has completed one task he is still a student
        filter = {
            'user': user,
            'program': gci_program_entity,
        }
        has_completed_task = gci_task_logic.logic.getForFields(filter,
                                                               unique=True)

        if student_entity or (user and has_completed_task):
            items += self._getStudentEntries(gci_program_entity,
                                             student_entity, params, id, user,
                                             'gci')
        else:
            # get mentor and org_admin entity for this user and program
            filter = {
                'user': user,
                'program': gci_program_entity,
                'status': 'active'
            }
            mentor_entity = gci_mentor_logic.logic.getForFields(filter,
                                                                unique=True)
            org_admin_entity = gci_org_admin_logic.logic.getForFields(
                filter, unique=True)

            if timeline_helper.isAfterEvent(
                    timeline_entity,
                    'accepted_organization_announced_deadline'):
                if mentor_entity or org_admin_entity:
                    items += self._getOrganizationEntries(
                        gci_program_entity, org_admin_entity, mentor_entity,
                        params, id, user)
                if timeline_helper.isBeforeEvent(timeline_entity,
                                                 'program_end'):
                    # add apply to become a mentor link
                    items += [('/gci/org/apply_mentor/%s' %
                               (gci_program_entity.key().id_or_name()),
                               "Apply to become a Mentor", 'any_access')]

        if timeline_helper.isAfterEvent(
                timeline_entity, 'accepted_organization_announced_deadline'):
            url = redirects.getAcceptedOrgsRedirect(gci_program_entity, params)
            # add a link to list all the organizations
            items += [(url, "List participating Organizations", 'any_access')]

        user_fields = {'user': user, 'status': 'active'}
        host_entity = host_logic.getForFields(user_fields, unique=True)

        # for org admins this link should be visible only after accepted
        # organizations are announced and for other public after the tasks
        # are public but for program host it must be visible always
        if (host_entity or ((org_admin_entity or mentor_entity)
                            and timeline_helper.isAfterEvent(
                                timeline_entity, 'tasks_publicly_visible'))
                or (timeline_helper.isAfterEvent(timeline_entity,
                                                 'tasks_publicly_visible'))):
            url = gci_redirects.getListAllTasksRedirect(
                gci_program_entity, params)
            # add a link to list all the organizations
            items += [(url, "List all tasks", 'any_access')]

            if user:
                # add a link to show all tasks of interest
                items += [(gci_redirects.getListMyTasksRedirect(
                    gci_program_entity,
                    params), 'List my Tasks', 'any_access')]

        return items
Beispiel #10
0
  def _getTimeDependentEntries(self, gci_program_entity, params, id, user):
    """Returns a list with time dependent menu items.
    """

    items = []

    timeline_entity = gci_program_entity.timeline

    # add show ranking item
    if timeline_helper.isAfterEvent(timeline_entity, 'tasks_publicly_visible'):
      items += [(gci_redirects.getShowRankingRedirect(
           gci_program_entity, {'url_name': 'gci/program'}),
           'Show Ranking', 'any_access')]

    mentor_entity = None
    org_admin_entity = None

    org_app_survey = org_app_logic.getForProgram(gci_program_entity)

    if org_app_survey and \
        timeline_helper.isActivePeriod(org_app_survey, 'survey'):
      # add the organization signup link
      items += [
          (redirects.getTakeSurveyRedirect(
               org_app_survey, {'url_name': 'gci/org_app'}),
          "Apply to become an Organization", 'any_access')]

    if user and org_app_survey and timeline_helper.isAfterEvent(
        org_app_survey, 'survey_start'):

      main_admin_fields = {
          'main_admin': user,
          'survey': org_app_survey,
          }

      backup_admin_fields = {
          'backup_admin': user,
          'survey': org_app_survey
          }

      org_app_record_logic = org_app_logic.getRecordLogic()

      if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \
          org_app_record_logic.getForFields(backup_admin_fields, unique=True):
        # add the 'List my Organization Applications' link
        items += [
            (redirects.getListSelfRedirect(org_app_survey,
                                           {'url_name' : 'gci/org_app'}),
             "List My Organization Applications", 'any_access')]

    # get the student entity for this user and program
    filter = {'user': user,
              'scope': gci_program_entity,
              'status': ['active', 'inactive']}
    student_entity = gci_student_logic.logic.getForFields(filter, unique=True)

    # students can register after successfully completing their first
    # task. So if a user has completed one task he is still a student
    filter = {
        'user': user,
        'program': gci_program_entity,
        }
    has_completed_task = gci_task_logic.logic.getForFields(
        filter, unique=True)

    if student_entity or (user and has_completed_task):
      items += self._getStudentEntries(gci_program_entity, student_entity,
                                       params, id, user, 'gci')
    else:
      # get mentor and org_admin entity for this user and program
      filter = {
          'user': user,
          'program': gci_program_entity,
          'status': 'active'
          }
      mentor_entity = gci_mentor_logic.logic.getForFields(filter, unique=True)
      org_admin_entity = gci_org_admin_logic.logic.getForFields(
          filter, unique=True)

      if timeline_helper.isAfterEvent(
          timeline_entity, 'accepted_organization_announced_deadline'):
        if mentor_entity or org_admin_entity:
          items += self._getOrganizationEntries(
              gci_program_entity, org_admin_entity,
              mentor_entity, params, id, user)
        if timeline_helper.isBeforeEvent(timeline_entity, 'program_end'):
          # add apply to become a mentor link
          items += [
              ('/gci/org/apply_mentor/%s' % (
                  gci_program_entity.key().id_or_name()),
                  "Apply to become a Mentor", 'any_access')]

    if timeline_helper.isAfterEvent(
        timeline_entity, 'accepted_organization_announced_deadline'):
      url = redirects.getAcceptedOrgsRedirect(
          gci_program_entity, params)
      # add a link to list all the organizations
      items += [(url, "List participating Organizations", 'any_access')]

    user_fields = {
        'user': user,
        'status': 'active'
        }
    host_entity = host_logic.getForFields(user_fields, unique=True)

    # for org admins this link should be visible only after accepted
    # organizations are announced and for other public after the tasks
    # are public but for program host it must be visible always
    if (host_entity or
        ((org_admin_entity or mentor_entity) and timeline_helper.isAfterEvent(
        timeline_entity, 'tasks_publicly_visible')) or
        (timeline_helper.isAfterEvent(
        timeline_entity, 'tasks_publicly_visible'))):
      url = gci_redirects.getListAllTasksRedirect(
          gci_program_entity, params)
      # add a link to list all the organizations
      items += [(url, "List all tasks", 'any_access')]

      if user:
        # add a link to show all tasks of interest
        items += [(gci_redirects.getListMyTasksRedirect(
            gci_program_entity, params),
            'List my Tasks', 'any_access')]

    return items
Beispiel #11
0
    def _getTimeDependentEntries(self, program_entity, params, id, user):
        """Returns a list with time dependent menu items.
    """

        from soc.modules.gsoc.logic.models.org_app_survey import logic as \
            org_app_logic

        items = []

        timeline_entity = program_entity.timeline

        org_app_survey = org_app_logic.getForProgram(program_entity)

        if org_app_survey and \
            timeline_helper.isActivePeriod(timeline_entity, 'org_signup'):
            # add the organization signup link
            items += [
                (redirects.getTakeSurveyRedirect(org_app_survey,
                                                 {'url_name': 'gsoc/org_app'}),
                 "Apply to become an Organization", 'any_access')
            ]

        if user and org_app_survey and timeline_helper.isAfterEvent(
                timeline_entity, 'org_signup_start'):

            main_admin_fields = {
                'main_admin': user,
                'survey': org_app_survey,
            }

            backup_admin_fields = {
                'backup_admin': user,
                'survey': org_app_survey
            }

            org_app_record_logic = org_app_logic.getRecordLogic()

            if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \
                org_app_record_logic.getForFields(backup_admin_fields, unique=True):
                # add the 'List my Organization Applications' link
                items += [(redirects.getListSelfRedirect(
                    org_app_survey, {'url_name': 'gsoc/org_app'}),
                           "List My Organization Applications", 'any_access')]

        # get the student entity for this user and program
        filter = {
            'user': user,
            'scope': program_entity,
            'status': ['active', 'inactive']
        }
        student_entity = student_logic.getForFields(filter, unique=True)

        if student_entity:
            items += self._getStudentEntries(program_entity, student_entity,
                                             params, id, user, 'gsoc')

        # get mentor and org_admin entity for this user and program
        filter = {
            'user': user,
            'program': program_entity,
            'status': ['active', 'inactive']
        }
        mentor_entity = mentor_logic.getForFields(filter, unique=True)
        org_admin_entity = org_admin_logic.getForFields(filter, unique=True)

        if mentor_entity or org_admin_entity:
            items += self._getOrganizationEntries(program_entity,
                                                  org_admin_entity,
                                                  mentor_entity, params, id,
                                                  user)

        if user and not (student_entity or mentor_entity or org_admin_entity):
            if timeline_helper.isActivePeriod(timeline_entity,
                                              'student_signup'):
                # this user does not have a role yet for this program
                items += [('/gsoc/student/apply/%s' %
                           (program_entity.key().id_or_name()),
                           "Register as a Student", 'any_access')]

        deadline = 'accepted_organization_announced_deadline'

        if timeline_helper.isAfterEvent(timeline_entity, deadline):
            url = redirects.getAcceptedOrgsRedirect(program_entity, params)
            # add a link to list all the organizations
            items += [(url, "List participating Organizations", 'any_access')]

            if not student_entity and \
                timeline_helper.isBeforeEvent(timeline_entity, 'program_end'):
                # add apply to become a mentor link
                items += [('/gsoc/org/apply_mentor/%s' %
                           (program_entity.key().id_or_name()),
                           "Apply to become a Mentor", 'any_access')]

        deadline = 'accepted_students_announced_deadline'

        if timeline_helper.isAfterEvent(timeline_entity, deadline):
            items += [(redirects.getListProjectsRedirect(
                program_entity, {'url_name': 'gsoc/program'}),
                       "List all Student Projects", 'any_access')]

        return items
Beispiel #12
0
  def _getTimeDependentEntries(self, program_entity, params, id, user):
    """Returns a list with time dependent menu items.
    """

    items = []

    timeline_entity = program_entity.timeline

    org_app_survey = org_app_logic.getForProgram(program_entity)

    if org_app_survey and \
        timeline_helper.isActivePeriod(org_app_survey, 'survey'):
      # add the organization signup link
      items += [
          (redirects.getTakeSurveyRedirect(
               org_app_survey, {'url_name': 'gsoc/org_app'}),
          "Apply to become an Organization", 'any_access')]

    if user and org_app_survey and timeline_helper.isAfterEvent(
        org_app_survey, 'survey_start'):

      main_admin_fields = {
          'main_admin': user,
          'survey': org_app_survey,
          }

      backup_admin_fields = {
          'backup_admin': user,
          'survey': org_app_survey
          }

      org_app_record_logic = org_app_logic.getRecordLogic()

      if org_app_record_logic.getForFields(main_admin_fields, unique=True) or \
          org_app_record_logic.getForFields(backup_admin_fields, unique=True):
        # add the 'List my Organization Applications' link
        items += [
            (redirects.getListSelfRedirect(org_app_survey,
                                           {'url_name' : 'gsoc/org_app'}),
             "List My Organization Applications", 'any_access')]

    # get the student entity for this user and program
    filter = {
        'user': user,
        'scope': program_entity,
        'status': ['active', 'inactive']
        }
    student_entity = student_logic.getForFields(filter, unique=True)

    if student_entity:
      items += self._getStudentEntries(program_entity, student_entity,
                                       params, id, user, 'gsoc')

    # get mentor and org_admin entity for this user and program
    filter = {
        'user': user,
        'program': program_entity,
        'status': ['active', 'inactive']
        }
    mentor_entity = mentor_logic.getForFields(filter, unique=True)
    org_admin_entity = org_admin_logic.getForFields(filter, unique=True)

    if mentor_entity or org_admin_entity:
      items += self._getOrganizationEntries(program_entity, org_admin_entity,
                                            mentor_entity, params, id, user)

    if not (student_entity or mentor_entity or org_admin_entity):
      if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'):
        # this user does not have a role yet for this program
        items += [
            ('/gsoc/student/apply/%s' % (program_entity.key().id_or_name()),
            "Register as a Student", 'any_access')]

    deadline = 'accepted_organization_announced_deadline'

    if timeline_helper.isAfterEvent(timeline_entity, deadline):
      url = redirects.getAcceptedOrgsRedirect(program_entity, params)
      # add a link to list all the organizations
      items += [(url, "List participating Organizations", 'any_access')]

      if not student_entity and \
          timeline_helper.isBeforeEvent(timeline_entity, 'program_end'):
        # add apply to become a mentor link
        items += [
            ('/gsoc/org/apply_mentor/%s' % (program_entity.key().id_or_name()),
           "Apply to become a Mentor", 'any_access')]

    deadline = 'accepted_students_announced_deadline'

    if timeline_helper.isAfterEvent(timeline_entity, deadline):
      items += [(redirects.getListProjectsRedirect(program_entity,
          {'url_name':'gsoc/program'}),
          "List all Student Projects", 'any_access')]

    return items