Esempio n. 1
0
    def acceptedOrgs(self, request, page_name, params, program_entity,
                     org_view, org_app_view):
        """See base.View.list.
    """

        logic = params['logic']

        list_params = org_view.getParams().copy()
        list_params['list_msg'] = program_entity.accepted_orgs_msg

        fmt = {'name': program_entity.name}

        org_app_params = org_app_view.getParams()

        # try to retrieve an accepted record
        org_app_logic = org_app_params['logic']
        org_app = org_app_logic.getForProgram(program_entity)

        aa_params = org_app_params['record_list_params'].copy(
        )  # accepted applications
        aa_params['public_row_extra'] = lambda entity: {}
        description = self.DEF_ACCEPTED_ORGS_MSG_FMT % fmt
        aa_params['list_description'] = description
        aa_params['public_conf_extra'] = {
            "rowNum": -1,
            "rowList": [],
        }

        description = self.DEF_CREATED_ORGS_MSG_FMT % fmt
        ap_params = org_view.getParams().copy()
        ap_params['list_description'] = description
        ap_params['public_row_extra'] = lambda entity: {
            'link': redirects.getHomeRedirect(entity, ap_params),
        }
        ap_params['public_conf_extra'] = {
            "rowNum": -1,
            "rowList": [],
        }

        if lists.isDataRequest(request):
            return self.getAcceptedOrgsData(request, aa_params, ap_params,
                                            org_app_logic, program_entity)

        contents = []
        order = ['name']

        ap_list = lists.getListGenerator(request,
                                         ap_params,
                                         order=order,
                                         idx=0)
        contents.append(ap_list)

        aa_list = lists.getListGenerator(request,
                                         aa_params,
                                         order=order,
                                         idx=1)
        contents.append(aa_list)

        return self._list(request, list_params, contents, page_name)
Esempio n. 2
0
  def acceptedOrgs(self, request, page_name, params, program_entity,
                   org_view, org_app_view):
    """See base.View.list.
    """

    logic = params['logic']

    list_params = org_view.getParams().copy()
    list_params['list_msg'] = program_entity.accepted_orgs_msg

    fmt = {'name': program_entity.name}

    org_app_params = org_app_view.getParams()

    # try to retrieve an accepted record
    org_app_logic = org_app_params['logic']
    org_app = org_app_logic.getForProgram(program_entity)

    aa_params = org_app_params['record_list_params'].copy() # accepted applications
    aa_params['public_row_extra'] = lambda entity: {}
    description = self.DEF_ACCEPTED_ORGS_MSG_FMT % fmt
    aa_params['list_description'] = description
    aa_params['public_conf_extra'] = {
        "rowNum": -1,
        "rowList": [],
    }

    description = self.DEF_CREATED_ORGS_MSG_FMT % fmt
    ap_params = org_view.getParams().copy()
    ap_params['list_description'] = description
    ap_params['public_row_extra'] = lambda entity: {
        'link': redirects.getHomeRedirect(entity, ap_params),
    }
    ap_params['public_conf_extra'] = {
        "rowNum": -1,
        "rowList": [],
    }

    if lists.isDataRequest(request):
      return self.getAcceptedOrgsData(
          request, aa_params, ap_params, org_app_logic, program_entity)

    contents = []
    order = ['name']

    ap_list = lists.getListGenerator(request, ap_params, order=order, idx=0)
    contents.append(ap_list)

    aa_list = lists.getListGenerator(request, aa_params, order=order, idx=1)
    contents.append(aa_list)

    return self._list(request, list_params, contents, page_name)
Esempio n. 3
0
    def listMyTasks(self,
                    request,
                    access_type,
                    page_name=None,
                    params=None,
                    **kwargs):
        """Displays a list of all starred tasks for the current user.

    If the current user is a student it also lists all tasks claimed by them.

    See base.View.list() for more details.
    """
        from soc.modules.gci.views.models import task as gci_task_view
        from soc.modules.gci.views.models import task_subscription as \
            gci_subscription_view

        program = gci_program_logic.logic.getFromKeyFieldsOr404(kwargs)
        user = user_logic.getCurrentUser()

        task_params = gci_task_view.view.getParams().copy()
        task_params['list_description'] = ugettext(
            'Tasks that you have claimed.')

        subscription_params = gci_subscription_view.view.getParams().copy()
        subscription_params['list_description'] = ugettext(
            'Tasks that you have starred.')

        if lists.isDataRequest(request):
            return self.getListMyTasksData(request, task_params,
                                           subscription_params, program, user)

        contents = []

        fields = {
            'user': user,
            'status': ['active', 'inactive'],
        }
        if gci_student_logic.logic.getForFields(fields, unique=True):
            order = ['modified_on']
            tasks_list = lists.getListGenerator(request,
                                                task_params,
                                                order=order,
                                                idx=0)
            contents.append(tasks_list)

        starred_tasks_list = lists.getListGenerator(request,
                                                    subscription_params,
                                                    idx=1)
        contents.append(starred_tasks_list)

        return self._list(request, task_params, contents, page_name)
Esempio n. 4
0
    def listSelf(self,
                 request,
                 access_type,
                 page_name=None,
                 params=None,
                 **kwargs):
        """View that lists all the OrgAppRecords you have access to.

    For Args see base.View().public().
    """

        survey_logic = params['logic']

        entity = survey_logic.getFromKeyFieldsOr404(kwargs)

        list_params = params['record_list_params'].copy()

        if timeline_helper.isActivePeriod(entity, 'survey'):
            info = {'url_name': params['url_name'], 'survey': entity}
            list_params['self_row_extra'] = lambda entity: {
                'link': redirects.getRetakeOrgAppSurveyRedirect(entity, info)
            }
        else:
            list_params['self_row_extra'] = lambda entity: {
                'link': redirects.getViewSurveyRecordRedirect(entity, params)
            }

        ma_params = list_params.copy()
        ma_params['list_description'] = \
            'List of Applications for which you are Main Admin.'

        ba_params = list_params.copy()
        ba_params['list_description'] = \
            'List of Applications for which your are Backup Admin.'

        if lists.isDataRequest(request):
            return self._getListSelfData(request, entity, ma_params, ba_params)

        ma_list = lists.getListGenerator(request,
                                         ma_params,
                                         visibility='self',
                                         idx=0)
        ba_list = lists.getListGenerator(request,
                                         ba_params,
                                         visibility='self',
                                         idx=1)

        contents = [ma_list, ba_list]

        return self._list(request, list_params, contents, page_name)
Esempio n. 5
0
    def home(self, request, access_type, page_name=None, params=None, **kwargs):
        """See base.View._public().
    """

        from soc.modules.gci.views.models import task as gci_task_view

        context = {"list": []}

        entity = self._params["logic"].getFromKeyFieldsOr404(kwargs)
        gci_program_entity = entity.scope

        params = params.copy() if params else {}

        is_after_student_signup = timeline_helper.isAfterEvent(gci_program_entity.timeline, "student_signup_start")

        is_after_tasks_become_public = timeline_helper.isAfterEvent(
            gci_program_entity.timeline, "tasks_publicly_visible"
        )

        if is_after_student_signup and is_after_tasks_become_public:
            list_params = gci_task_view.view.getParams().copy()

            list_params["list_description"] = self.DEF_PROJECTS_MSG_FMT % (entity.name)

            if lists.isDataRequest(request):
                return self.getListTasksData(request, list_params, entity)

            content = lists.getListGenerator(request, list_params, visibility="home", idx=0)
            contents = [content]
            context["list"] = soc.logic.lists.Lists(contents)

        params["context"] = context

        return super(View, self).home(request, "any_access", page_name=page_name, params=params, **kwargs)
