def __init__(self, *args, **kwargs): super(PersonalityTypeForm, self).__init__(*args, **kwargs) # Get statements from JSON data file and convert to Python object data = load_json_data('personality_type_statements.json') # Create fields for each statement # # Each statement is tied to a specific personality type, so name the # fields after the personality type. (i.e. INTP1, INTP2, etc.) i = {} for statement in data: if i.has_key(statement['type']): i[statement['type']] += 1 else: i[statement['type']] = 1 self.fields[statement['type'] + str(i[statement['type']])] = ( forms.ChoiceField(label=statement['statement'], choices=( ('2', 'Strongly Agree'), ('1', 'Agree'), ('-1', 'Disagree'), ('-2', 'Strongly Disagree'), ), widget=forms.RadioSelect) )
def learning_style_results(request, result_id): if not request.user.groups.filter(name__in=['Students', 'Employees']): raise Http403 # Get learning style test results result = LearningStyleResult.objects.get(pk=result_id) # Make sure the logged-in user should have access to these results if (not request.user.groups.filter(name='Employees') and result.student != request.user): raise Http403 # Get description of learning style(s) from JSON data descriptions = [] for style in result.learning_style.split(', '): descriptions.append(load_json_data(os.path.join('learning_styles', '%s.json' % style.lower()))) if request.is_ajax(): template = 'assessments/learning_style_results_ajax.html' else: template = 'assessments/learning_style_results.html' return direct_to_template(request, template, {'result': result, 'descriptions': descriptions})
def personality_type_results(request, result_id): if not request.user.groups.filter(name__in=['Students', 'Employees']): raise Http403 # Get personality type test results result = PersonalityTypeResult.objects.get(pk=result_id) # Make sure the logged-in user should have access to these results if (not request.user.groups.filter(name='Employees') and result.student != request.user): raise Http403 # Get description of personality type from JSON data description = load_json_data(os.path.join('personality_types', '%s.json' % result.personality_type.lower())) if request.is_ajax(): template = 'assessments/personality_type_results_ajax.html' else: template = 'assessments/personality_type_results.html' return direct_to_template(request, template, {'result': result, 'description': description})
def __init__(self, *args, **kwargs): super(LearningStyleForm, self).__init__(*args, **kwargs) # Get questions from JSON data file and convert to Python object data = load_json_data('learning_style_questions.json') # Create fields for each question # # Each question is tied to a specific learning style, so name the # fields after the learning style abbreviation. (i.e. K1, K2, etc.) i = {} for question in data: if i.has_key(question['style']): i[question['style']] += 1 else: i[question['style']] = 1 self.fields[question['style'] + str(i[question['style']])] = ( forms.ChoiceField(label=question['question'], choices=( ('1', 'Yes'), ('0', 'No'), ), widget=forms.RadioSelect) )