Example #1
0
  def getSidebarMenus(self, id, user, params=None):
    """Returns the extra menu's for this view.

    A menu item is generated for each program that is currently
    running. The public page for each program is added as menu item,
    as well as all public documents for that program.

    Args:
      params: a dict with params for this View.
    """

    rights = params['rights']

    menus = []

    rights.setCurrentUser(id, user)

    items = [('/seeder/home', 'Manage Data Seeder', '')]
    items = sidebar.getSidebarMenu(id, user, items, params=params)

    menu = {}
    menu['heading'] = 'Data Seeder'
    menu['items'] = items
    menu['group'] = 'Developer'
    menu['collapse'] = 'collapse'
    menus.append(menu)

    return menus
Example #2
0
    def getSidebarMenus(self, id, user, params=None):
        """Returns the extra menu's for this view.

    A menu item is generated for each program that is currently
    running. The public page for each program is added as menu item,
    as well as all public documents for that program.

    Args:
      params: a dict with params for this View.
    """

        rights = params['rights']

        menus = []

        rights.setCurrentUser(id, user)

        items = [('/seeder/home', 'Manage Data Seeder', '')]
        items = sidebar.getSidebarMenu(id, user, items, params=params)

        menu = {}
        menu['heading'] = 'Data Seeder'
        menu['items'] = items
        menu['group'] = 'Developer'
        menu['collapse'] = 'collapse'
        menus.append(menu)

        return menus
Example #3
0
  def getExtraMenus(self, id, user, params=None):
    """Returns the extra menu's for this view.

    A menu item is generated for each program that is currently
    running. The public page for each program is added as menu item,
    as well as all public documents for that program.

    Args:
      params: a dict with params for this View.
    """

    from soc.views.models import survey as survey_view
    from soc.views.models import project_survey as project_survey_view
    from soc.views.models import grading_project_survey as grading_survey_view

    logic = params['logic']
    rights = params['rights']

    # only get all invisible and visible programs
    fields = {'status': ['invisible', 'visible']}
    entities = logic.getForFields(fields)

    menus = []

    rights.setCurrentUser(id, user)

    for entity in entities:
      items = []

      if entity.status == 'visible':
        # show the documents for this program, even for not logged in users
        items += document_view.view.getMenusForScope(entity, params)
        items += survey_view.view.getMenusForScope(entity, params, id, user)
        items += project_survey_view.view.getMenusForScope(
            entity, params, id, user)
        items += grading_survey_view.view.getMenusForScope(
            entity, params, id, user)
        items += self._getTimeDependentEntries(entity, params, id, user)
      try:
        # check if the current user is a host for this program
        rights.doCachedCheck('checkIsHostForProgram',
                             {'scope_path': entity.scope_path,
                              'link_id': entity.link_id}, [])

        if entity.status == 'invisible':
          # still add the document links so hosts can see how it looks like
          items += document_view.view.getMenusForScope(entity, params)
          items += survey_view.view.getMenusForScope(entity, params, id, user)
          items += project_survey_view.view.getMenusForScope(
              entity, params, id, user)
          items += grading_survey_view.view.getMenusForScope(
              entity, params, id, user)
          items += self._getTimeDependentEntries(entity, params, id, user)

        items += [(redirects.getReviewOverviewRedirect(
            entity, {'url_name': 'org_app'}),
            "Review Organization Applications", 'any_access')]
        # add link to edit Program Profile
        items += [(redirects.getEditRedirect(entity, params),
            'Edit Program Profile', 'any_access')]
        # add link to Assign Slots
        items += [(redirects.getAssignSlotsRedirect(entity, params),
            'Assign Slots', 'any_access')]
        # add link to Show Duplicate project assignments
        items += [(redirects.getShowDuplicatesRedirect(entity, params),
            'Show Duplicate Project Assignments', 'any_access')]
        # add link to edit Program Timeline
        items += [(redirects.getEditRedirect(entity, {'url_name': 'timeline'}),
            "Edit Program Timeline", 'any_access')]
        # add link to create a new Program Document
        items += [(redirects.getCreateDocumentRedirect(entity, 'program'),
            "Create a New Document", 'any_access')]
        # add link to list all Program Document
        items += [(redirects.getListDocumentsRedirect(entity, 'program'),
            "List Documents", 'any_access')]
        # add link to create a new Program Survey
        items += [(redirects.getCreateSurveyRedirect(entity, 'program',
            'survey'),
            "Create a New Survey", 'any_access')]
        # add link to list all Program Surveys
        items += [(redirects.getListSurveysRedirect(entity, 'program',
            'survey'),
            "List Surveys", 'any_access')]
        # add link to create a new Project Survey
        items += [(redirects.getCreateSurveyRedirect(entity, 'program',
            'project_survey'),
            "Create a New Project Survey", 'any_access')]
        # add link to list all Project Surveys
        items += [(redirects.getListSurveysRedirect(entity, 'program',
            'project_survey'),
            "List Project Surveys", 'any_access')]
        # add link to create a new Grading Survey
        items += [(redirects.getCreateSurveyRedirect(entity, 'program',
            'grading_project_survey'),
            "Create a New Grading Survey", 'any_access')]
        # add link to list all Grading Surveys
        items += [(redirects.getListSurveysRedirect(entity, 'program',
            'grading_project_survey'),
            "List Grading Surveys", 'any_access')]

      except out_of_band.Error:
        pass

      items = sidebar.getSidebarMenu(id, user, items, params=params)
      if not items:
        continue

      menu = {}
      menu['heading'] = entity.short_name
      menu['items'] = items
      menu['group'] = 'Programs'
      menus.append(menu)

    return menus
