Added skeleton for the take view and its template.
Also fixed the sorting of imports of the Survey View.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/survey/take.html Wed Jul 01 17:25:54 2009 +0200
@@ -0,0 +1,87 @@
+{% extends "soc/base.html" %}
+{% comment %}
+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.
+{% endcomment %}
+
+{% block scripts %}
+{{ block.super }}
+<script type="text/javascript" src="/soc/content/js/survey-default-text-090627.js"></script>
+<script type="text/javascript" src="/soc/content/survey-take-090627.js"></script>
+<script type="text/javascript" src="/jquery/jquery-growfield.js"></script>
+{% endblock %}
+
+{% block page_title %}
+{{ entity.title }}
+{% endblock %}
+
+{% block header_title %}
+{{ entity.title }}
+{% endblock %}
+
+{% block body %}
+<div id="created">Last modified on {{ entity.modified }} by {{ entity.modified_by.name }}</div>
+
+{% if survey_form %}
+
+ {% load forms_helpers %}
+
+ {% if not read_only %}
+ <form method="post">
+ {% endif %}
+
+ {% if read_only %}
+ <form method="get" onsubmit="javascript:return false">
+ {% endif %}
+
+ {{ help_text }}
+
+<div style="width:100%; float:left;">
+ <div class="{{ status }}" id="survey_widget">
+
+ <table>
+
+ {# Project Selected for this Survey #}
+ {% if project %}
+ <div id="project_link" style="font-size:.8em; margin:3px; display:none;">
+ view project:
+ <a target="_blank" href="/student_project/show/{{ project.key.name }}" >
+ {{ project.title }}
+ </a>
+ </div>
+ {% endif %}
+
+ {% block form_table %}
+ {% as_twoline_table survey_form %}
+ {% endblock %}
+
+ </table>
+ </div> {# end survey_widget #}
+ </div>
+
+<br/><br/>
+ <table>
+ <tbody>
+ <tr>
+ <td>
+ {% if not read_only %}
+ <input type="submit" value="Submit" style="font-weight: bold;"/>
+ {% endif %}
+ </td>
+ </tr>
+ </tbody>
+ </table>
+
+ </form>
+{% endif %}
+
+{% endblock %}
--- a/app/soc/views/models/survey.py Wed Jul 01 16:28:27 2009 +0200
+++ b/app/soc/views/models/survey.py Wed Jul 01 17:25:54 2009 +0200
@@ -28,17 +28,17 @@
import re
import StringIO
import string
+
+from google.appengine.ext import db
+
from django import forms
from django import http
from django.utils import simplejson
-from google.appengine.ext import db
-
-from soc.cache import home
from soc.logic import cleaning
from soc.logic import dicts
+from soc.logic.models.survey import GRADES
from soc.logic.models.survey import logic as survey_logic
-from soc.logic.models.survey import GRADES
from soc.logic.models.user import logic as user_logic
from soc.models.survey import Survey
from soc.models.survey_record import SurveyRecord
@@ -103,6 +103,7 @@
rights['delete'] = ['checkIsDeveloper'] # TODO: fix deletion of Surveys
rights['list'] = ['checkDocumentList']
rights['pick'] = ['checkDocumentPick']
+ rights['take'] = ['checkIsDeveloper'] # TODO(ljvderijk) test proper check
new_params = {}
new_params['logic'] = survey_logic
@@ -112,6 +113,9 @@
new_params['pickable'] = True
new_params['extra_django_patterns'] = [
+ (r'^%(url_name)s/(?P<access_type>take)/%(key_fields)s$',
+ 'soc.views.models.%(module_name)s.take',
+ 'Take %(module_name)s'),
(r'^%(url_name)s/(?P<access_type>json)/%(scope)s$',
'soc.views.models.%(module_name)s.json',
'Export %(name)s as JSON'),
@@ -133,6 +137,7 @@
new_params['edit_template'] = 'soc/survey/edit.html'
new_params['create_template'] = 'soc/survey/edit.html'
+ new_params['take_template'] = 'soc/survey/take.html'
# TODO which one of these are leftovers from Document?
new_params['no_create_raw'] = True
@@ -487,6 +492,62 @@
return super(View, self).editGet(request, entity, context, params=params)
+ @decorators.merge_params
+ @decorators.check_access
+ def take(self, request, access_type, page_name=None,
+ params=None, **kwargs):
+ """View for taking a Survey.
+
+ For Args see base.View().public().
+ """
+
+ try:
+ entity = self._logic.getFromKeyFieldsOr404(kwargs)
+ except out_of_band.Error, error:
+ return responses.errorResponse(
+ error, request, template=params['error_public'])
+
+ template = params['take_template']
+
+ # get the context for this webpage
+ context = responses.getUniversalContext(request)
+ responses.useJavaScript(context, params['js_uses_all'])
+ context['page_name'] = "%s titled '%s'" % (page_name, entity.title)
+ context['entity'] = entity
+
+ if request.POST:
+ return self.takePost(request, template, context, params, entity,
+ **kwargs)
+ else: #request.GET
+ return self.takeGet(request, template, context, params, entity,
+ **kwargs)
+
+ def takeGet(self, request, template, context, params, entity, **kwargs):
+ """Handles the GET request for the Survey's take page.
+
+ Args:
+ template: the template used for this view
+ entity: the student project entity
+ rest: see base.View.public()
+ """
+
+ # TODO(ljvderijk) implement takeGet
+
+ return http.HttpResponse("Work in Progress")
+
+ def takePost(self, request, template, context, params, entity, **kwargs):
+ """Handles the POST request for the Survey's take page.
+
+ Args:
+ template: the template used for this view
+ entity: the student project entity
+ rest: see base.View.public()
+ """
+
+ # TODO(ljvderijk) implement takePost
+
+ return httpHttpResponse("Work in Progress")
+
def activate(self, request, **kwargs):
"""This is a hack to support the 'Enable grades' button.
"""
@@ -787,10 +848,11 @@
admin = decorators.view(view.admin)
create = decorators.view(view.create)
edit = decorators.view(view.edit)
+export = decorators.view(view.export)
delete = decorators.view(view.delete)
+json = decorators.view(view.exportSerialized)
list = decorators.view(view.list)
public = decorators.view(view.public)
-export = decorators.view(view.export)
pick = decorators.view(view.pick)
results = decorators.view(view.viewResults)
-json = decorators.view(view.exportSerialized)
+take = decorators.view(view.take)