app/soc/views/models/grading_survey_group.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sun, 12 Jul 2009 16:01:41 +0200
changeset 2612 216002ba6b86
parent 2610 95949d4c45d9
child 2619 04d4494f518d
permissions -rw-r--r--
Added view to GradingSurveyGroup to list all records for a specified group. This view will later be extended with options to start Tasks for collecting the data and processing it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Views for GradingSurveyGroup.
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    21
    '"Daniel Diniz" <ajaksu@gmail.com>',
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
    '"Lennard de Rijk" <ljvderijk@gmail.com>',
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
  ]
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    26
import time
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    27
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    28
from google.appengine.ext.db import djangoforms
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    29
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    30
from django import forms
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    31
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
from soc.logic import dicts
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    33
from soc.logic.models.program import logic as program_logic
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    34
from soc.logic.models.survey import grading_logic
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    35
from soc.logic.models.survey import project_logic
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    36
from soc.logic.models.user import logic as user_logic
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    37
from soc.logic.models.grading_survey_group import logic as survey_group_logic
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    38
from soc.models.grading_survey_group import GradingSurveyGroup
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    39
from soc.models.grading_project_survey import GradingProjectSurvey
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    40
from soc.models.project_survey import ProjectSurvey
2612
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
    41
from soc.views import out_of_band
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
from soc.views.helper import access
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    43
from soc.views.helper import decorators
2612
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
    44
from soc.views.helper import lists
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    45
from soc.views.helper import redirects
2612
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
    46
from soc.views.helper import responses
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
from soc.views.models import base
2610
95949d4c45d9 Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2589
diff changeset
    48
from soc.views.models import program as program_view
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    50
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
class View(base.View):
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
  """View methods for the GradingSurveyGroup model.
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
  """
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
  def __init__(self, params=None):
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
    """Defines the fields and methods required for the base View class
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    57
    to provide the user with list, public, create, edit and delete views.
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    58
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    59
    Params:
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
      params: a dict with params for this View
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
    """
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    63
    rights = access.Checker(params)
2610
95949d4c45d9 Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2589
diff changeset
    64
    rights['create'] = ['checkIsHostForProgramInScope']
95949d4c45d9 Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2589
diff changeset
    65
    rights['edit'] = ['checkIsHostForProgramInScope']
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    rights['delete'] = ['checkIsDeveloper']
2610
95949d4c45d9 Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2589
diff changeset
    67
    rights['show'] = ['checkIsHostForProgramInScope']
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    rights['list'] = ['checkIsDeveloper']
2612
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
    69
    rights['records'] = ['checkIsHostForProgramInScope']
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    70
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
    new_params = {}
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    72
    new_params['logic'] = survey_group_logic
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
    new_params['rights'] = rights
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
    new_params['name'] = "Grading Survey Group"
2586
283bb903b216 Added GradingSurveyGroup to the sitemap and sidebar.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2585
diff changeset
    75
    new_params['sidebar_grouping'] = "Surveys"
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    76
2610
95949d4c45d9 Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2589
diff changeset
    77
    new_params['scope_view'] = program_view
95949d4c45d9 Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2589
diff changeset
    78
    new_params['scope_redirect'] = redirects.getCreateRedirect
95949d4c45d9 Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2589
diff changeset
    79
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    80
    new_params['no_admin'] = True
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    81
    new_params['no_create_with_key_fields'] = True
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    82
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    83
    new_params['create_extra_dynaproperties'] = {
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    84
       'grading_survey': djangoforms.ModelChoiceField(
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    85
            GradingProjectSurvey, required=True),
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    86
       'student_survey': djangoforms.ModelChoiceField(ProjectSurvey,
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    87
                                                      required=False),
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    88
       }
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    89
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    90
    new_params['extra_dynaexclude'] = ['link_id', 'scope', 'scope_path',
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    91
                                       'last_update_started',
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    92
                                       'last_update_complete']
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    93
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    94
    new_params['edit_extra_dynaproperties'] = {
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    95
        'link_id': forms.CharField(widget=forms.HiddenInput),
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    96
        }
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    97
2612
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
    98
    patterns = [
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
    99
        (r'^%(url_name)s/(?P<access_type>records)/%(key_fields)s$',
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   100
        'soc.views.models.%(module_name)s.grading_records',
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   101
        'Overview of GradingRecords'),
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   102
    ]
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   103
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   104
    new_params['extra_django_patterns'] = patterns
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   105
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   106
    new_params['records_template'] = 'soc/grading_survey_group/records.html'
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   107
    new_params['records_heading_template'] = 'soc/grading_record/list/heading.html'
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   108
    new_params['records_row_template'] = 'soc/grading_record/list/row.html'
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   109
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   110
    params = dicts.merge(params, new_params)
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   111
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   112
    super(View, self).__init__(params=params)
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   113
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   114
  @decorators.merge_params
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   115
  @decorators.check_access
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   116
  def create(self, request, access_type,
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   117
             page_name=None, params=None, **kwargs):
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   118
    """Pass the correct survey queries to GroupForm.
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   119
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   120
    For params see base.View.create().
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   121
    """
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   122
2610
95949d4c45d9 Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2589
diff changeset
   123
    if kwargs.get('scope_path'):
