Created
April 11, 2014 15:59
-
-
Save ddemid/10480093 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@login_required | |
def getQuestions(request): | |
if request.method == 'GET': | |
session_hash = request.GET['session_hash'] | |
categories = Category.objects.all() | |
myQuestions = SessionQuestion.objects.filter(session_hash_id=session_hash) | |
questionSessionIds = [] | |
response = {} | |
response['my_questions'] = [] | |
for q in myQuestions: | |
obj = {} | |
obj['question'] = q.question.question | |
print q.question.question | |
obj['id'] = q.question.id | |
obj['category_id'] = q.question.category.id | |
obj['in_set'] = True | |
questionSessionIds.append(q.question.id) | |
response['my_questions'].append(obj) | |
response['category_data'] = [] | |
for c in categories: | |
obj = {} | |
flag = 0 | |
obj['category'] = c.name | |
if c.name == "Custom": | |
flag = 1 | |
else: | |
flag = 1 | |
obj['id'] = c.id | |
obj['questions'] = [] | |
for q in c.question_set.all(): | |
if flag == 1: | |
if q.user == request.user: | |
question = {} | |
question['question'] = q.question | |
question['id'] = q.id | |
question['category_id'] = q.category.id | |
question['in_set'] = q.id in questionSessionIds | |
obj['questions'].append(question) | |
else: | |
question = {} | |
question['question'] = q.question | |
question['id'] = q.id | |
question['category_id'] = q.category.id | |
question['in_set'] = q.id in questionSessionIds | |
obj['questions'].append(question) | |
response['category_data'].append(obj) | |
return HttpResponse(simplejson.dumps(response), content_type="application/json") | |
return HttpResponse('Error') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment