Пример #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.modules.gsoc.logic.models.student import logic as \
        student_logic

    survey_logic = params['logic']

    user_entity = user_logic.getCurrentUser()

    # 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)

    fields = {'student': student_entity,
              'status': 'accepted'}

    return fields
Пример #2
0
    def _getResultsViewRecordFields(self, survey, allowed_to_read):
        """Get the Results View filter for ProjectSurveyRecords.

    For args see survey.View()._getResultsViewRecordFields()

    Returns:
      Returns the dictionary containing the fields to filter on
    """

        from soc.modules.gsoc.logic.models.org_admin import logic as \
            org_admin_logic
        from soc.modules.gsoc.logic.models.student import logic as \
            student_logic

        if allowed_to_read:
            return super(View, self)._getResultsViewRecordFields(
                survey, allowed_to_read)

        fields = {'survey': survey}

        program_entity = survey.scope
        user_entity = user_logic.getForCurrentAccount()

        student_fields = {
            'scope': program_entity,
            'user': user_entity,
            'status': ['active', 'inactive']
        }
        student_entity = student_logic.getForFields(student_fields,
                                                    unique=True)

        if student_entity:
            # just get all records for the current user
            fields['user'] = user_entity
            return fields

        org_admin_fields = {
            'user': user_entity,
            'program': program_entity,
            'status': ['active', 'inactive']
        }

        org_admins = org_admin_logic.getForFields(org_admin_fields)

        if org_admins:
            # filter on all the organizations this user is org admin for
            organizations = []

            for org_admin in org_admins:
                organizations.append(org_admin.scope)

            # TODO: this might blow up if the user is org admin for too many orgs
            fields['org'] = organizations

        if not student_entity and not org_admins:
            # return only the surveys for the current user
            fields['user'] = user_entity

        return fields
Пример #3
0
  def _getResultsViewRecordFields(self, survey, allowed_to_read):
    """Get the Results View filter for ProjectSurveyRecords.

    For args see survey.View()._getResultsViewRecordFields()

    Returns:
      Returns the dictionary containing the fields to filter on
    """

    from soc.modules.gsoc.logic.models.org_admin import logic as \
        org_admin_logic
    from soc.modules.gsoc.logic.models.student import logic as \
        student_logic

    if allowed_to_read:
      return super(View, self)._getResultsViewRecordFields(survey,
                                                           allowed_to_read)

    fields = {'survey': survey}

    program_entity = survey.scope
    user_entity = user_logic.getCurrentUser()

    student_fields = {'scope': program_entity,
                      'user': user_entity,
                      'status': ['active', 'inactive']}
    student_entity = student_logic.getForFields(student_fields, unique=True)

    if student_entity:
      # just get all records for the current user
      fields['user'] = user_entity
      return fields

    org_admin_fields = {'user': user_entity,
                        'program': program_entity,
                        'status': ['active', 'inactive']}

    org_admins = org_admin_logic.getForFields(org_admin_fields)

    if org_admins:
      # filter on all the organizations this user is org admin for
      organizations = []

      for org_admin in org_admins:
        organizations.append(org_admin.scope)

      # TODO: this might blow up if the user is org admin for too many orgs
      fields['org'] = organizations

    if not student_entity and not org_admins:
      # return only the surveys for the current user
      fields['user'] = user_entity

    return fields
Пример #4
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
Пример #5
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