95949d4c45d9 Add scope view for GradingSurveyGroup and set access checks.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2589
diff changeset
   124
      self.setQueries(kwargs['scope_path'], params['create_form'])
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   125
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   126
    return super(View, self).create(request, access_type, page_name=page_name,
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   127
                                    params=params, **kwargs)
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   128
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   129
  @decorators.merge_params
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   130
  @decorators.check_access
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   131
  def edit(self, request, access_type,
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   132
           page_name=None, params=None, seed=None, **kwargs):
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   133
    """Pass the correct survey queries to GroupForm.
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   134
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   135
    For params see base.View.edit().
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   136
    """
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   137
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   138
    self.setQueries(kwargs['scope_path'], params['edit_form'])
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   139
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   140
    return super(View, self).edit(request, access_type, page_name=page_name,
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   141
                                  params=params, seed=seed, **kwargs)
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   142
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   143
  def _editGet(self, request, entity, form):
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   144
    """Performs any required processing on the form to get its edit page.
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   145
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   146
    Args:
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   147
      request: the django request object
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   148
      entity: the entity to get
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   149
      form: the django form that will be used for the page
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   150
    """
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   151
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   152
    form.fields['link_id'].initial = entity.link_id
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   153
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   154
    return super(View,self)._editGet(request, entity,form)
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   155
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   156
  def _editPost(self, request, entity, fields):
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   157
    """See base.View._editPost().
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   158
    """
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   159
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   160
    if not entity:
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   161
      # generate a unique link_id
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   162
      fields['link_id'] = 't%i' % (int(time.time()*100))
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   163
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   164
      # TODO: seriously redesign _editPost to pass along kwargs
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   165
      fields['scope_path'] = fields['grading_survey'].scope_path
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   166
    else:
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   167
      fields['link_id'] = entity.link_id
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   168
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   169
    # fill in the scope via call to super
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   170
    return super(View, self)._editPost(request, entity, fields)
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   171
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   172
  def setQueries(self, program_keyname, group_form):
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   173
    """Add program filtering queries to the GroupForm.
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   174
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   175
    Args:
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   176
      program_keyname: keyname of the program to filter on
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   177
      group_form: DynaForm instance to set the queries for
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   178
    """
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   179
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   180
    # fetch the program
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   181
    program = program_logic.getFromKeyNameOr404(program_keyname)
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   182
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   183
    # filter grading surveys by program and use title for display
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   184
    grading_query = grading_logic.getQueryForFields(
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   185
        filter={'scope_path':program_keyname})
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   186
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   187
    # filter project surveys by program and use title for display
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   188
    student_query = project_logic.getQueryForFields(
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   189
        filter={'scope_path':program_keyname})
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   190
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   191
    group_form.base_fields['grading_survey'].query = grading_query
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   192
    group_form.base_fields['student_survey'].query = student_query
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   193
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   194
    # use survey titles in drop-downs
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   195
    self.choiceTitles(group_form, 'grading_survey', grading_logic)
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   196
    self.choiceTitles(group_form, 'student_survey', project_logic)
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   197
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   198
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   199
  def choiceTitles(self, group_form, field, logic):
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   200
    """Fetch entity titles for choice field entries.
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   201
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   202
    Args:
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   203
      group_form: The form to set the choice field entries for
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   204
      field: the field_name to set the choice entries for
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   205
      logic: the logic for the model to set the choice entries for
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   206
    """
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   207
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   208
    # TODO(ajaksu): subclass ModelChoiceField so we don't need this method
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   209
    choice_list = []
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   210
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   211
    model = logic.getModel()
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   212
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   213
    for value, text in tuple(group_form.base_fields[field].choices):
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   214
      if value:
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   215
        entity = model.get(value)
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   216
        text = '%s (%s)' % (entity.title, entity.link_id)
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   217
      choice_list.append((value,text))
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   218
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   219
    choices = tuple(choice_list)
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   220
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   221
    group_form.base_fields[field].choices = choices
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   222
2612
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   223
  @decorators.merge_params
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   224
  @decorators.check_access
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   225
  def gradingRecords(self, request, access_type, page_name=None, params=None,
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   226
                     **kwargs):
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   227
    """View which shows all collected records for a given GradingSurveyGroup.
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   228
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   229
    For args see base.View.public().
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   230
    """
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   231
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   232
    from soc.logic import lists as lists_logic
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   233
    from soc.logic.models.grading_record import logic as record_logic
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   234
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   235
    survey_group_logic = params['logic']
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   236
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   237
    try:
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   238
      entity = survey_group_logic.getFromKeyFieldsOr404(kwargs)
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   239
    except out_of_band.Error, error:
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   240
      return responses.errorResponse(
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   241
          error, request, template=params['error_public'])
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   242
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   243
    template = params['records_template']
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   244
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   245
    list_params = params.copy()
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   246
    list_params['logic'] = record_logic
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   247
    list_params['list_heading'] = params['records_heading_template']
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   248
    list_params['list_row'] = params['records_row_template']
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   249
    # TODO(ljvderijk) proper redirect to edit a record
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   250
    list_params['list_action'] = None
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   251
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   252
    # get the context for this webpage
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   253
    context = responses.getUniversalContext(request)
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   254
    responses.useJavaScript(context, params['js_uses_all'])
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   255
    context['page_name'] = "%s for %s named '%s'" %(
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   256
        page_name, params['name'], entity.name)
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   257
    context['entity'] = entity
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   258
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   259
    fields = {'grading_survey_group': entity}
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   260
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   261
    # list all records with grading_decision set to pass
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   262
    fields['grade_decision'] = 'pass'
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   263
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   264
    # get the list content for passing records
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   265
    pr_params = list_params.copy()
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   266
    pr_params['list_description'] =  \
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   267
        'List of all Records which have their grading outcome set to pass.'
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   268
    pr_list = lists.getListContent(
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   269
        request, pr_params, fields, idx=0)
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   270
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   271
    # list all records with grading_decision set to fail
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   272
    fields['grade_decision'] = 'fail'
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   273
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   274
    # get the list content for all failing records
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   275
    fr_params = list_params.copy()
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   276
    fr_params['list_description'] =  \
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   277
        'List of all Records which have their grading outcome set to fail.'
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   278
    fr_list = lists.getListContent(
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   279
        request, fr_params, fields, idx=1)
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   280
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   281
    # list all records with grading decision set to undecided
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   282
    fields['grade_decision'] = 'undecided'
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   283
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   284
    # get the list content for all undecided records
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   285
    ur_params = list_params.copy()
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   286
    ur_params['list_description'] =  \
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   287
        'List of all Records which have their grading outcome set to undecided.'
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   288
    ur_list = lists.getListContent(
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   289
        request, ur_params, fields, idx=2)
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   290
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   291
    # specify the contents and create a Lists object for use in the context
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   292
    contents = [pr_list, fr_list, ur_list]
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   293
    context['list'] = lists_logic.Lists(contents)
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   294
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   295
    return responses.respond(request, template, context)
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   296
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   297
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   298
view = View()
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   299
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   300
create = decorators.view(view.create)
2612
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   301
delete = decorators.view(view.delete)
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   302
edit = decorators.view(view.edit)
2612
216002ba6b86 Added view to GradingSurveyGroup to list all records for a specified group.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2610
diff changeset
   303
grading_records = decorators.view(view.gradingRecords)
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   304
list = decorators.view(view.list)
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   305
public = decorators.view(view.public)