Esempio n. 6
0
  def listParticipants(self, request, access_type, page_name=None,
                       params=None, **kwargs):
    """View that lists the roles of all the participants for a single Program.

    For args see base.list().
    """

    from soc.views.models.role import ROLE_VIEWS

    program_logic = params['logic']
    program_entity = program_logic.getFromKeyFieldsOr404(kwargs)

    if lists.isDataRequest(request):
      return self.getListParticipantsData(request, params, program_entity)

    # we need to generate the lists to be shown on this page
    participants = []

    idx = 0
    for (role_logic, _) in params['participants_logic']:
      # retrieve the role view belonging to the logic
      role_view = ROLE_VIEWS[role_logic.role_name]
      role_params = role_view.getParams().copy()
      role_params['list_description'] = 'List of All %s' %(
          role_params['name_plural'])

      role_list = lists.getListGenerator(request, role_params,
                                         visibility='admin', idx=idx)
      participants.append(role_list)

      idx = idx + 1

    page_name = '%s %s' %(page_name, program_entity.name)
    return self._list(request, params, contents=participants,
                      page_name=page_name)
Esempio n. 7
0
  def overviewGet(self, request, page_name, params, program_entity, **kwargs):
    """Handles the GET request for the Program Admins overview page.

    Args:
      request: Django HTTPRequest object
      page_name: Name for this page
      params: Params for this view
      program_entity: GSocProgram entity
    """

    page_name = '%s %s' %(page_name, program_entity.name)

    list_params = params.copy()
    list_params['admin_row_extra'] = lambda entity: {
        'link': redirects.getPublicRedirect(entity, list_params)
    }

    list_params['list_description'] = ugettext(
        'An overview of all StudentProjects for %s. Click on an item to view '
        'the project, use the buttons on the list for withdrawing a project.'%
        (program_entity.name))

    if lists.isDataRequest(request):
      return self.getOverviewData(request, list_params, program_entity)

    project_list = lists.getListGenerator(request, list_params, idx=0, visibility='admin')

    # fill contents with the list
    contents = [project_list]

    # call the _list method from base to display the list
    return self._list(request, params, contents, page_name)
Esempio n. 8
0
  def list(self, request, access_type, page_name=None,
           params=None, filter=None, order=None,
           visibility=None, context=None, **kwargs):
    """Displays the list page for the entity type.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      filter: a dict for the properties that the entities should have

    Params usage:
      The params dictionary is passed as argument to getListContent in
      the soc.views.helper.list module. See the docstring for getListContent
      on how it uses it. The params dictionary is also passed as argument to
      the _list method. See the docstring for _list on how it uses it.
    """

    if lists.isDataRequest(request):
      return self.getListData(request, params, visibility, filter)

    content = lists.getListGenerator(request, params, order=order,
                                            visibility=visibility, idx=0)
    contents = [content]

    return self._list(request, params, contents, page_name, context=context)
Esempio n. 9
0
  def roles(self, request, access_type,
               page_name=None, params=None, **kwargs):
    """Displays the valid roles for this user.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: not used
    """

    lists_params = []

    for _, loop_view in sorted(role_view.ROLE_VIEWS.iteritems()):
      list_params = loop_view.getParams()

      if not list_params['show_in_roles_overview']:
        # filler for easy indexing
        lists_params.append(None)
        continue

      list_params = list_params.copy()
      list_params['public_field_keys'] = list_params['public_field_keys'] + ['status']
      list_params['public_field_names'] = list_params['public_field_names'] + ['Status']
      list_params['list_description'] = self.DEF_ROLE_LIST_MSG_FMT % list_params
      field_props = list_params.setdefault('public_field_props', {})
      field_props['status'] = {
          'searchoptions': {'defaultValue': 'Active'},
          'stype': 'select',
          'editoptions': {'value': ':All;^active$:Active;^inactive$:Inactive'},
      }

      lists_params.append(list_params)

    if lists.isDataRequest(request):
      return self.getRolesListData(request, lists_params)

    contents = []

    for i, list_params in enumerate(lists_params):
      if list_params is None:
        continue

      if not self.getRolesListData(lists.IsNonEmptyRequest(i), lists_params):
        continue

      list = lists.getListGenerator(request, list_params, idx=i)
      contents.append(list)

    params = params.copy()

    if not contents:
      site_name = site_logic.getSingleton().site_name
      params['list_msg'] = self.DEF_NO_ROLES_MSG_FMT % site_name

    return self._list(request, params, contents, page_name)
Esempio n. 10
0
  def listTasks(self, request, access_type, page_name=None, params=None,
                **kwargs):
    """View where all the tasks can be searched from.
    """

    from soc.modules.gci.views.models.task import view as task_view

    logic = params['logic']

    program_entity = logic.getFromKeyFieldsOr404(kwargs)

    page_name = '%s %s' % (page_name, program_entity.name)

    list_params = task_view.getParams().copy()

    user_account = user_logic.getCurrentUser()
    user_fields = {
        'user': user_account,
        'status': 'active'
        }

    host_entity = host_logic.getForFields(user_fields, unique=True)

    tasks_filter = {
        'program': program_entity,
        'status': ['Open', 'Reopened', 'ClaimRequested']
    }

    if host_entity:
      list_params['list_description'] = self.DEF_LIST_VALID_TASKS_MSG_FMT % (
          program_entity.name)
      tasks_filter['status'].extend([
          'Claimed', 'ActionNeeded', 'Closed', 'AwaitingRegistration',
          'NeedsWork', 'NeedsReview','Unapproved', 'Unpublished'])
    else:
      list_params.setdefault('public_field_ignore', []).append('mentors')
      list_params['list_description'] = self.DEF_LIST_PUBLIC_TASKS_MSG_FMT % (
          program_entity.name)

    list_params['public_row_extra'] = lambda entity, *args: {
        'link': redirects.getPublicRedirect(entity, list_params)
        }

    list_params['public_conf_min_num'] = list_params['public_conf_limit'] = 100

    if lists.isDataRequest(request):
        return self.getListTasksData(request, list_params, tasks_filter)

    contents = []
    order = ['-modified_on']

    tasks_list = lists.getListGenerator(request, list_params,
                                        order=order, idx=0)
    contents.append(tasks_list)

    return self._list(request, list_params, contents, page_name)
