670 |
670 |
671 @decorators.merge_params |
671 @decorators.merge_params |
672 @decorators.check_access |
672 @decorators.check_access |
673 def viewResults(self, request, access_type, page_name=None, |
673 def viewResults(self, request, access_type, page_name=None, |
674 params=None, **kwargs): |
674 params=None, **kwargs): |
675 """View for SurveyRecords. |
675 """View that will list the survey records. |
676 |
676 |
677 For params see base.View.public(). |
677 For params see base.View.public(). |
678 """ |
678 """ |
679 |
|
680 # TODO(ljvderijk) finish this method |
|
681 return http.HttpResponse("Work In Progress") |
|
682 |
679 |
683 # TODO If read access then show all records, else show only mine + |
680 # TODO If read access then show all records, else show only mine + |
684 # hook for subclasses. On both possibilities. |
681 # hook for subclasses. On both possibilities. |
685 |
682 |
|
683 survey_logic = params['logic'] |
|
684 record_logic = survey_logic.getRecordLogic() |
|
685 |
686 try: |
686 try: |
687 entity = params['logic'].getFromKeyFieldsOr404(kwargs) |
687 entity = survey_logic.getFromKeyFieldsOr404(kwargs) |
688 except out_of_band.Error, error: |
688 except out_of_band.Error, error: |
689 return responses.errorResponse( |
689 return responses.errorResponse( |
690 error, request, template=params['error_public']) |
690 error, request, template=params['error_public']) |
691 |
691 |
692 # get the context for this webpage |
692 # get the context for this webpage |
693 context = responses.getUniversalContext(request) |
693 context = responses.getUniversalContext(request) |
694 responses.useJavaScript(context, params['js_uses_all']) |
694 responses.useJavaScript(context, params['js_uses_all']) |
695 context['page_name'] = "%s titled '%s'" % (page_name, entity.title) |
695 context['page_name'] = "%s titled '%s'" % (page_name, entity.title) |
696 context['entity'] = entity |
696 context['entity'] = entity |
697 |
697 |
698 results_logic = params['logic'].getRecordLogic() |
|
699 |
|
700 # only show truncated preview of first answer |
698 # only show truncated preview of first answer |
701 context['first_question'] = entity.survey_content.orderedProperties()[0] |
699 context['first_question'] = entity.survey_content.orderedProperties()[0] |
702 |
700 |
703 context['record_redirect'] = redirects.getSurveyRecordRedirect( |
|
704 entity, params) |
|
705 |
|
706 filter = {'survey': entity} |
701 filter = {'survey': entity} |
707 |
702 |
708 list_params = params.copy() |
703 list_params = params.copy() |
|
704 list_params['logic'] = record_logic |
|
705 list_params['list_heading'] = 'soc/survey/list/records_heading.html' |
|
706 list_params['list_row'] = 'soc/survey/list/records_row.html' |
709 list_params['list_description'] = \ |
707 list_params['list_description'] = \ |
710 'List of %(name_plural)s.' % list_params |
708 'List of %(name_plural)s.' % list_params |
711 list_params['logic'] = results_logic |
709 list_params['list_action'] = (redirects.getViewSurveyRecordRedirect, |
712 list_params['list_heading'] = 'soc/survey/list/results_heading.html' |
710 list_params) |
713 list_params['list_row'] = 'soc/survey/list/results_row.html' |
|
714 |
711 |
715 record_list = lists.getListContent(request, list_params, filter, idx=0) |
712 record_list = lists.getListContent(request, list_params, filter, idx=0) |
716 |
713 |
717 contents = [record_list] |
714 contents = [record_list] |
718 |
715 |