Example #4
0
  def getExtraMenus(self, id, user, params=None):
    """Returns the extra menu's for this view.

    A menu item is generated for each group that the user has an active
    role for. The public page for each group is added as menu item,
    as well as all public documents for that group.

    Args:
      params: a dict with params for this View.
    """

    params = dicts.merge(params, self._params)

    # set fields to match every active role this user has
    fields = {'user': user,
              'status': 'active'}

    # get the role views and start filling group_entities
    role_views = self._params['role_views']
    role_descriptions = {}

    for role_name in role_views.keys():
      role_view = role_views[role_name]
      role_view_params = role_view.getParams()
      role_logic = role_view_params['logic']

      roles = role_logic.getForFields(fields)

      for role in roles:
        group_key_name = role.scope.key().id_or_name()
        existing_role_descriptions = role_descriptions.get(group_key_name)

        if existing_role_descriptions:
          # add this description to existing roles
          existing_roles = existing_role_descriptions['roles']
          existing_roles[role_name] = role
        else:
          # create a description of this role
          role_description = {'roles': {role_name: role},
              'group': role.scope}

          # add the new entry to our dictionary
          role_descriptions[group_key_name] = role_description

    # get the document view params to add the group's documents to the menu
    doc_params = document_view.view.getParams()

    menus = []

    # for each role description in our collection
    for role_description in role_descriptions.itervalues():
      #start with an empty menu
      menu = {}

      # get the group for this role description
      group_entity = role_description['group']

      # set the menu header name
      menu['heading'] = group_entity.short_name

      # get the documents for this group entity
      doc_items = document_view.view.getMenusForScope(group_entity, params)
      doc_items = sidebar.getSidebarMenu(id, user, doc_items,
                                         params=doc_params)

      # get the group specific items
      group_items = self._getExtraMenuItems(role_description, params)
      group_items = sidebar.getSidebarMenu(id, user, group_items,
                                           params=self._params)

      # add the items together
      menu['items'] = doc_items + group_items
      menu['group'] = params['name_plural']

      # append this as a new menu
      menus.append(menu)

    return menus
