Ejemplo n.º 1
0
def setProjectSurveyInfoForProject(list_content, project_entity,
                                   survey_params):
  """Sets the list info to a function for the given list.
  
  This function contains the information used for showing ProjectSurvey
  records on the StudentProject manage page.

  Args:
    list_content: list content for which to set the info
    project_entity: a StudentProject entity
    survey_params: params for the view of the type of Survey that is listed
  """

  survey_logic = survey_params['logic']
  record_logic = survey_logic.getRecordLogic()

  # store the needed info since Django calls the wrapper method for every
  # info call.
  info_storage = {}

  for survey_entity in list_content['data']:
    # try to retrieve the SurveyRecord for the given Survey and Project
    fields = {'survey': survey_entity,
              'project': project_entity}
    record_entity = record_logic.getForFields(fields, unique=True)

    info = {'record': record_entity}

    if record_entity:
      # SurveyRecord has been found store the import data in info
      info['taken_by'] = record_entity.user.name
      info['taken_on'] = record_entity.modified
      info['record_url'] = redirects.getViewSurveyRecordRedirect(record_entity,
                                                                 survey_params)
    else:
      info['taken_by'] = DEF_NO_RECORD_AVAILABLE_MESSAGE
      info['taken_on'] = DEF_NO_RECORD_AVAILABLE_MESSAGE

    take_redirect_info = {'survey': survey_entity,
                          'params': survey_params}
    info['take_url'] = redirects.getTakeProjectSurveyRedirect(
        project_entity, take_redirect_info)

    info_storage[survey_entity.key()] = info

  def wrapper(item, _):
    """Wrapper method.
    """
    return info_storage[item.key()]

  list_content['info'] = (wrapper, None)
  return list_content
Ejemplo n.º 2
0
def setProjectSurveyInfoForProject(list_content, project_entity,
                                   survey_params):
    """Sets the list info to a function for the given list.
  
  This function contains the information used for showing ProjectSurvey
  records on the StudentProject manage page.

  Args:
    list_content: list content for which to set the info
    project_entity: a StudentProject entity
    survey_params: params for the view of the type of Survey that is listed
  """

    survey_logic = survey_params['logic']
    record_logic = survey_logic.getRecordLogic()

    # store the needed info since Django calls the wrapper method for every
    # info call.
    info_storage = {}

    for survey_entity in list_content['data']:
        # try to retrieve the SurveyRecord for the given Survey and Project
        fields = {'survey': survey_entity, 'project': project_entity}
        record_entity = record_logic.getForFields(fields, unique=True)

        info = {'record': record_entity}

        if record_entity:
            # SurveyRecord has been found store the import data in info
            info['taken_by'] = record_entity.user.name
            info['taken_on'] = record_entity.modified
            info['record_url'] = redirects.getViewSurveyRecordRedirect(
                record_entity, survey_params)
        else:
            info['taken_by'] = DEF_NO_RECORD_AVAILABLE_MESSAGE
            info['taken_on'] = DEF_NO_RECORD_AVAILABLE_MESSAGE

        take_redirect_info = {'survey': survey_entity, 'params': survey_params}
        info['take_url'] = redirects.getTakeProjectSurveyRedirect(
            project_entity, take_redirect_info)

        info_storage[survey_entity.key()] = info

    def wrapper(item, _):
        """Wrapper method.
    """
        return info_storage[item.key()]

    list_content['info'] = (wrapper, None)
    return list_content
