<commit_before>#!/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 Surveys.
"""

__authors__ = [
  '"<NAME>" <<EMAIL>>',
  '"<NAME>" <<EMAIL>>',
  '"<NAME>" <<EMAIL>>',
  ]

import datetime
import re
import string

from google.appengine.ext import db

from django import forms
from django import http
from django.utils import simplejson

from soc.logic import cleaning
from soc.logic import dicts
from soc.logic.helper import timeline
from soc.logic.models.survey import logic as survey_logic
from soc.logic.models.user import logic as user_logic
from soc.models.survey import Survey
from soc.models.survey_record import SurveyRecord
from soc.models.user import User
from soc.views import out_of_band
from soc.views.helper import access
from soc.views.helper import decorators
from soc.views.helper import forms as forms_helper
from soc.views.helper import lists
from soc.views.helper import redirects
from soc.views.helper import responses
from soc.views.helper import surveys
from soc.views.helper import widgets
from soc.views.models import base


DEF_CHOICE_TYPES = set(('selection', 'pick_multi', 'choice', 'pick_quant'))
DEF_TEXT_TYPES = set(('long_answer', 'short_answer'))
DEF_PROPERTY_TYPES = tuple(DEF_CHOICE_TYPES) + tuple(DEF_TEXT_TYPES)

# used in View.getSchemaOptions to map POST values
DEF_BOOL = {'True': True, 'False': False}

DEF_SHORT_ANSWER = ("Short Answer",
                    "Less than 40 characters. Rendered as a text input. "
                    "It's possible to add a free form question (Content) "
                    "and a in-input prompt/example text.")
DEF_CHOICE = (
    "Selection",
    "Can be set as a single choice (selection) or multiple choice "
    "(pick_multi) question. Rendered as a select (single choice) "
    "or a group of checkboxes (multiple choice). It's possible to "
    "add a free form question (Content) and as many free form options "
    "as wanted. Each option can be edited (double-click), deleted "
    "(click on (-) button) or reordered (drag and drop).")
DEF_LONG_ANSWER = (
    "Long Answer",
    "Unlimited length, auto-growing field. Rendered as a textarea. "
    "It's possible to add a free form question (Content) and an in-input "
    "prompt/example text.")

DEF_QUESTION_TYPES = dict(short_answer=DEF_SHORT_ANSWER,
                          long_answer=DEF_LONG_ANSWER, choice=DEF_CHOICE)

# for toCSV and View.exportSerialized
DEF_FIELDS = 'author modified_by'
DEF_PLAIN = 'is_featured content created modified'


class View(base.View):
  """View methods for the Survey 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'] = [('checkIsSurveyWritable', survey_logic)]
    rights['create'] = ['checkIsUser']
    rights['edit'] = [('checkIsSurveyWritable', survey_logic)]
    rights['delete'] = ['checkIsDeveloper'] # TODO: fix deletion of Surveys
    rights['list'] = ['checkDocumentList']
    rights['pick'] = ['checkDocumentPick']
    rights['record'] = [('checkHasAny', [
        [('checkIsSurveyReadable', [survey_logic]),
         ('checkIsMySurveyRecord', [survey_logic, 'id'])]
        ])]
    rights['results'] = ['checkIsDeveloper'] # TODO: proper access check
    rights['take'] = [('checkIsSurveyTakeable', survey_logic)]
<commit_msg>Open up the Survey Results view for users.<commit_after>#!/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 Surveys.
"""

__authors__ = [
  '"<NAME>" <<EMAIL>>',
  '"<NAME>" <<EMAIL>>',
  '"<NAME>" <<EMAIL>>',
  ]

import datetime
import re
import string

from google.appengine.ext import db

from django import forms
from django import http
from django.utils import simplejson

from soc.logic import cleaning
from soc.logic import dicts
from soc.logic.helper import timeline
from soc.logic.models.survey import logic as survey_logic
from soc.logic.models.user import logic as user_logic
from soc.models.survey import Survey
from soc.models.survey_record import SurveyRecord
from soc.models.user import User
from soc.views import out_of_band
from soc.views.helper import access
from soc.views.helper import decorators
from soc.views.helper import forms as forms_helper
from soc.views.helper import lists
from soc.views.helper import redirects
from soc.views.helper import responses
from soc.views.helper import surveys
from soc.views.helper import widgets
from soc.views.models import base


DEF_CHOICE_TYPES = set(('selection', 'pick_multi', 'choice', 'pick_quant'))
DEF_TEXT_TYPES = set(('long_answer', 'short_answer'))
DEF_PROPERTY_TYPES = tuple(DEF_CHOICE_TYPES) + tuple(DEF_TEXT_TYPES)

# used in View.getSchemaOptions to map POST values
DEF_BOOL = {'True': True, 'False': False}

DEF_SHORT_ANSWER = ("Short Answer",
                    "Less than 40 characters. Rendered as a text input. "
                    "It's possible to add a free form question (Content) "
                    "and a in-input prompt/example text.")
DEF_CHOICE = (
    "Selection",
    "Can be set as a single choice (selection) or multiple choice "
    "(pick_multi) question. Rendered as a select (single choice) "
    "or a group of checkboxes (multiple choice). It's possible to "
    "add a free form question (Content) and as many free form options "
    "as wanted. Each option can be edited (double-click), deleted "
    "(click on (-) button) or reordered (drag and drop).")
DEF_LONG_ANSWER = (
    "Long Answer",
    "Unlimited length, auto-growing field. Rendered as a textarea. "
    "It's possible to add a free form question (Content) and an in-input "
    "prompt/example text.")

DEF_QUESTION_TYPES = dict(short_answer=DEF_SHORT_ANSWER,
                          long_answer=DEF_LONG_ANSWER, choice=DEF_CHOICE)

# for toCSV and View.exportSerialized
DEF_FIELDS = 'author modified_by'
DEF_PLAIN = 'is_featured content created modified'


class View(base.View):
  """View methods for the Survey 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'] = [('checkIsSurveyWritable', survey_logic)]
    rights['create'] = ['checkIsUser']
    rights['edit'] = [('checkIsSurveyWritable', survey_logic)]
    rights['delete'] = ['checkIsDeveloper'] # TODO: fix deletion of Surveys
    rights['list'] = ['checkDocumentList']
    rights['pick'] = ['checkDocumentPick']
    rights['record'] = [('checkHasAny', [
        [('checkIsSurveyReadable', [survey_logic]),
         ('checkIsMySurveyRecord', [survey_logic, 'id'])]
        ])]
    rights['results'] = ['checkIsUser']
    rights['take'] = [('checkIsSurveyTakeable', survey_logic)]

{'fraction_non_alphanumeric': 0.1062866927592955, 'fraction_numerical': 0.0029354207436399216, 'mean_word_length': 3.979902557856273, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2621065', 'n_tokens_mistral': 2456, 'n_tokens_neox': 2363, 'n_words': 855}