Example #5
0
    def getExtraMenus(self, id, user, params=None):
        """See soc.views.models.program.View.getExtraMenus().
    """

        # TODO: the largest part of this method can be moved to the core Program

        logic = params['logic']
        rights = params['rights']

        # only get all invisible and visible programs
        fields = {'status': ['invisible', 'visible']}
        entities = logic.getForFields(fields)

        menus = []

        rights.setCurrentUser(id, user)

        for entity in entities:
            items = []

            if entity.status == 'visible':
                # show the documents for this program, even for not logged in users
                items += document_view.view.getMenusForScope(entity, params)
                items += self._getTimeDependentEntries(entity, params, id,
                                                       user)

            try:
                # check if the current user is a host for this program
                rights.doCachedCheck('checkIsHostForProgram', {
                    'scope_path': entity.scope_path,
                    'link_id': entity.link_id
                }, [logic])

                if entity.status == 'invisible':
                    # still add the document links so hosts can see how it looks like
                    items += self._getTimeDependentEntries(
                        entity, params, id, user)

                items += self._getHostEntries(entity, params, 'ghop')

                items += [(redirects.getReviewOverviewRedirect(
                    entity, {
                        'url_name': 'ghop/org_app',
                        'scope_view': self
                    }), "Review Organization Applications", 'any_access')]
                # add link to Assign Task Quota limits
                items += [(ghop_redirects.getAssignTaskQuotasRedirect(
                    entity, params), 'Assign Task Quota limits', 'any_access')]
                # add link to edit Task Difficulty Levels
                items += [(ghop_redirects.getDifficultyEditRedirect(
                    entity, {'url_name': 'ghop/program'}),
                           "Edit Task Difficulty Levels", 'any_access')]
                # add link to edit Task Type Tags
                items += [(ghop_redirects.getTaskTypeEditRedirect(
                    entity, {'url_name': 'ghop/program'}),
                           "Edit Task Type Tags", 'any_access')]

            except out_of_band.Error:
                pass

            items = sidebar.getSidebarMenu(id, user, items, params=params)
            if not items:
                continue

            menu = {}
            menu['heading'] = entity.short_name
            menu['items'] = items
            menu['group'] = 'Programs'
            menus.append(menu)

        return menus
Example #6
0
  def getExtraMenus(self, id, user, params=None):
    """See soc.views.models.program.View.getExtraMenus().
    """
    from soc.modules.gci.views.models.org_app_survey import view as org_app_view

    params['org_app_view'] = org_app_view

    # TODO: the largest part of this method can be moved to the core Program

    logic = params['logic']
    rights = params['rights']

    # only get all invisible and visible programs
    fields = {'status': ['invisible', 'visible']}
    entities = logic.getForFields(fields)

    menus = []

    rights.setCurrentUser(id, user)

    for entity in entities:
      items = []

      if entity.status == 'visible':
        # show the documents for this program, even for not logged in users
        items += document_view.view.getMenusForScope(entity, params)
        items += self._getTimeDependentEntries(entity, params, id, user)

      try:
        # check if the current user is a host for this program
        rights.doCachedCheck('checkIsHostForProgram',
                             {'scope_path': entity.scope_path,
                              'link_id': entity.link_id}, [logic])

        if entity.status == 'invisible':
          # still add the document links so hosts can see how it looks like
          items += self._getTimeDependentEntries(entity, params, id, user)

        items += self._getHostEntries(entity, params, 'gci')

        # add link to Assign Task Quota limits
        items += [(gci_redirects.getAssignTaskQuotasRedirect(entity, params),
            'Assign Task Quota limits', 'any_access')]
        # add link to edit Task Difficulty Levels
        items += [(gci_redirects.getDifficultyEditRedirect(
            entity, {'url_name': 'gci/program'}),
            "Edit Task Difficulty Levels", 'any_access')]
        # add link to edit Task Type Tags
        items += [(gci_redirects.getTaskTypeEditRedirect(
            entity, {'url_name': 'gci/program'}),
            "Edit Task Type Tags", 'any_access')]

      except out_of_band.Error:
        pass

      items = sidebar.getSidebarMenu(id, user, items, params=params)
      if not items:
        continue

      menu = {}
      menu['heading'] = entity.short_name
      menu['items'] = items
      menu['group'] = 'Programs'
      menus.append(menu)

    return menus