Ejemplo n.º 3
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)
Ejemplo 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)
Ejemplo n.º 5
0
                    'user': user_entity
                }, survey_logic)
            allowed_to_read = True
        except:
            pass

        # get the filter for the SurveyRecords
        fields = self._getResultsViewRecordFields(entity, allowed_to_read)

        list_params = params.copy()
        list_params['logic'] = record_logic
        list_params['list_description'] = \
            "List of Records for the %s titled '%s'." %(list_params['name'],
                                                        entity.title)
        list_params['records_row_extra'] = lambda entity: {
            'link': redirects.getViewSurveyRecordRedirect(entity, list_params)
        }
        list_params['records_row_action'] = {
            'type': 'redirect_custom',
            'parameters': dict(new_window=False),
        }

        # add columns for each question
        self._extendListWithSurveyAnswers(list_params, entity, 'records')

        return self.list(request,
                         'allow',
                         page_name=page_name,
                         params=list_params,
                         filter=fields,
                         visibility='records',
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
class View(survey_view.View):
    """View methods for the ProjectSurvey model.
  """
    def __init__(self, params=None):
        """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

    Params:
      params: a dict with params for this View
    """

        new_params = {}
        new_params['logic'] = org_app_logic

        new_params['name'] = "Org Application Survey"
        new_params['url_name'] = 'org_app'

        new_params['extra_dynaexclude'] = ['taking_access']

        new_params['survey_take_form'] = OrgAppSurveyForm
        new_params['survey_record_form'] = OrgAppRecordForm

        new_params['extra_django_patterns'] = [
            (r'^%(url_name)s/(?P<access_type>list_self)/%(key_fields)s$',
             '%(module_package)s.%(module_name)s.list_self',
             'Overview of %(name_plural)s Taken by You'),
        ]

        params = dicts.merge(params, new_params, sub_merge=True)

        super(View, self).__init__(params=params)

    @decorators.check_access
    def create(self,
               request,
               access_type,
               page_name=None,
               params=None,
               **kwargs):
        """Displays the create page for this entity type.

    If an OrgAppSurvey already exists it will redirect to the edit page.
    """

        params = dicts.merge(params, self._params)
        program_view = params['scope_view']
        program_logic = program_view.getParams()['logic']

        program_entity = program_logic.getFromKeyName(kwargs['scope_path'])
        org_app = org_app_logic.getForProgram(program_entity)

        if org_app:
            # redirect to edit page
            return http.HttpResponseRedirect(
                redirects.getEditRedirect(org_app, params))
        else:
            # show create page
            return super(View, self).create(request,
                                            access_type,
                                            page_name=page_name,
                                            params=params,
                                            **kwargs)

    def _getSurveyRecordFor(self, survey, request, params):
        """Returns the SurveyRecord for the given Survey and request.

    This method also take the ID specified as GET param into
    account when querying for the SurveyRecord.

    For params see survey.View._getSurveyRecordFor().
    """

        get_dict = request.GET
        record_id = get_dict.get('id', None)

        survey_logic = params['logic']
        record_logic = survey_logic.getRecordLogic()

        if not record_id or not record_id.isdigit():
            return None
        else:
            return record_logic.getFromIDOr404(int(record_id))

    def _takeGet(self, request, template, context, params, entity, record,
                 **kwargs):
        """Hooking into the view for the take's page GET request.

    For params see survey.View._takeGet().
    """

        # the form action should contain the requested record
        if record:
            context['form_action'] = "?id=%s" % (request.GET['id'])

    def _takePost(self, request, params, entity, record, properties):
        """Hook into the view for the take's page POST request.

    For params see survey.View._takePost().
    """

        from soc.logic.models.user import logic as user_logic

        if not record:
            # creating a new record
            user_entity = user_logic.getForCurrentAccount()
            properties['main_admin'] = user_entity

            if properties['agreed_to_tos']:
                properties['agreed_to_admin_agreement'] = True

        # remove fields we don't need to store in the SurveyRecord
        properties.pop('tos')
        properties.pop('agreed_to_tos')

    def _getRedirectOnSuccessfulTake(self, request, params, survey, record):
        """Returns a path to which the user should be redirected after successfully
    taking a OrgAppSurvey.
    """
        return request.path + '?id=' + str(record.key().id_or_name())

    @decorators.merge_params
    @decorators.check_access
    def list_self(self,
                  request,
                  access_type,
                  page_name=None,
                  params=None,
                  **kwargs):
        """View that lists all the OrgRecords you have access to.

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

        from soc.logic.models.user import logic as user_logic

        survey_logic = params['logic']
        record_logic = survey_logic.getRecordLogic()

        try:
            entity = survey_logic.getFromKeyFieldsOr404(kwargs)
        except out_of_band.Error, error:
            return responses.errorResponse(error,
                                           request,
                                           template=params['error_public'])

        # get the context for this webpage
        context = responses.getUniversalContext(request)
        responses.useJavaScript(context, params['js_uses_all'])
        context['entity'] = entity

        list_contents = []
        user_entity = user_logic.getForCurrentAccount()

        list_params = params.copy()
        list_params['logic'] = record_logic
        list_params[
            'list_heading'] = 'soc/org_app_survey/list/records_heading.html'
        list_params['list_row'] = 'soc/org_app_survey/list/records_row.html'

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

        fields = {'survey': entity, 'main_admin': user_entity}
        list_params['list_description'] = \
            'List of Applications for which you are Main Admin.'
        main_list = lists.getListContent(request,
                                         list_params,
                                         fields,
                                         need_content=True,
                                         idx=0)
        # TODO(LIST)
        if main_list:
            list_contents.append(main_list)

        fields = {'survey': entity, 'backup_admin': user_entity}
        list_params['list_description'] = \
            'List of Applications for which your are Backup Admin.'
        backup_list = lists.getListContent(request,
                                           list_params,
                                           fields,
                                           need_content=True,
                                           idx=1)

        if backup_list:
            list_contents.append(backup_list)

        return self._list(request, list_params, list_contents, page_name,
                          context)
Ejemplo n.º 8
0
           'user': user_entity},
          survey_logic)
      allowed_to_read = True
    except:
      pass

    # get the filter for the SurveyRecords
    fields = self._getResultsViewRecordFields(entity, allowed_to_read)

    list_params = params.copy()
    list_params['logic'] = record_logic
    list_params['list_description'] = \
        "List of Records for the %s titled '%s'." %(list_params['name'],
                                                    entity.title)
    list_params['records_row_extra'] = lambda entity: {
        'link': redirects.getViewSurveyRecordRedirect(entity, list_params)
    }
    list_params['records_row_action'] = {
        'type': 'redirect_custom',
        'parameters': dict(new_window=False),
    }

    # add columns for each question
    self._extendListWithSurveyAnswers(list_params, entity, 'records')

    return self.list(request, 'allow', page_name=page_name,
                     params=list_params, filter=fields, visibility='records',
                     context=context)

  def _getResultsViewRecordFields(self, survey, allowed_to_read):
    """Retrieves the Results View filter for SurveyRecords.
Ejemplo n.º 9
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)