# HG changeset patch # User Daniel Diniz # Date 1247128770 -7200 # Node ID 7a1138f8a0e295214cbbd7e3266bc614a1d500de # Parent e319fd52cbc4ef0435585436b6b60c95997cb127 Removed results list from Survey edit. Some changes to the Survey Result page have also been made, however the results viewer and the CSV export are not working properly in that View. Reviewd by: Lennard de Rijk diff -r e319fd52cbc4 -r 7a1138f8a0e2 app/soc/templates/soc/survey/edit.html --- a/app/soc/templates/soc/survey/edit.html Thu Jul 09 10:16:29 2009 +0200 +++ b/app/soc/templates/soc/survey/edit.html Thu Jul 09 10:39:30 2009 +0200 @@ -194,11 +194,4 @@

- - {% if not new_survey %} - {% if survey_records %} - {{ survey_records|safe }} - {% endif %} - {% endif %} - {% endblock %} diff -r e319fd52cbc4 -r 7a1138f8a0e2 app/soc/templates/soc/survey/results.html --- a/app/soc/templates/soc/survey/results.html Thu Jul 09 10:16:29 2009 +0200 +++ b/app/soc/templates/soc/survey/results.html Thu Jul 09 10:39:30 2009 +0200 @@ -1,6 +1,3 @@ -{% if grades %} -
-{% endif %} {% if list_msg %} {{ list_msg|safe }} {% endif %} @@ -14,8 +11,3 @@ {% include list.nextList %}

{% endfor %} - -{% if grades %} - -
-{% endif %} diff -r e319fd52cbc4 -r 7a1138f8a0e2 app/soc/views/helper/surveys.py --- a/app/soc/views/helper/surveys.py Thu Jul 09 10:16:29 2009 +0200 +++ b/app/soc/views/helper/surveys.py Thu Jul 09 10:39:30 2009 +0200 @@ -930,71 +930,6 @@ 'quant_radio': PickQuantRadio} -class SurveyResults(widgets.Widget): - """Render List of Survey Results For Given Survey. - """ - - def render(self, survey, params, filter=filter, limit=1000, offset=0, - order=[], idx=0, context={}): - """ renders list of survey results - - params: - survey: current survey - params: dict of params for rendering list - filter: filter for list results - limit: limit for list results - offset: offset for list results - order: order for list results - idx: index for list results - context: context dict for template - """ - - survey_logic = params['logic'] - record_logic = survey_logic.getRecordLogic() - filter = {'survey': survey} - data = record_logic.getForFields(filter=filter, limit=limit, offset=offset, - order=order) - - params['name'] = "Survey Results" - content = { - 'idx': idx, - 'data': data, - 'logic': record_logic, - 'limit': limit, - } - updates = dicts.rename(params, params['list_params']) - content.update(updates) - contents = [content] - - if len(content) == 1: - content = content[0] - key_order = content.get('key_order') - - context['list'] = Lists(contents) - - # TODO(ajaksu) is this the best way to build the results list? - for list_ in context['list']._contents: - if len(list_['data']) < 1: - return "

No Survey Results Have Been Submitted