Example #7
0
  def getExtraMenus(self, id, user, params=None):
    """Returns the extra menu's for this view.

    A menu item is generated for each group that the user has an active
    role for. The public page for each group is added as menu item,
    as well as all public documents for that group.

    Args:
      params: a dict with params for this View.
    """

    params = dicts.merge(params, self._params)

    # set fields to match every active/inactive role this user has
    fields = {
        'user': user,
        'status': ['active', 'inactive']
        }

    # get the role views and start filling group_entities
    role_views = self._params['role_views']
    role_descriptions = {}

    for role_name in role_views.keys():
      role_view = role_views[role_name]
      role_view_params = role_view.getParams()
      role_logic = role_view_params['logic']

      roles = role_logic.getForFields(fields)

      for role in roles:
        group_key_name = role.scope.key().id_or_name()
        existing_role_descriptions = role_descriptions.get(group_key_name)

        if existing_role_descriptions:
          # add this description to existing roles
          existing_roles = existing_role_descriptions['roles']
          existing_roles[role_name] = role
        else:
          # create a description of this role
          role_description = {'roles': {role_name: role},
              'group': role.scope}

          # add the new entry to our dictionary
          role_descriptions[group_key_name] = role_description

    # get the document view params to add the group's documents to the menu
    doc_params = document_view.view.getParams()

    menus = []

    # for each role description in our collection
    for role_description in role_descriptions.itervalues():
      #start with an empty menu
      menu = {}

      # get the group for this role description
      group_entity = role_description['group']

      # set the menu header name
      menu['heading'] = group_entity.short_name

      # get the documents for this group entity
      doc_items = document_view.view.getMenusForScope(group_entity, params)
      doc_items = sidebar.getSidebarMenu(id, user, doc_items,
                                         params=doc_params)

      # get the group specific items
      group_items = self._getExtraMenuItems(role_description, params)
      group_items = sidebar.getSidebarMenu(id, user, group_items,
                                           params=self._params)

      # add the items together
      menu['items'] = doc_items + group_items
      menu['group'] = params['name_plural']

      # append this as a new menu
      menus.append(menu)

    return menus
Example #8
0
    def getExtraMenus(self, id, user, params=None):
        """Returns the extra menu's for this view.

    A menu item is generated for each program that is currently
    running. The public page for each program is added as menu item,
    as well as all public documents for that program.

    Args:
      params: a dict with params for this View.
    """

        # TODO: the largest part of this method can be moved to the core Program

        logic = params['logic']
        rights = params['rights']

        # only get all valid programs
        fields = {'status': ['invisible', 'visible', 'inactive']}
        entities = logic.getForFields(fields)

        menus = []

        rights.setCurrentUser(id, user)

        for entity in entities:
            items = []

            # some entries should be shown for all programs which are not hidden
            if entity.status in ['visible', 'inactive']:
                items += self._getStandardProgramEntries(
                    entity, id, user, params)
                items += self._getSurveyEntries(entity, params, id, user)
            try:
                # check if the current user is a host for this program
                rights.doCachedCheck('checkIsHostForProgram', {
                    'scope_path': entity.scope_path,
                    'link_id': entity.link_id
                }, [logic])

                if entity.status == 'invisible':
                    # still add the standard entries so hosts can see how it looks like
                    items += self._getStandardProgramEntries(
                        entity, id, user, params)
                    items += self._getSurveyEntries(entity, params, id, user)

                items += self._getHostEntries(entity, params, 'gsoc')

                items += [(redirects.getReviewOverviewRedirect(
                    entity, {'url_name': 'org_app'}),
                           "Review Organization Applications", 'any_access')]

                # add link to Assign Slots
                items += [(redirects.getAssignSlotsRedirect(entity, params),
                           'Assign Slots', 'any_access')]
                # add link to Show Duplicate project assignments
                items += [(redirects.getShowDuplicatesRedirect(entity, params),
                           'Show Duplicate Project Assignments', 'any_access')]
                # add link to create a new Program Survey
                items += [
                    (redirects.getCreateSurveyRedirect(entity, 'gsoc_program',
                                                       'survey'),
                     "Create a New Survey", 'any_access')
                ]
                # add link to list all Program Surveys
                items += [
                    (redirects.getListSurveysRedirect(entity, 'gsoc_program',
                                                      'survey'),
                     "List Surveys", 'any_access')
                ]
                # add link to create a new Project Survey
                items += [
                    (redirects.getCreateSurveyRedirect(entity, 'gsoc_program',
                                                       'gsoc/project_survey'),
                     "Create a New Project Survey", 'any_access')
                ]
                # add link to list all Project Surveys
                items += [
                    (redirects.getListSurveysRedirect(entity, 'gsoc_program',
                                                      'gsoc/project_survey'),
                     "List Project Surveys", 'any_access')
                ]
                # add link to create a new Grading Survey
                items += [(redirects.getCreateSurveyRedirect(
                    entity, 'gsoc_program', 'gsoc/grading_project_survey'),
                           "Create a New Grading Survey", 'any_access')]
                # add link to list all Grading Surveys
                items += [(redirects.getListSurveysRedirect(
                    entity, 'gsoc_program', 'gsoc/grading_project_survey'),
                           "List Grading Surveys", 'any_access')]
                # add link to withdraw Student Projects
                items += [(redirects.getWithdrawRedirect(
                    entity, {'url_name': 'student_project'}),
                           "Withdraw Student Projects", 'any_access')]

            except out_of_band.Error:
                pass

            items = sidebar.getSidebarMenu(id, user, items, params=params)
            if not items:
                continue

            menu = {}
            menu['heading'] = entity.short_name
            menu['items'] = items
            menu['group'] = 'Programs'
            menu[
                'collapse'] = 'collapse' if entity.status == 'inactive' else ''
            menus.append(menu)

        return menus