Esempio n. 11
0
    def listRoles(self,
                  request,
                  access_type,
                  page_name=None,
                  params=None,
                  **kwargs):
        """Gives an overview of all the roles in a specific group.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

        # set the pagename to include the link_id
        page_name = '%s %s' % (page_name, kwargs['link_id'])

        role_views = params['role_views']

        lists_params = []

        for role_name in sorted(role_views.keys()):
            # create the list parameters
            list_params = role_views[role_name].getParams().copy()

            # Required because without this the lambda refers to list_params,
            # which is set to a different value due to the iteration.
            def getter(list_params):
                return lambda entity: {
                    'link': redirects.getManageRedirect(entity, list_params)
                }

            list_params['public_row_extra'] = getter(list_params)
            list_params['list_description'] = ugettext(
                "An overview of the %s for this %s." %
                (list_params['name_plural'], params['name']))

            lists_params.append(list_params)

        if lists.isDataRequest(request):
            group_logic = params['logic']
            group_entity = group_logic.getFromKeyFields(kwargs)
            return self.getListRolesData(request, lists_params, group_entity)

        contents = []

        index = 0
        for list_params in lists_params:
            list = lists.getListGenerator(request, list_params, idx=index)
            contents.append(list)
            index += 1

        # call the _list method from base.View to show the list
        return self._list(request, params, contents, page_name)
Esempio n. 12
0
  def listMyTasks(self, request, access_type, page_name=None,
                       params=None, **kwargs):
    """Displays a list of all starred tasks for the current user.

    If the current user is a student it also lists all tasks claimed by them.

    See base.View.list() for more details.
    """
    from soc.modules.gci.views.models import task as gci_task_view
    from soc.modules.gci.views.models import task_subscription as \
        gci_subscription_view

    program = gci_program_logic.logic.getFromKeyFieldsOr404(kwargs)
    user = user_logic.getCurrentUser()

    task_params = gci_task_view.view.getParams().copy()
    task_params['list_description'] = ugettext(
        'Tasks that you have claimed.')

    subscription_params = gci_subscription_view.view.getParams().copy()
    subscription_params['list_description'] = ugettext(
        'Tasks that you have starred.')

    if lists.isDataRequest(request):
        return self.getListMyTasksData(request, task_params,
                                       subscription_params, program, user)

    contents = []

    fields = {'user': user,
              'status': ['active', 'inactive'],
              }
    if gci_student_logic.logic.getForFields(fields, unique=True):
      order = ['modified_on']
      tasks_list = lists.getListGenerator(request, task_params,
                                          order=order, idx=0)
      contents.append(tasks_list)

    starred_tasks_list = lists.getListGenerator(request, subscription_params,
                                                idx=1)
    contents.append(starred_tasks_list)

    return self._list(request, task_params, contents, page_name)
Esempio n. 13
0
    def listMentorTasks(self,
                        request,
                        access_type,
                        page_name=None,
                        params=None,
                        **kwargs):
        """Displays a list of all tasks for a given student.

    See base.View.list() for more details.
    """

        entity = params['logic'].getFromKeyFieldsOr404(kwargs)

        # obtain program entity based on request params
        program = entity.program

        user_account = user_logic.logic.getCurrentUser()

        filter = {'user': user_account, 'program': program, 'status': 'active'}

        list_params = gci_task_view.view.getParams().copy()

        list_params['list_description'] = self.DEF_MENTOR_TASKS_MSG_FMT % (
            program.name)

        filter = {
            'program':
            program,
            'mentors': [entity],
            'status': [
                'Unapproved', 'Unpublished', 'Open', 'Reopened',
                'ClaimRequested', 'Claimed', 'ActionNeeded', 'Closed',
                'AwaitingRegistration', 'NeedsWork', 'NeedsReview'
            ]
        }

        if lists.isDataRequest(request):
            return self.getListMentorTasksData(request, list_params, filter)

        tasks = gci_task_logic.logic.getForFields(filter=filter, unique=True)

        contents = []

        if tasks:
            order = ['modified_on']
            tasks_list = lists.getListGenerator(request,
                                                list_params,
                                                order=order,
                                                idx=0)
            contents.append(tasks_list)

        if contents:
            return self._list(request, list_params, contents, page_name)
        else:
            raise out_of_band.Error(self.DEF_NO_TASKS_MSG)
Esempio n. 14
0
    def listSelf(self,
                 request,
                 access_type,
                 page_name=None,
                 params=None,
                 **kwargs):
        """Lists all proposals from the current logged-in user 
       for the given student.

    For params see base.View.public().
    """

        context = {}

        list_params = params.copy()
        list_params['list_description'] = \
            'List of my %(name_plural)s.' % list_params
        list_params['public_row_extra'] = lambda entity: {
            'link': redirects.getPublicRedirect(entity, list_params)
        }

        ip_params = list_params.copy()  # ineligible proposals

        description = ugettext('List of my ineligible/withdrawn %s.') % (
            ip_params['name_plural'])

        ip_params['list_description'] = description
        ip_params['public_row_extra'] = lambda entity: {
            'link': redirects.getPublicRedirect(entity, ip_params)
        }

        if request.GET.get('fmt') == 'json':
            scope_path = kwargs['scope_path']
            return self.getListSelfData(request, list_params, ip_params,
                                        scope_path)

        valid_list = lists.getListGenerator(request, list_params, idx=0)
        ip_list = lists.getListGenerator(request, ip_params, idx=1)

        contents = [valid_list, ip_list]

        return self._list(request, list_params, contents, page_name, context)
Esempio n. 15
0
  def listSelf(self, request, access_type, page_name=None,
           params=None, **kwargs):
    """View that lists all the OrgAppRecords you have access to.

    For Args see base.View().public().
    """

    survey_logic = params['logic']

    entity = survey_logic.getFromKeyFieldsOr404(kwargs)

    list_params = params['record_list_params'].copy()

    if timeline_helper.isActivePeriod(entity, 'survey'):
      info = {'url_name': params['url_name'],
              'survey':entity}
      list_params['self_row_extra'] = lambda entity: {
          'link': redirects.getRetakeOrgAppSurveyRedirect(entity, info)
      }
    else:
      list_params['self_row_extra'] = lambda entity: {
          'link': redirects.getViewSurveyRecordRedirect(entity, params)
      }

    ma_params = list_params.copy()
    ma_params['list_description'] = \
        'List of Applications for which you are Main Admin.'

    ba_params = list_params.copy()
    ba_params['list_description'] = \
        'List of Applications for which your are Backup Admin.'

    if lists.isDataRequest(request):
      return self._getListSelfData(request, entity, ma_params, ba_params)

    ma_list = lists.getListGenerator(request, ma_params, visibility='self', idx=0)
    ba_list = lists.getListGenerator(request, ba_params, visibility='self', idx=1)

    contents = [ma_list, ba_list]

    return self._list(request, list_params, contents, page_name)
Esempio n. 16
0
    def home(self,
             request,
             access_type,
             page_name=None,
             params=None,
             **kwargs):
        """See base.View._public().
    """

        from soc.modules.gsoc.views.models import student_project as \
            student_project_view

        entity = self._logic.getFromKeyFieldsOr404(kwargs)
        program_entity = entity.scope

        params = params.copy() if params else {}

        if timeline_helper.isAfterEvent(
                program_entity.timeline,
                'accepted_students_announced_deadline'):
            # accepted projects
            ap_params = student_project_view.view.getParams().copy()

            ap_params[
                'list_description'] = self.DEF_ACCEPTED_PROJECTS_MSG_FMT % (
                    entity.name)

            if lists.isDataRequest(request):
                return self.getHomeData(request, ap_params, entity)

            ap_list = lists.getListGenerator(request,
                                             ap_params,
                                             idx=0,
                                             visibility='org_home',
                                             order=['name'])

            contents = [ap_list]

            extra_context = {}
            # construct the list and put it into the context
            extra_context['list'] = soc.logic.lists.Lists(contents)

            fields = {'scope': entity, 'status': ['accepted', 'completed']}

            # obtain data to construct the organization map as json object
            extra_context['org_map_data'] = self._getMapData(fields)
            params['context'] = extra_context

        return super(View, self).home(request,
                                      'any_access',
                                      page_name=page_name,
                                      params=params,
                                      **kwargs)
Esempio n. 17
0
  def manageOverview(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """View that allows Organization Admins to see an overview of 
       their Organization's Student Projects.

    For params see base.View().public()
    """

    from soc.modules.gsoc.logic.models.survey import grading_logic as \
        grading_survey_logic
    from soc.modules.gsoc.logic.models.survey import project_logic as \
        project_survey_logic
    from soc.modules.gsoc.logic.models.survey_record import grading_logic
    from soc.modules.gsoc.logic.models.survey_record import project_logic

    # make sure the organization exists
    org_entity = org_logic.getFromKeyNameOr404(kwargs['scope_path'])
    page_name = '%s %s' % (page_name, org_entity.name)

    mo_params = params.copy()
    mo_params['list_heading'] = params['manage_overview_heading']
    mo_params['list_row'] = params['manage_overview_row']

    #list all active projects
    mo_params['list_description'] = \
        'List of all active %(name_plural)s' % mo_params
    mo_params['public_field_names'] = params['public_field_names'] + [
        "Mentor evaluation", "Student Evaluation"]
    mo_params['public_field_keys'] = params['public_field_keys'] + [
        "mentor_evaluation", "student_evaluation"]
    mo_params['public_row_extra'] = lambda entity, *args: {
        'link': redirects.getManageRedirect(entity, mo_params)
    }
    mo_params['public_field_extra'] = lambda entity, ps, psc, gs, gsc: {
        "student": entity.student.name(),
        "mentor": entity.mentor.name(),
        "mentor_evaluation": "%d/%d" % (
                project_logic.getQueryForFields({'project': entity}).count(),
                psc),
        "student_evaluation": "%d/%d" % (
                grading_logic.getQueryForFields({'project': entity}).count(),
                gsc),
    }

    if request.GET.get('fmt') == 'json':
      return self.getManageOverviewData(request, mo_params, org_entity)

    mo_list = lists.getListGenerator(request, mo_params, idx=0)
    contents = [mo_list]

    # call the _list method from base to display the list
    return self._list(request, mo_params, contents, page_name)
Esempio n. 18
0
  def listMentorTasks(self, request, access_type, page_name=None,
                      params=None, **kwargs):
    """Displays a list of all tasks for a given student.

    See base.View.list() for more details.
    """

    entity = params['logic'].getFromKeyFieldsOr404(kwargs)

    # obtain program entity based on request params
    program = entity.program

    user_account = user_logic.logic.getCurrentUser()

    filter = {
        'user': user_account,
        'program': program,
        'status': 'active'
        }

    list_params = gci_task_view.view.getParams().copy()

    list_params['list_description'] = self.DEF_MENTOR_TASKS_MSG_FMT % (
          program.name)

    filter = {
        'program': program,
        'mentors': [entity],
        'status': ['Unapproved', 'Unpublished', 'Open', 'Reopened',
                   'ClaimRequested', 'Claimed', 'ActionNeeded', 'Closed',
                   'AwaitingRegistration', 'NeedsWork', 'NeedsReview']
        }

    if lists.isDataRequest(request):
        return self.getListMentorTasksData(request, list_params,
                                           filter)

    tasks = gci_task_logic.logic.getForFields(filter=filter, unique=True)

    contents = []

    if tasks:
      order = ['modified_on']
      tasks_list = lists.getListGenerator(request, list_params,
                                          order=order, idx=0)
      contents.append(tasks_list)

    if contents:
      return self._list(request, list_params, contents, page_name)
    else:
      raise out_of_band.Error(self.DEF_NO_TASKS_MSG)
Esempio n. 19
0
    def showDetails(self,
                    request,
                    access_type,
                    page_name=None,
                    params=None,
                    **kwargs):
        """Shows ranking details for the entity specified by **kwargs.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

        logic = params['logic']
        ranking = logic.getFromKeyFieldsOr404(kwargs)
        student = ranking.student

        all_d = gci_task_model.TaskDifficultyTag.all().fetch(100)

        list_params = params.copy()
        list_params[
            'list_description'] = self.DETAILS_MSG_FMT % student.user.name
        list_params['public_field_extra'] = lambda entity: {
            'task': entity.title,
            'org': entity.scope.name,
            'points_difficulty': entity.taskDifficulty(all_d).value
        }
        list_params['public_field_keys'] = [
            'task', 'org', 'points_difficulty', 'closed_on'
        ]
        list_params['public_field_names'] = [
            'Task', 'Organization', 'Points (Difficulty)', 'Completed on'
        ]
        list_params['public_row_extra'] = lambda entity: {
            'link': redirects.getPublicRedirect(entity,
                                                {'url_name': 'gci/task'}),
        }

        if lists.isDataRequest(request):
            return self.getListRankingDetailsData(request, list_params,
                                                  student)

        contents = []
        order = ['closed_on']
        list = lists.getListGenerator(request, list_params, order=order, idx=0)
        contents.append(list)

        return self._list(request, list_params, contents, page_name)
