Added skeleton view for ProjectSurvey and GradingProjectSurvey.
authorLennard de Rijk <ljvderijk@gmail.com>
Mon, 29 Jun 2009 15:53:50 +0200
changeset 2448 325e08ee9d25
parent 2447 dae6715a2f19
child 2449 8777fd1dc4d4
Added skeleton view for ProjectSurvey and GradingProjectSurvey.
app/soc/views/models/grading_project_survey.py
app/soc/views/models/project_survey.py
app/soc/views/models/survey.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/models/grading_project_survey.py	Mon Jun 29 15:53:50 2009 +0200
@@ -0,0 +1,74 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2009 the Melange authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Views for GradingProjectSurveys.
+"""
+
+__authors__ = [
+  '"Lennard de Rijk" <ljvderijk@gmail.com>',
+  ]
+
+
+from soc.logic import dicts
+from soc.logic.models.survey import grading_logic as grading_survey_logic
+from soc.views.models import project_survey
+
+
+class View(project_survey.View):
+  """View methods for the GradingProjectSurvey model.
+  """
+
+  def __init__(self, params=None):
+    """Defines the fields and methods required for the base View class
+    to provide the user with list, public, create, edit and delete views.
+
+    Params:
+      params: a dict with params for this View
+    """
+
+    rights = access.Checker(params)
+    rights['any_access'] = ['allow']
+    rights['show'] = [('checkIsSurveyReadable', grading_survey_logic)]
+    rights['create'] = ['checkIsUser']
+    rights['edit'] = [('checkIsSurveyWritable', grading_survey_logic)]
+    rights['delete'] = [('checkIsSurveyWritable', grading_survey_logic)]
+    rights['list'] = ['checkDocumentList']
+    rights['pick'] = ['checkDocumentPick']
+
+    new_params = {}
+    new_params['logic'] = grading_survey_logic
+    new_params['rights'] = rights
+
+    new_params['name'] = "Grading Project Survey"
+
+    params = dicts.merge(params, new_params)
+
+    super(View, self).__init__(params=params)
+
+
+view = View()
+
+admin = decorators.view(view.admin)
+create = decorators.view(view.create)
+edit = decorators.view(view.edit)
+delete = decorators.view(view.delete)
+list = decorators.view(view.list)
+public = decorators.view(view.public)
+export = decorators.view(view.export)
+pick = decorators.view(view.pick)
+activate = decorators.view(view.activate)
+results = decorators.view(view.viewResults)
+json = decorators.view(view.exportSerialized)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/views/models/project_survey.py	Mon Jun 29 15:53:50 2009 +0200
@@ -0,0 +1,76 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2009 the Melange authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Views for ProjectSurveys.
+"""
+
+__authors__ = [
+  '"Lennard de Rijk" <ljvderijk@gmail.com>',
+  ]
+
+
+from soc.logic import dicts
+from soc.logic.models.survey import project_logic as project_survey_logic
+from soc.views.models import survey
+
+
+class View(survey.View):
+  """View methods for the ProjectSurvey model.
+  """
+
+  def __init__(self, params=None):
+    """Defines the fields and methods required for the base View class
+    to provide the user with list, public, create, edit and delete views.
+
+    Params:
+      params: a dict with params for this View
+    """
+
+    rights = access.Checker(params)
+    rights['any_access'] = ['allow']
+    rights['show'] = [('checkIsSurveyReadable', project_survey_logic)]
+    rights['create'] = ['checkIsUser']
+    rights['edit'] = [('checkIsSurveyWritable', project_survey_logic)]
+    rights['delete'] = [('checkIsSurveyWritable', project_survey_logic)]
+    rights['list'] = ['checkDocumentList']
+    rights['pick'] = ['checkDocumentPick']
+
+    new_params = {}
+    new_params['logic'] = project_survey_logic
+    new_params['rights'] = rights
+
+    new_params['name'] = "Project Survey"
+
+    new_params['extra_dynaexclude'] = ['prefix', 'taking_access']
+
+    params = dicts.merge(params, new_params)
+
+    super(View, self).__init__(params=params)
+
+
+view = View()
+
+admin = decorators.view(view.admin)
+create = decorators.view(view.create)
+edit = decorators.view(view.edit)
+delete = decorators.view(view.delete)
+list = decorators.view(view.list)
+public = decorators.view(view.public)
+export = decorators.view(view.export)
+pick = decorators.view(view.pick)
+activate = decorators.view(view.activate)
+results = decorators.view(view.viewResults)
+json = decorators.view(view.exportSerialized)
--- a/app/soc/views/models/survey.py	Mon Jun 29 15:44:33 2009 +0200
+++ b/app/soc/views/models/survey.py	Mon Jun 29 15:53:50 2009 +0200
@@ -331,7 +331,6 @@
     rights = self._params['rights']
     can_write = access.Checker.hasMembership(rights, roles, params)
 
-
     not_ready = False
     # check if we're past the start date
     if survey.survey_start and now < survey.survey_start:
@@ -395,19 +394,6 @@
 
     super(View, self)._editContext(request, context)
 
-  def createPost(self, request, context, params):
-
-    # TODO(ajaksu) create new View class for other surveys
-    survey_type = request.POST.get('survey_type')
-    if not survey_type:
-      self._logic = params['logic'] = survey_logic
-    elif survey_type == 'project':
-      self._logic =  params['logic'] = project_logic
-    elif survey_type == 'grading':
-      self._logic = params['logic'] = grading_logic
-
-    return super(View, self).createPost(request, context, params)
-
   def _editPost(self, request, entity, fields):
     """See base.View._editPost().