Example #9
0
  def getExtraMenus(self, id, user, params=None):
    """Returns the extra menu's for this view.

    A menu item is generated for each program that is currently
    running. The public page for each program is added as menu item,
    as well as all public documents for that program.

    Args:
      params: a dict with params for this View.
    """
    from soc.modules.gsoc.views.models.org_app_survey import view as org_app_view

    params['org_app_view'] = org_app_view

    # TODO: the largest part of this method can be moved to the core Program

    logic = params['logic']
    rights = params['rights']

    # only get all valid programs
    fields = {'status': ['invisible', 'visible', 'inactive']}
    entities = logic.getForFields(fields)

    menus = []

    rights.setCurrentUser(id, user)

    for entity in entities:
      items = []

      # some entries should be shown for all programs which are not hidden
      if entity.status in ['visible', 'inactive']:
        items += self._getStandardProgramEntries(entity, id, user, params)
        items += self._getSurveyEntries(entity, params, id, user)
      try:
        # check if the current user is a host for this program
        rights.doCachedCheck('checkIsHostForProgram',
                             {'scope_path': entity.scope_path,
                              'link_id': entity.link_id}, [logic])

        if entity.status == 'invisible':
          # still add the standard entries so hosts can see how it looks like
          items += self._getStandardProgramEntries(entity, id, user, params)
          items += self._getSurveyEntries(entity, params, id, user)

        items += self._getHostEntries(entity, params, 'gsoc')

        # add link to Assign Slots
        items += [(redirects.getAssignSlotsRedirect(entity, params),
            'Assign Slots', 'any_access')]
        # add link to Show Duplicate project assignments
        items += [(redirects.getShowDuplicatesRedirect(entity, params),
            'Show Duplicate Project Assignments', 'any_access')]
        # add link to create a new Program Survey
        items += [(redirects.getCreateSurveyRedirect(
            entity, params['document_prefix'], 'survey'),
            "Create a New Survey", 'any_access')]
        # add link to list all Program Surveys
        items += [(redirects.getListSurveysRedirect(
            entity, params['document_prefix'], 'survey'),
            "List Surveys", 'any_access')]
        # add link to create a new Project Survey
        items += [(redirects.getCreateSurveyRedirect(
            entity, params['document_prefix'], 'gsoc/project_survey'),
            "Create a New Project Survey", 'any_access')]
        # add link to list all Project Surveys
        items += [(redirects.getListSurveysRedirect(
            entity, params['document_prefix'], 'gsoc/project_survey'),
            "List Project Surveys", 'any_access')]
        # add link to create a new Grading Survey
        items += [(redirects.getCreateSurveyRedirect(
            entity, params['document_prefix'], 'gsoc/grading_project_survey'),
            "Create a New Grading Survey", 'any_access')]
        # add link to list all Grading Surveys
        items += [(redirects.getListSurveysRedirect(
            entity, params['document_prefix'], 'gsoc/grading_project_survey'),
            "List Grading Surveys", 'any_access')]
        # add link to list all Grading Surveys
        items += [(redirects.getListRedirect(
             entity, {'url_name': 'gsoc/grading_survey_group'}),
            "List Grading Survey Groups", 'any_access')]
        # add link to view Student Projects
        items += [(redirects.getOverviewRedirect(
             entity, {'url_name': 'gsoc/student_project'}),
            "View all Student Projects", 'any_access')]

      except out_of_band.Error:
        pass

      items = sidebar.getSidebarMenu(id, user, items, params=params)
      if not items:
        continue

      menu = {}
      menu['heading'] = entity.short_name
      menu['items'] = items
      menu['group'] = 'Programs'
      menu['collapse'] = 'collapse' if entity.status == 'inactive' else ''
      menus.append(menu)

    return menus