" - - list_['row'] = 'soc/survey/list/results_row.html' - list_['heading'] = 'soc/survey/list/results_heading.html' - list_['description'] = 'Survey Results:' - - context['properties'] = survey.survey_content.orderedProperties() - context['entity_type'] = "Survey Results" - context['entity_type_plural'] = "Results" - context['no_lists_msg'] = "No Survey Results" - - path = (survey.entity_type().lower(), survey.prefix, - survey.scope_path, survey.link_id) - context['grade_action'] = "/%s/grade/%s/%s/%s" % path - - markup = loader.render_to_string('soc/survey/results.html', - dictionary=context).strip('\n') - return markup - - class HelperForm(object): """Thin wrapper for adding values to params['edit_form'].fields. """ diff -r e319fd52cbc4 -r 7a1138f8a0e2 app/soc/views/models/grading_project_survey.py --- a/app/soc/views/models/grading_project_survey.py Thu Jul 09 10:16:29 2009 +0200 +++ b/app/soc/views/models/grading_project_survey.py Thu Jul 09 10:39:30 2009 +0200 @@ -55,6 +55,7 @@ rights['edit'] = [('checkIsSurveyWritable', grading_survey_logic)] rights['delete'] = ['checkIsDeveloper'] # TODO: fix deletion of Surveys rights['list'] = ['checkDocumentList'] + rights['results'] = [('checkIsSurveyWritable', grading_survey_logic)] rights['take'] = [('checkIsSurveyTakeable', grading_survey_logic), ('checkIsAllowedToTakeProjectSurveyAs', [grading_survey_logic, 'mentor', 'project'])] @@ -232,4 +233,5 @@ delete = decorators.view(view.delete) list = decorators.view(view.list) public = decorators.view(view.public) +results = decorators.view(view.viewResults) take = decorators.view(view.take) diff -r e319fd52cbc4 -r 7a1138f8a0e2 app/soc/views/models/project_survey.py --- a/app/soc/views/models/project_survey.py Thu Jul 09 10:16:29 2009 +0200 +++ b/app/soc/views/models/project_survey.py Thu Jul 09 10:39:30 2009 +0200 @@ -53,11 +53,11 @@ rights['edit'] = [('checkIsSurveyWritable', project_survey_logic)] rights['delete'] = ['checkIsDeveloper'] # TODO: fix deletion of Surveys rights['list'] = ['checkDocumentList'] + rights['results'] = [('checkIsSurveyWritable', project_survey_logic)] rights['take'] = [('checkIsSurveyTakeable', project_survey_logic), ('checkIsAllowedToTakeProjectSurveyAs', [project_survey_logic, 'student', 'project'])] - new_params = {} new_params['logic'] = project_survey_logic new_params['rights'] = rights @@ -218,4 +218,5 @@ delete = decorators.view(view.delete) list = decorators.view(view.list) public = decorators.view(view.public) +results = decorators.view(view.viewResults) take = decorators.view(view.take) diff -r e319fd52cbc4 -r 7a1138f8a0e2 app/soc/views/models/survey.py --- a/app/soc/views/models/survey.py Thu Jul 09 10:16:29 2009 +0200 +++ b/app/soc/views/models/survey.py Thu Jul 09 10:39:30 2009 +0200 @@ -45,6 +45,7 @@ from soc.views.helper import access from soc.views.helper import decorators from soc.views.helper import forms as forms_helper +from soc.views.helper import lists from soc.views.helper import redirects from soc.views.helper import responses from soc.views.helper import surveys @@ -102,6 +103,7 @@ rights['delete'] = ['checkIsDeveloper'] # TODO: fix deletion of Surveys rights['list'] = ['checkDocumentList'] rights['pick'] = ['checkDocumentPick'] + rights['results'] = [('checkIsSurveyWritable', survey_logic)] rights['take'] = [('checkIsSurveyTakeable', survey_logic)] new_params = {} @@ -118,7 +120,7 @@ (r'^%(url_name)s/(?Pjson)/%(scope)s$', 'soc.views.models.%(module_name)s.json', 'Export %(name)s as JSON'), - (r'^%(url_name)s/(?Presults)/%(scope)s$', + (r'^%(url_name)s/(?Presults)/%(key_fields)s$', 'soc.views.models.%(module_name)s.results', 'View survey results for %(name)s'), (r'^%(url_name)s/(?Pshow)/user/(?P)\w+$', @@ -216,28 +218,6 @@ # return True to signal that the page may be displayed return True - def _editContext(self, request, context): - """Performs any required processing on the context for edit pages. - - Args: - request: the django request object - context: the context dictionary that will be used - - Adds list of SurveyRecord results as supplement to view. - - See surveys.SurveyResults for details. - """ - - if not getattr(self, '_entity', None): - return - - results = surveys.SurveyResults() - - context['survey_records'] = results.render(self._entity, self._params, - filter={}) - - super(View, self)._editContext(request, context) - def _editPost(self, request, entity, fields): """See base.View._editPost(). @@ -696,63 +676,52 @@ @decorators.check_access def viewResults(self, request, access_type, page_name=None, params=None, **kwargs): - """View for SurveyRecord and SurveyRecordGroup. + """View for SurveyRecords. + + For params see base.View.public(). """ - results_logic = params['logic'].getRecordLogic() + survey_logic = params['logic'] + + 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['page_name'] = "%s titled '%s'" % (page_name, entity.title) + context['entity'] = entity + + results_logic = survey_logic.getRecordLogic() user = user_logic.getForCurrentAccount() - # TODO(ajaksu) use the named parameter link_id from the re - if request.path == '/survey/show/user/' + user.link_id: - records = tuple(user.surveys_taken.run()) - context = responses.getUniversalContext(request) - context['content'] = records[0].survey.survey_content - responses.useJavaScript(context, params['js_uses_all']) - context['page_name'] = u'Your survey records.' - else: - entity, context = self.getContextEntity(request, page_name, - params, kwargs) + context['properties'] = entity.survey_content.orderedProperties() + + filter = self._params.get('filter') or {} + + filter['survey'] = entity + + list_params = params.copy() + list_params['list_description'] = \ + 'List of %(name_plural)s.' % list_params + + list_params['logic'] = results_logic - if context is None: - # user cannot see this page, return error response - return entity - context['content'] = entity.survey_content - can_write = False - rights = self._params['rights'] - try: - rights.checkIsSurveyWritable({'key_name': entity.key().name(), - 'prefix': entity.prefix, - 'scope_path': entity.scope_path, - 'link_id': entity.link_id,}, - 'key_name') - can_write = True - except out_of_band.AccessViolation: - pass + valid_list = lists.getListContent(request, list_params, filter, idx=0) - filter = self._params.get('filter') or {} + valid_list['row'] = 'soc/survey/list/results_row.html' + valid_list['heading'] = 'soc/survey/list/results_heading.html' + valid_list['description'] = 'Survey Results:' - # if user can edit the survey, show everyone's results - if can_write: - filter['survey'] = entity - else: - filter.update({'user': user, 'survey': entity}) - - limit = self._params.get('limit') or 1000 - offset = self._params.get('offset') or 0 - order = self._params.get('order') or [] - idx = self._params.get('idx') or 0 + contents = [] + # fill contents with all the needed lists + contents.append(valid_list) - records = results_logic.getForFields(filter=filter, limit=limit, - offset=offset, order=order) - - updates = dicts.rename(params, params['list_params']) - context.update(updates) - - context['results'] = records, records - - template = 'soc/survey/results_page.html' - return responses.respond(request, template, context=context) + return self._list(request, list_params, contents, page_name, context) @decorators.merge_params @decorators.check_access