app/soc/views/models/grading_survey_group.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sat, 11 Jul 2009 23:29:22 +0200
changeset 2598 59ebf718c6a4
parent 2589 2ecd4df2c9c7
child 2610 95949d4c45d9
permissions -rw-r--r--
Changed URL pattern for starting sending out survey reminders.
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
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
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
    42
from soc.views.helper import decorators
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    43
from soc.views.helper import redirects
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
from soc.views.models import base
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    46
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
class View(base.View):
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
  """View methods for the GradingSurveyGroup model.
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
  """
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
  def __init__(self, params=None):
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
    """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
    53
    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
    54
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    55
    Params:
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    56
      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
    57
    """
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
    rights = access.Checker(params)
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    60
    rights['create'] = ['checkIsDeveloper']
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    61
    rights['edit'] = ['checkIsDeveloper']
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    62
    rights['delete'] = ['checkIsDeveloper']
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    63
    rights['show'] = ['checkIsDeveloper']
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    64
    rights['list'] = ['checkIsDeveloper']
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    65
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    66
    new_params = {}
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    67
    new_params['logic'] = survey_group_logic
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    68
    new_params['rights'] = rights
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    69
    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
    70
    new_params['sidebar_grouping'] = "Surveys"
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    71
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    72
    new_params['no_admin'] = True
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    73
    new_params['no_create_raw'] = True
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
    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
    75
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    76
    new_params['create_extra_dynaproperties'] = {
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    77
       'grading_survey': djangoforms.ModelChoiceField(
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    78
            GradingProjectSurvey, required=True),
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    79
       'student_survey': djangoforms.ModelChoiceField(ProjectSurvey,
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    80
                                                      required=False),
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    81
       }
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    82
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    83
    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
    84
                                       'last_update_started',
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    85
                                       'last_update_complete']
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    86
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    87
    new_params['edit_extra_dynaproperties'] = {
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
    88
        '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
    89
        }
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    90
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    91
    params = dicts.merge(params, new_params)
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    92
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    93
    super(View, self).__init__(params=params)
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    94
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    95
  @decorators.merge_params
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    96
  @decorators.check_access
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    97
  def create(self, request, access_type,
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    98
             page_name=None, params=None, **kwargs):
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
    99
    """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
   100
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   101
    For params see base.View.create().
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   102
    """
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   103
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   104
    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
   105
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   106
    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
   107
                                    params=params, **kwargs)
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   108
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   109
  @decorators.merge_params
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   110
  @decorators.check_access
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   111
  def edit(self, request, access_type,
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   112
           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
   113
    """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
   114
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   115
    For params see base.View.edit().
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   116
    """
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   117
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   118
    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
   119
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   120
    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
   121
                                  params=params, seed=seed, **kwargs)
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   122
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   123
  def _editGet(self, request, entity, form):
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   124
    """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
   125
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   126
    Args:
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   127
      request: the django request object
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   128
      entity: the entity to get
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   129
      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
   130
    """
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   131
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   132
    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
   133
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   134
    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
   135
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   136
  def _editPost(self, request, entity, fields):
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   137
    """See base.View._editPost().
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   138
    """
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
    if not entity:
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   141
      # generate a unique link_id
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   142
      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
   143
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   144
      # 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
   145
      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
   146
    else:
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   147
      fields['link_id'] = entity.link_id
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   148
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   149
    # 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
   150
    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
   151
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   152
  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
   153
    """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
   154
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   155
    Args:
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   156
      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
   157
      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
   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
    # fetch the program
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   161
    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
   162
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   163
    # 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
   164
    grading_query = grading_logic.getQueryForFields(
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   165
        filter={'scope_path':program_keyname})
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   166
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   167
    # 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
   168
    student_query = project_logic.getQueryForFields(
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   169
        filter={'scope_path':program_keyname})
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   170
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   171
    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
   172
    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
   173
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   174
    # use survey titles in drop-downs
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   175
    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
   176
    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
   177
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   178
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   179
  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
   180
    """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
   181
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   182
    Args:
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   183
      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
   184
      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
   185
      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
   186
    """
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   187
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   188
    # 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
   189
    choice_list = []
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   190
2589
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   191
    model = logic.getModel()
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   192
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   193
    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
   194
      if value:
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   195
        entity = model.get(value)
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   196
        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
   197
      choice_list.append((value,text))
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
    choices = tuple(choice_list)
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   200
2ecd4df2c9c7 GradingSurveyGroup now uses DynaForm for its forms.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2586
diff changeset
   201
    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
   202
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   203
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   204
view = View()
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   205
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   206
create = decorators.view(view.create)
2585
37584af2420e Completed the Create and Edit view for GradingSurveyGroup.
Daniel Diniz <ajaksu@gmail.com>
parents: 2580
diff changeset
   207
edit = decorators.view(view.edit)
2580
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   208
delete = decorators.view(view.delete)
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   209
list = decorators.view(view.list)
cd3b42f52b21 Added skeleton view and templates for GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   210
public = decorators.view(view.public)