Esempio n. 20
0
  def listRoles(self, request, access_type,
                page_name=None, params=None, **kwargs):
    """Gives an overview of all the roles in a specific group.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

    # set the pagename to include the link_id
    page_name = '%s %s' % (page_name, kwargs['link_id'])

    role_views = params['role_views']

    lists_params = []

    for role_name in sorted(role_views.keys()):
      # create the list parameters
      list_params = role_views[role_name].getParams().copy()

      # Required because without this the lambda refers to list_params,
      # which is set to a different value due to the iteration.
      def getter(list_params):
        return lambda entity: {
            'link': redirects.getManageRedirect(entity, list_params)
        }
      list_params['public_row_extra'] = getter(list_params)
      list_params['list_description'] = ugettext(
          "An overview of the %s for this %s." % (
          list_params['name_plural'], params['name']))

      lists_params.append(list_params)

    if lists.isDataRequest(request):
      group_logic = params['logic']
      group_entity = group_logic.getFromKeyFields(kwargs)
      return self.getListRolesData(request, lists_params, group_entity)

    contents = []

    index = 0
    for list_params in lists_params:
      list = lists.getListGenerator(request, list_params, idx=index)
      contents.append(list)
      index += 1

    # call the _list method from base.View to show the list
    return self._list(request, params, contents, page_name)
Esempio n. 21
0
  def withdraw(self, request, access_type,
               page_name=None, params=None, **kwargs):
    """View that allows Program Admins to accept or withdraw Student Projects.

    For params see base.View().public()
    """

    ap_params = params.copy() # accepted projects

    ap_params['public_row_extra'] = lambda entity: {
        'link': redirects.getWithdrawProjectRedirect(entity,ap_params)
    }

    ap_params['list_description'] = ugettext(
        "An overview of accepted and completed Projects. "
        "Click on a project to withdraw it.")

    wp_params = params.copy() # withdrawn projects

    wp_params['public_row_extra'] = lambda entity: {
        'link': redirects.getAcceptProjectRedirect(entity, wp_params)
    }
    wp_params['list_description'] = ugettext(
        "An overview of withdrawn Projects. "
        "Click on a project to undo the withdrawal.")

    if request.GET.get('fmt') == 'json':
      return self.getWithdrawData(request, ap_params, wp_params, kwargs)

    ap_list = lists.getListGenerator(request, ap_params, idx=0)
    wp_list = lists.getListGenerator(request, wp_params, idx=1)

    # fill contents with all the needed lists
    contents = [ap_list, wp_list]

    # call the _list method from base to display the list
    return self._list(request, params, contents, page_name)
Esempio n. 22
0
    def home(self,
             request,
             access_type,
             page_name=None,
             params=None,
             **kwargs):
        """See base.View._public().
    """

        from soc.modules.gci.views.models import task as gci_task_view

        context = {'list': []}

        entity = self._params['logic'].getFromKeyFieldsOr404(kwargs)
        gci_program_entity = entity.scope

        params = params.copy() if params else {}

        is_after_student_signup = timeline_helper.isAfterEvent(
            gci_program_entity.timeline, 'student_signup_start')

        is_after_tasks_become_public = timeline_helper.isAfterEvent(
            gci_program_entity.timeline, 'tasks_publicly_visible')

        if is_after_student_signup and is_after_tasks_become_public:
            list_params = gci_task_view.view.getParams().copy()

            list_params['list_description'] = self.DEF_PROJECTS_MSG_FMT % (
                entity.name)

            if lists.isDataRequest(request):
                return self.getListTasksData(request, list_params, entity)

            content = lists.getListGenerator(request,
                                             list_params,
                                             visibility='home',
                                             idx=0)
            contents = [content]
            context['list'] = soc.logic.lists.Lists(contents)

        params['context'] = context

        return super(View, self).home(request,
                                      'any_access',
                                      page_name=page_name,
                                      params=params,
                                      **kwargs)
Esempio n. 23
0
    def listParticipants(self,
                         request,
                         access_type,
                         page_name=None,
                         params=None,
                         **kwargs):
        """View that lists the roles of all the participants for a single Program.

    For args see base.list().
    """

        from soc.views.models.role import ROLE_VIEWS

        program_logic = params['logic']
        program_entity = program_logic.getFromKeyFieldsOr404(kwargs)

        if lists.isDataRequest(request):
            return self.getListParticipantsData(request, params,
                                                program_entity)

        # we need to generate the lists to be shown on this page
        participants = []

        idx = 0
        for (role_logic, _) in params['participants_logic']:
            # retrieve the role view belonging to the logic
            role_view = ROLE_VIEWS[role_logic.role_name]
            role_params = role_view.getParams().copy()
            role_params['list_description'] = 'List of All %s' % (
                role_params['name_plural'])

            role_list = lists.getListGenerator(request,
                                               role_params,
                                               visibility='admin',
                                               idx=idx)
            participants.append(role_list)

            idx = idx + 1

        page_name = '%s %s' % (page_name, program_entity.name)
        return self._list(request,
                          params,
                          contents=participants,
                          page_name=page_name)
Esempio n. 24
0
  def showDetails(self, request, access_type,
                  page_name=None, params=None, **kwargs):
    """Shows ranking details for the entity specified by **kwargs.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

    logic = params['logic']
    ranking = logic.getFromKeyFieldsOr404(kwargs)
    student = ranking.student

    all_d = gci_task_model.TaskDifficultyTag.all().fetch(100)

    list_params = params.copy()
    list_params['list_description'] = self.DETAILS_MSG_FMT % student.user.name
    list_params['public_field_extra'] = lambda entity: {
        'task': entity.title,
        'org': entity.scope.name,
        'points_difficulty': entity.taskDifficulty(all_d).value
        }
    list_params['public_field_keys'] = [
        'task', 'org', 'points_difficulty', 'closed_on']
    list_params['public_field_names'] = [
        'Task', 'Organization', 'Points (Difficulty)', 'Completed on']
    list_params['public_row_extra'] = lambda entity: {
        'link': redirects.getPublicRedirect(entity, {'url_name': 'gci/task'}),
    }

    if lists.isDataRequest(request):
      return self.getListRankingDetailsData(request, list_params, student)

    contents = []
    order = ['closed_on']
    list = lists.getListGenerator(request, list_params, order=order, idx=0)
    contents.append(list)

    return self._list(request, list_params, contents, page_name)
Esempio n. 25
0
  def home(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """See base.View._public().
    """

    from soc.modules.gsoc.views.models import student_project as \
        student_project_view

    entity = self._logic.getFromKeyFieldsOr404(kwargs)
    program_entity = entity.scope

    params = params.copy() if params else {}

    if timeline_helper.isAfterEvent(program_entity.timeline,
                                    'accepted_students_announced_deadline'):
      # accepted projects
      ap_params = student_project_view.view.getParams().copy()

      ap_params['list_description'] = self.DEF_ACCEPTED_PROJECTS_MSG_FMT % (
          entity.name)

      if lists.isDataRequest(request):
        return self.getHomeData(request, ap_params, entity)

      ap_list = lists.getListGenerator(request, ap_params, idx=0,
                                       visibility='org_home', order=['name'])

      contents = [ap_list]

      extra_context = {}
      # construct the list and put it into the context
      extra_context['list'] = soc.logic.lists.Lists(contents)

      fields= {'scope': entity,
               'status': ['accepted', 'completed']}

      # obtain data to construct the organization map as json object
      extra_context['org_map_data'] = self._getMapData(fields)
      params['context'] = extra_context

    return super(View, self).home(request, 'any_access', page_name=page_name,
                                  params=params, **kwargs)
Esempio n. 26
0
    def list(self,
             request,
             access_type,
             page_name=None,
             params=None,
             filter=None,
             order=None,
             visibility=None,
             context=None,
             **kwargs):
        """Displays the list page for the entity type.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      filter: a dict for the properties that the entities should have

    Params usage:
      The params dictionary is passed as argument to getListContent in
      the soc.views.helper.list module. See the docstring for getListContent
      on how it uses it. The params dictionary is also passed as argument to
      the _list method. See the docstring for _list on how it uses it.
    """

        if lists.isDataRequest(request):
            return self.getListData(request, params, visibility, filter)

        content = lists.getListGenerator(request,
                                         params,
                                         order=order,
                                         visibility=visibility,
                                         idx=0)
        contents = [content]

        return self._list(request,
                          params,
                          contents,
                          page_name,
                          context=context)
Esempio n. 27
0
    def overviewGet(self, request, page_name, params, program_entity,
                    **kwargs):
        """Handles the GET request for the Program Admins overview page.

    Args:
      request: Django HTTPRequest object
      page_name: Name for this page
      params: Params for this view
      program_entity: GSocProgram entity
    """

        page_name = '%s %s' % (page_name, program_entity.name)

        list_params = params.copy()
        list_params['admin_row_extra'] = lambda entity: {
            'link': redirects.getPublicRedirect(entity, list_params)
        }

        list_params['list_description'] = ugettext(
            'An overview of all StudentProjects for %s. Click on an item to view '
            'the project, use the buttons on the list for withdrawing a project.'
            % (program_entity.name))

        if lists.isDataRequest(request):
            return self.getOverviewData(request, list_params, program_entity)

        project_list = lists.getListGenerator(request,
                                              list_params,
                                              idx=0,
                                              visibility='admin')

        # fill contents with the list
        contents = [project_list]

        # call the _list method from base to display the list
        return self._list(request, params, contents, page_name)
Esempio n. 28
0
  def reviewOverview(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """Displays a list of applications that are in a different
    status of the application process.
    """
    survey_logic = params['logic']

    entity = survey_logic.getFromKeyFieldsOr404(kwargs)

    if request.POST:
      # POST request received, check and respond to button actions
      post_dict = request.POST

      if post_dict.get('button_id') == 'bulk_process':
        params['bulk_process_task'].start(entity.scope)

      if post_dict.get('button_id') == 'save_status' and 'data' in request.POST:
        self.processSaveReview(request.POST['data'])

      return http.HttpResponse()

    list_params = params['record_list_params'].copy()
    list_params['list_description'] = (
        'List of all the Organization Applications made to the %s program. '
        'Click an application to review it, or use the buttons on the top of '
        'the list for bulk actions.' %(entity.scope.name))

    info = {'url_name': params['url_name'],
            'survey':entity}
    choices = org_app_record.OrgAppRecord.status.choices
    values = ";".join("%s:%s" % (i, i.capitalize()) for i in choices)

    list_params['overview_field_props'] = {'status': {
        'editable': True,
        'edittype': "select",
        'editoptions': {
            'value': values
        }
    }}

    # define the basic fields for the overview list
    list_params['overview_field_keys'] = [
        'name', 'home_page', 'details', 'status',
    ]
    list_params['overview_field_names'] = [
        'Organization Name', 'Home Page', 'Details', 'Application Status',
    ]
    list_params['overview_field_extra'] = lambda entity: {
        'home_page': lists.urlize(entity.home_page),
        'status': entity.status.capitalize(),
        'details': lists.urlize(
            redirects.getReviewOrgAppSurvey(entity, info), name="[details]"),
    }
    list_params['overview_button_global'] = [
        {
          'bounds': [0,'all'],
          'id': 'bulk_process',
          'caption': 'Bulk Accept/Reject Organizations',
          'type': 'post',
          'parameters': {'url': ''},
        },
        {
          'id': 'save_status',
          'caption': 'Save status',
          'type': 'post_edit',
          'parameters': {
              'url': '',
              'keys': ['key'],
              'refresh': 'current',
          },
        },
    ]

    list_params['overview_row_action'] = {
        "type": "redirect_custom",
        "parameters": dict(new_window=False),
    }

    self._extendListWithSurveyAnswers(list_params, entity, 'overview')

    if lists.isDataRequest(request):
      # get all records for the entity specified in the URL
      fields = {'survey': entity}
      # use the overview visibility to show the correct columns to the Host
      contents = lists.getListData(request, list_params, fields,
                                   visibility='overview')

      return lists.getResponse(request, contents)

    overview_list = lists.getListGenerator(request, list_params,
                                           visibility='overview', idx=0)
    contents = [overview_list]

    return self._list(request, list_params, contents, page_name)
Esempio n. 29
0
    def manage(self,
               request,
               access_type,
               page_name=None,
               params=None,
               **kwargs):
        """View that allows Organization Admins to manage their Student Projects.

    For params see base.View().public()
    """

        import soc.logic.lists

        from soc.modules.gsoc.views.models.grading_project_survey import view as \
            grading_survey_view
        from soc.modules.gsoc.views.models.project_survey import view as \
            project_survey_view

        entity = self._logic.getFromKeyFieldsOr404(kwargs)

        template = params['manage_template']

        # get the context for this webpage
        context = responses.getUniversalContext(request)
        responses.useJavaScript(context, params['js_uses_all'])
        context['page_name'] = "%s '%s' from %s" % (page_name, entity.title,
                                                    entity.student.name())
        context['entity'] = entity

        if project_logic.canChangeMentors(entity):
            # only accepted project can have their mentors managed
            self._enableMentorManagement(entity, params, context)

        # list all surveys for this Project's Program
        gps_params = grading_survey_view.getParams().copy()
        gps_params['list_description'] = \
            'List of all Mentor Evaluations for this Project'
        gps_params['public_row_extra'] = lambda entity, *args: {}
        gps_params['public_row_action'] = {}
        gps_params['public_field_keys'] = [
            "title", "taken_by", "taken_on", "record_url", "take_url"
        ]
        gps_params['public_field_names'] = [
            "Title",
            "Taken by",
            "Taken on",
            "View",
            "(Re) Take",
        ]
        no_record = self.DEF_NO_RECORD_AVAILABLE_MSG

        # TODO(SRabbelier): use buttons instead
        project_entity = entity
        getExtra = lambda params: lambda entity, re: {
            "taken_by":
            no_record if not re(entity) else re(entity).user.name,
            "taken_on":
            no_record if not re(entity) else str(re(entity).modified),
            "record_url":
            no_record if not re(entity) else lists.urlize(
                redirects.getViewSurveyRecordRedirect(re(entity), params),
                name=self.DEF_VIEW_RECORD_MSG),
            "take_url":
            lists.urlize(redirects.getTakeProjectSurveyRedirect(
                project_entity, {
                    'survey': entity,
                    'params': params
                }),
                         name=self.DEF_TAKE_SURVEY_MSG),
        }

        gps_params['public_field_extra'] = getExtra(gps_params)

        # get the ProjectSurvey list
        ps_params = project_survey_view.getParams().copy()
        ps_params['list_description'] = \
            'List of all Student Evaluations for this Project'
        ps_params['public_row_extra'] = lambda entity, *args: {}
        ps_params['public_row_action'] = {}
        ps_params['public_field_keys'] = gps_params['public_field_keys']
        ps_params['public_field_names'] = gps_params['public_field_names']
        ps_params['public_field_ignore'] = ["take_url"]
        ps_params['public_field_extra'] = getExtra(ps_params)

        if lists.isDataRequest(request):
            return self._getManageData(request, gps_params, ps_params, entity)

        gps_list = lists.getListGenerator(request, gps_params, idx=0)
        ps_list = lists.getListGenerator(request, ps_params, idx=1)

        # store both lists in the content
        content = [gps_list, ps_list]

        context['evaluation_list'] = soc.logic.lists.Lists(content)

        if request.POST:
            return self.managePost(request, template, context, params, entity,
                                   **kwargs)
        else:  #request.GET
            return self.manageGet(request, template, context, params, entity,
                                  **kwargs)
Esempio n. 30
0
    def manageOverview(self,
                       request,
                       access_type,
                       page_name=None,
                       params=None,
                       **kwargs):
        """View that allows Organization Admins to see an overview of 
       their Organization's Student Projects.

    For params see base.View().public()
    """

        from soc.modules.gsoc.logic.models.survey import grading_logic as \
            grading_survey_logic
        from soc.modules.gsoc.logic.models.survey import project_logic as \
            project_survey_logic
        from soc.modules.gsoc.logic.models.survey_record import grading_logic
        from soc.modules.gsoc.logic.models.survey_record import project_logic

        # make sure the organization exists
        org_entity = org_logic.getFromKeyNameOr404(kwargs['scope_path'])
        page_name = '%s %s' % (page_name, org_entity.name)

        mo_params = params.copy()

        #list all active projects
        mo_params['list_description'] = ugettext(
            'List of all %s for %s, if you are an Org Admin you can click '
            'a project for more actions. Such as reassigning mentors or viewing '
            'results of the evaluations.' %
            (params['name_plural'], org_entity.name))
        mo_params['public_field_names'] = params['public_field_names'] + [
            'Mentor evaluation', 'Student Evaluation'
        ]
        mo_params['public_field_keys'] = params['public_field_keys'] + [
            'mentor_evaluation', 'student_evaluation'
        ]

        fields = {'scope': org_entity, 'status': ['active', 'inactive']}
        org_admin = org_admin_logic.getForFields(fields, unique=True)

        # Org Admins get a link to manage the project, others go to public page
        if org_admin:
            mo_params['public_row_extra'] = lambda entity, *args: {
                'link': redirects.getManageRedirect(entity, mo_params)
            }
        else:
            mo_params['public_row_extra'] = lambda entity, *args: {
                'link': redirects.getPublicRedirect(entity, mo_params)
            }

        mo_params['public_field_prefetch'] = ['student', 'mentor', 'scope']
        mo_params['public_field_extra'] = lambda entity, ps, psc, gs, gsc: {
            'org':
            entity.scope.name,
            'student':
            '%s (%s)' % (entity.student.name(), entity.student.email),
            'mentor':
            entity.mentor.name(),
            'mentor_evaluation':
            '%d/%d' % (grading_logic.getQueryForFields({
                'project': entity
            }).count(), gsc),
            'student_evaluation':
            '%d/%d' % (project_logic.getQueryForFields({
                'project': entity
            }).count(), psc),
        }

        if lists.isDataRequest(request):
            return self.getManageOverviewData(request, mo_params, org_entity)

        mo_list = lists.getListGenerator(request, mo_params, idx=0)
        contents = [mo_list]

        # call the _list method from base to display the list
        return self._list(request, mo_params, contents, page_name)
Esempio n. 31
0
  def manageOverview(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """View that allows Organization Admins to see an overview of 
       their Organization's Student Projects.

    For params see base.View().public()
    """

    from soc.modules.gsoc.logic.models.survey import grading_logic as \
        grading_survey_logic
    from soc.modules.gsoc.logic.models.survey import project_logic as \
        project_survey_logic
    from soc.modules.gsoc.logic.models.survey_record import grading_logic
    from soc.modules.gsoc.logic.models.survey_record import project_logic

    # make sure the organization exists
    org_entity = org_logic.getFromKeyNameOr404(kwargs['scope_path'])
    page_name = '%s %s' % (page_name, org_entity.name)

    mo_params = params.copy()

    #list all active projects
    mo_params['list_description'] = ugettext(
        'List of all %s for %s, if you are an Org Admin you can click '
        'a project for more actions. Such as reassigning mentors or viewing '
        'results of the evaluations.' %(params['name_plural'], org_entity.name)
        )
    mo_params['public_field_names'] = params['public_field_names'] + [
        'Mentor evaluation', 'Student Evaluation']
    mo_params['public_field_keys'] = params['public_field_keys'] + [
        'mentor_evaluation', 'student_evaluation']

    fields = {'scope': org_entity,
              'status': ['active', 'inactive']}
    org_admin = org_admin_logic.getForFields(fields, unique=True)

    # Org Admins get a link to manage the project, others go to public page
    if org_admin:
      mo_params['public_row_extra'] = lambda entity, *args: {
          'link': redirects.getManageRedirect(entity, mo_params)
      }
    else:
      mo_params['public_row_extra'] = lambda entity, *args: {
          'link': redirects.getPublicRedirect(entity, mo_params)
      }

    mo_params['public_field_prefetch'] = ['student', 'mentor', 'scope']
    mo_params['public_field_extra'] = lambda entity, ps, psc, gs, gsc: {
        'org': entity.scope.name,
        'student': '%s (%s)' % (entity.student.name(), entity.student.email),
        'mentor': entity.mentor.name(),
        'mentor_evaluation': '%d/%d' % (
                grading_logic.getQueryForFields({'project': entity}).count(),
                gsc),
        'student_evaluation': '%d/%d' % (
                project_logic.getQueryForFields({'project': entity}).count(),
                psc),
    }

    if lists.isDataRequest(request):
      return self.getManageOverviewData(request, mo_params, org_entity)

    mo_list = lists.getListGenerator(request, mo_params, idx=0)
    contents = [mo_list]

    # call the _list method from base to display the list
    return self._list(request, mo_params, contents, page_name)
Esempio n. 32
0
  def showRanking(self, request, access_type,
                  page_name=None, params=None, **kwargs):
    """Shows the ranking for the program specified by **kwargs.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

    from soc.modules.gci.views.models.student_ranking import view as ranking_view
    from soc.modules.gci.views.models.student import view as student_view

    sparams = student_view.getParams()

    user_account = user_logic.getCurrentUser()
    user_fields = {
        'user': user_account,
        'status': 'active'
        }
    host_entity = host_logic.getForFields(user_fields, unique=True)
    is_host = host_entity or user_logic.isDeveloper(user=user_account)

    logic = params['logic']
    program = logic.getFromKeyFieldsOr404(kwargs)

    list_params = ranking_view.getParams().copy()

    list_params['list_description'] = self.DEF_LIST_RANKING_MSG_FMT % (
        program.name)

    list_params['public_field_keys'] = ["student", "points", "number"]
    list_params['public_field_names'] = ["Student", "Points", "Number of tasks"]
    list_params['public_conf_extra'] = {
        "rowNum": -1,
        "rowList": [],
        }
    list_params['public_field_prefetch'] = ['student']
    def getExtraFields(entity, *args):
      res = {
          'student': entity.student.user.name,
          'number': len(entity.tasks)
      }
      if is_host:
        fields = sparams['admin_field_keys']
        extra = dicts.toDict(entity.student, fields)
        res.update(extra)
        res['group_name'] = entity.student.scope.name
        res['birth_date'] = entity.student.birth_date.isoformat()
        res['account_name'] = accounts.normalizeAccount(entity.student.user.account).email()
        res['forms_submitted'] = "Yes" if (entity.student.consent_form and entity.student.student_id_form) else "No"
      return res

    list_params['public_field_extra'] = getExtraFields
    list_params['public_row_extra'] = lambda entity, *args: {
        'link': gci_redirects.getShowRankingDetails(entity, list_params)
    }

    list_params['public_field_props'] = {
        'points': {
            'sorttype': 'integer',
        },
        'number': {
            'sorttype': 'integer',
        },
    }
    if is_host:
      list_params['public_field_keys'] += ["forms_submitted"]
      list_params['public_field_names'] += ["Forms submitted"]
      list_params['public_field_hidden'] = sparams['admin_field_hidden'] + sparams['admin_field_keys']
      list_params['public_field_keys'].extend(sparams['admin_field_keys'])
      list_params['public_field_names'].extend(sparams['admin_field_names'])

    ranking_filter = {
        'scope': program
        }

    order = ['-points']

    if lists.isDataRequest(request):
      contents = lists.getListData(request, list_params, ranking_filter)
      return lists.getResponse(request, contents)

    contents = [lists.getListGenerator(
        request, list_params, order=order, idx=0)]

    return self._list(request, list_params, contents=contents,
        page_name=page_name)
Esempio n. 33
0
    def showRanking(self,
                    request,
                    access_type,
                    page_name=None,
                    params=None,
                    **kwargs):
        """Shows the ranking for the program specified by **kwargs.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

        from soc.modules.gci.views.models.student_ranking import view as ranking_view
        from soc.modules.gci.views.models.student import view as student_view

        sparams = student_view.getParams()

        user_account = user_logic.getCurrentUser()
        user_fields = {'user': user_account, 'status': 'active'}
        host_entity = host_logic.getForFields(user_fields, unique=True)
        is_host = host_entity or user_logic.isDeveloper(user=user_account)

        logic = params['logic']
        program = logic.getFromKeyFieldsOr404(kwargs)

        list_params = ranking_view.getParams().copy()

        list_params['list_description'] = self.DEF_LIST_RANKING_MSG_FMT % (
            program.name)

        list_params['public_field_keys'] = ["student", "points", "number"]
        list_params['public_field_names'] = [
            "Student", "Points", "Number of tasks"
        ]
        list_params['public_conf_extra'] = {
            "rowNum": -1,
            "rowList": [],
        }
        list_params['public_field_prefetch'] = ['student']

        def getExtraFields(entity, *args):
            res = {
                'student': entity.student.user.name,
                'number': len(entity.tasks)
            }
            if is_host:
                fields = sparams['admin_field_keys']
                extra = dicts.toDict(entity.student, fields)
                res.update(extra)
                res['group_name'] = entity.student.scope.name
                res['birth_date'] = entity.student.birth_date.isoformat()
                res['account_name'] = accounts.normalizeAccount(
                    entity.student.user.account).email()
                res['forms_submitted'] = "Yes" if (
                    entity.student.consent_form
                    and entity.student.student_id_form) else "No"
            return res

        list_params['public_field_extra'] = getExtraFields
        list_params['public_row_extra'] = lambda entity, *args: {
            'link': gci_redirects.getShowRankingDetails(entity, list_params)
        }

        list_params['public_field_props'] = {
            'points': {
                'sorttype': 'integer',
            },
            'number': {
                'sorttype': 'integer',
            },
        }
        if is_host:
            list_params['public_field_keys'] += ["forms_submitted"]
            list_params['public_field_names'] += ["Forms submitted"]
            list_params['public_field_hidden'] = sparams[
                'admin_field_hidden'] + sparams['admin_field_keys']
            list_params['public_field_keys'].extend(
                sparams['admin_field_keys'])
            list_params['public_field_names'].extend(
                sparams['admin_field_names'])

        ranking_filter = {'scope': program}

        order = ['-points']

        if lists.isDataRequest(request):
            contents = lists.getListData(request, list_params, ranking_filter)
            return lists.getResponse(request, contents)

        contents = [
            lists.getListGenerator(request, list_params, order=order, idx=0)
        ]

        return self._list(request,
                          list_params,
                          contents=contents,
                          page_name=page_name)
Esempio n. 34
0
    def listTasks(self,
                  request,
                  access_type,
                  page_name=None,
                  params=None,
                  **kwargs):
        """View where all the tasks can be searched from.
    """

        from soc.modules.gci.views.models.task import view as task_view

        logic = params['logic']

        program_entity = logic.getFromKeyFieldsOr404(kwargs)

        page_name = '%s %s' % (page_name, program_entity.name)

        list_params = task_view.getParams().copy()

        user_account = user_logic.getCurrentUser()
        user_fields = {'user': user_account, 'status': 'active'}

        host_entity = host_logic.getForFields(user_fields, unique=True)

        tasks_filter = {
            'program': program_entity,
            'status': ['Open', 'Reopened', 'ClaimRequested']
        }

        if host_entity:
            list_params[
                'list_description'] = self.DEF_LIST_VALID_TASKS_MSG_FMT % (
                    program_entity.name)
            tasks_filter['status'].extend([
                'Claimed', 'ActionNeeded', 'Closed', 'AwaitingRegistration',
                'NeedsWork', 'NeedsReview', 'Unapproved', 'Unpublished'
            ])
        else:
            list_params.setdefault('public_field_ignore', []).append('mentors')
            list_params[
                'list_description'] = self.DEF_LIST_PUBLIC_TASKS_MSG_FMT % (
                    program_entity.name)

        list_params['public_row_extra'] = lambda entity, *args: {
            'link': redirects.getPublicRedirect(entity, list_params)
        }

        list_params['public_conf_min_num'] = list_params[
            'public_conf_limit'] = 100

        if lists.isDataRequest(request):
            return self.getListTasksData(request, list_params, tasks_filter)

        contents = []
        order = ['-modified_on']

        tasks_list = lists.getListGenerator(request,
                                            list_params,
                                            order=order,
                                            idx=0)
        contents.append(tasks_list)

        return self._list(request, list_params, contents, page_name)
Esempio n. 35
0
  def manage(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """View that allows Organization Admins to manage their Student Projects.

    For params see base.View().public()
    """

    import soc.logic.lists

    from soc.modules.gsoc.views.models.grading_project_survey import view as \
        grading_survey_view
    from soc.modules.gsoc.views.models.project_survey import view as \
        project_survey_view

    entity = self._logic.getFromKeyFieldsOr404(kwargs)

    template = params['manage_template']

    # get the context for this webpage
    context = responses.getUniversalContext(request)
    responses.useJavaScript(context, params['js_uses_all'])
    context['page_name'] = "%s '%s' from %s" % (page_name, entity.title,
                                                entity.student.name())
    context['entity'] = entity

    if project_logic.canChangeMentors(entity):
      # only accepted project can have their mentors managed
      self._enableMentorManagement(entity, params, context)

    # list all surveys for this Project's Program
    gps_params = grading_survey_view.getParams().copy()
    gps_params['list_description'] = \
        'List of all Mentor Evaluations for this Project'
    gps_params['public_row_extra'] = lambda entity, *args: {}
    gps_params['public_row_action'] = {}
    gps_params['public_field_keys'] = [
        "title", "taken_by", "taken_on", "record_url", "take_url"
    ]
    gps_params['public_field_names'] = [
        "Title", "Taken by", "Taken on", "View", "(Re) Take",
    ]
    no_record = self.DEF_NO_RECORD_AVAILABLE_MSG

    # TODO(SRabbelier): use buttons instead
    project_entity = entity
    getExtra = lambda params: lambda entity, re: {
        "taken_by": no_record if not re(entity) else re(entity).user.name,
        "taken_on": no_record if not re(entity) else str(re(entity).modified),
        "record_url": no_record if not re(entity) else lists.urlize(
            redirects.getViewSurveyRecordRedirect(re(entity), params),
            name=self.DEF_VIEW_RECORD_MSG),
        "take_url": lists.urlize(redirects.getTakeProjectSurveyRedirect(
            project_entity, {'survey': entity, 'params': params}),
            name=self.DEF_TAKE_SURVEY_MSG),
    }

    gps_params['public_field_extra'] = getExtra(gps_params)

    # get the ProjectSurvey list
    ps_params = project_survey_view.getParams().copy()
    ps_params['list_description'] = \
        'List of all Student Evaluations for this Project'
    ps_params['public_row_extra'] = lambda entity, *args: {}
    ps_params['public_row_action'] = {}
    ps_params['public_field_keys'] = gps_params['public_field_keys']
    ps_params['public_field_names'] = gps_params['public_field_names']
    ps_params['public_field_ignore'] = ["take_url"]
    ps_params['public_field_extra'] = getExtra(ps_params)

    if lists.isDataRequest(request):
      return self._getManageData(request, gps_params, ps_params, entity)

    gps_list = lists.getListGenerator(request, gps_params, idx=0)
    ps_list = lists.getListGenerator(request, ps_params, idx=1)

    # store both lists in the content
    content = [gps_list, ps_list]

    context['evaluation_list'] = soc.logic.lists.Lists(content)

    if request.POST:
      return self.managePost(request, template, context, params, entity,
                             **kwargs)
    else: #request.GET
      return self.manageGet(request, template, context, params, entity,
                            **kwargs)
Esempio n. 36
0
    def reviewOverview(self,
                       request,
                       access_type,
                       page_name=None,
                       params=None,
                       **kwargs):
        """Displays a list of applications that are in a different
    status of the application process.
    """
        survey_logic = params['logic']

        entity = survey_logic.getFromKeyFieldsOr404(kwargs)

        if request.POST:
            # POST request received, check and respond to button actions
            post_dict = request.POST

            if post_dict.get('button_id') == 'bulk_process':
                params['bulk_process_task'].start(entity.scope)

            if post_dict.get(
                    'button_id') == 'save_status' and 'data' in request.POST:
                self.processSaveReview(request.POST['data'])

            return http.HttpResponse()

        list_params = params['record_list_params'].copy()
        list_params['list_description'] = (
            'List of all the Organization Applications made to the %s program. '
            'Click an application to review it, or use the buttons on the top of '
            'the list for bulk actions.' % (entity.scope.name))

        info = {'url_name': params['url_name'], 'survey': entity}
        choices = org_app_record.OrgAppRecord.status.choices
        values = ";".join("%s:%s" % (i, i.capitalize()) for i in choices)

        list_params['overview_field_props'] = {
            'status': {
                'editable': True,
                'edittype': "select",
                'editoptions': {
                    'value': values
                }
            }
        }

        # define the basic fields for the overview list
        list_params['overview_field_keys'] = [
            'name',
            'home_page',
            'details',
            'status',
        ]
        list_params['overview_field_names'] = [
            'Organization Name',
            'Home Page',
            'Details',
            'Application Status',
        ]
        list_params['overview_field_extra'] = lambda entity: {
            'home_page':
            lists.urlize(entity.home_page),
            'status':
            entity.status.capitalize(),
            'details':
            lists.urlize(redirects.getReviewOrgAppSurvey(entity, info),
                         name="[details]"),
        }
        list_params['overview_button_global'] = [
            {
                'bounds': [0, 'all'],
                'id': 'bulk_process',
                'caption': 'Bulk Accept/Reject Organizations',
                'type': 'post',
                'parameters': {
                    'url': ''
                },
            },
            {
                'id': 'save_status',
                'caption': 'Save status',
                'type': 'post_edit',
                'parameters': {
                    'url': '',
                    'keys': ['key'],
                    'refresh': 'current',
                },
            },
        ]

        list_params['overview_row_action'] = {
            "type": "redirect_custom",
            "parameters": dict(new_window=False),
        }

        self._extendListWithSurveyAnswers(list_params, entity, 'overview')

        if lists.isDataRequest(request):
            # get all records for the entity specified in the URL
            fields = {'survey': entity}
            # use the overview visibility to show the correct columns to the Host
            contents = lists.getListData(request,
                                         list_params,
                                         fields,
                                         visibility='overview')

            return lists.getResponse(request, contents)

        overview_list = lists.getListGenerator(request,
                                               list_params,
                                               visibility='overview',
                                               idx=0)
        contents = [overview_list]

        return self._list(request, list_params, contents, page_name)