def named_lists_submit(user, post): lexForm = LexiconForm(post) timeForm = TimeForm(post) nlForm = NamedListForm(post) num_q_form = NumQuestionsForm(post) if not (lexForm.is_valid() and timeForm.is_valid() and nlForm.is_valid() and num_q_form.is_valid()): return response({'success': False, 'error': _('Please check that you have selected a ' 'list and that your quiz time is greater ' 'than 1 minute.')}) lex = Lexicon.objects.get( lexiconName=lexForm.cleaned_data['lexicon']) quizTime = int( round(timeForm.cleaned_data['quizTime'] * 60)) wwg = WordwallsGame() questions_per_round = num_q_form.cleaned_data['num_questions'] tablenum = wwg.initialize_by_named_list( lex, user, nlForm.cleaned_data['namedList'], quizTime, questions_per_round) if tablenum == 0: raise Http404 return response({'url': reverse('wordwalls_table', args=(tablenum,)), 'success': True})
def named_lists_submit(user, post): lexForm = LexiconForm(post) timeForm = TimeForm(post) nlForm = NamedListForm(post) if not (lexForm.is_valid() and timeForm.is_valid() and nlForm.is_valid()): return response({ 'success': False, 'error': 'Please check that you have selected a ' 'list and that your quiz time is greater ' 'than 1 minute.' }) lex = Lexicon.objects.get(lexiconName=lexForm.cleaned_data['lexicon']) quizTime = int(round(timeForm.cleaned_data['quizTime'] * 60)) wwg = WordwallsGame() tablenum = wwg.initializeByNamedList(lex, user, nlForm.cleaned_data['namedList'], quizTime) if tablenum == 0: raise Http404 return response({ 'url': reverse('wordwalls_table', args=(tablenum, )), 'success': True })
def createQuiz(request): if request.method == 'GET': return render(request, 'whitleyCards/index.html', {'accessedWithGet': True}) elif request.method == 'POST': action = request.POST.get('action') if action == 'searchParamsFlashcard': lexForm = LexiconForm(request.POST) # form bound to the POST data fwForm = FindWordsForm(request.POST) if lexForm.is_valid() and fwForm.is_valid(): lex = Lexicon.objects.get( lexiconName=lexForm.cleaned_data['lexicon']) asd = searchForAlphagrams(fwForm.cleaned_data, lex) return response({ 'url': reverse('flashcards_by_prob_range', args=(asd['lexicon'].pk, asd['length'], asd['min'], asd['max'])), 'success': True}) elif action == 'namedListsFlashcard': lexForm = LexiconForm(request.POST) nlForm = NamedListForm(request.POST) if lexForm.is_valid() and nlForm.is_valid(): lex = Lexicon.objects.get( lexiconName=lexForm.cleaned_data['lexicon']) # lex doesn't matter return response({ 'url': reverse( 'flashcards_by_namedList_pk', args=(nlForm.cleaned_data['namedList'].pk,)), 'success': True}) elif (action == 'savedListsFlashcardEntire' or action == 'savedListsFlashcardFM'): lexForm = LexiconForm(request.POST) slForm = SavedListForm(request.POST) if lexForm.is_valid() and slForm.is_valid(): lex = Lexicon.objects.get( lexiconName=lexForm.cleaned_data['lexicon']) # lex doesn't matter if request.POST['action'] == 'savedListsFlashcardEntire': option = SavedListForm.RESTART_LIST_CHOICE elif request.POST['action'] == 'savedListsFlashcardFM': option = SavedListForm.FIRST_MISSED_CHOICE return response({ 'url': reverse('flashcards_by_savedList_pk', args=(slForm.cleaned_data['wordList'].pk, option)), 'success': True}) # don't do any checking right now for user access to # other user lists. why? maybe people can share lists # this way as long as we're not letting the users delete # lists, i think it should be fine. return response({'success': False, 'error': 'Did you select a list to flashcard?'}, status=400)
def handle_create_post(request): action = request.POST.get('action') if action == 'searchParamsFlashcard': # form bound to the POST data lexForm = LexiconForm(request.POST) if lexForm.is_valid(): lex = Lexicon.objects.get( lexiconName=lexForm.cleaned_data['lexicon']) logger.debug('POST data %s', request.POST) try: encoded_search = search_criteria_to_b64(request.POST) except ImproperCodingException: return response( { 'success': False, 'error': 'Please refresh; the app has changed.' }, status=400) return response({ 'url': reverse('flashcards_by_search', args=(lex.pk, encoded_search.decode())), 'success': True }) elif action == 'namedListsFlashcard': lexForm = LexiconForm(request.POST) nlForm = NamedListForm(request.POST) if lexForm.is_valid() and nlForm.is_valid(): lex = Lexicon.objects.get( lexiconName=lexForm.cleaned_data['lexicon']) # lex doesn't matter return response({ 'url': reverse('flashcards_by_namedList_pk', args=(nlForm.cleaned_data['namedList'].pk, )), 'success': True }) elif (action == 'savedListsFlashcardEntire' or action == 'savedListsFlashcardFM'): lexForm = LexiconForm(request.POST) slForm = SavedListForm(request.POST) if lexForm.is_valid() and slForm.is_valid(): lex = Lexicon.objects.get( lexiconName=lexForm.cleaned_data['lexicon']) # lex doesn't matter if request.POST['action'] == 'savedListsFlashcardEntire': option = SavedListForm.RESTART_LIST_CHOICE elif request.POST['action'] == 'savedListsFlashcardFM': option = SavedListForm.FIRST_MISSED_CHOICE return response({ 'url': reverse('flashcards_by_savedList_pk', args=(slForm.cleaned_data['wordList'].pk, option)), 'success': True }) # don't do any checking right now for user access to # other user lists. why? maybe people can share lists # this way as long as we're not letting the users delete # lists, i think it should be fine. return response( { 'success': False, 'error': 'Did you select a list to flashcard?' }, status=400)
def createQuiz(request): if request.method == 'GET': return render_to_response('whitleyCards/index.html', {'accessedWithGet': True }, context_instance=RequestContext(request)) elif request.method == 'POST': action = request.POST.get('action') if action == 'searchParamsFlashcard': lexForm = LexiconForm(request.POST) fwForm = FindWordsForm(request.POST) # form bound to the POST data if lexForm.is_valid() and fwForm.is_valid(): lex = Lexicon.objects.get(lexiconName=lexForm.cleaned_data['lexicon']) asd = searchForAlphagrams(fwForm.cleaned_data, lex) #questionData = getWordDataByProb(alphasSearchDescription['min'], alphasSearchDescription['max']) response = HttpResponse(json.dumps( {'url': reverse('flashcards_by_prob_pk_range', args=(asd['min'], asd['max'])), 'success': True} ), mimetype="application/javascript") response['Content-Type'] = 'text/plain; charset=utf-8' return response elif action == 'namedListsFlashcard': lexForm = LexiconForm(request.POST) nlForm = NamedListForm(request.POST) if lexForm.is_valid() and nlForm.is_valid(): lex = Lexicon.objects.get(lexiconName=lexForm.cleaned_data['lexicon']) # lex doesn't matter response = HttpResponse(json.dumps( {'url': reverse('flashcards_by_namedList_pk', args=(nlForm.cleaned_data['namedList'].pk,)), 'success': True} ), mimetype="application/javascript") response['Content-Type'] = 'text/plain; charset=utf-8' return response elif action == 'savedListsFlashcardEntire' or action == 'savedListsFlashcardFM': lexForm = LexiconForm(request.POST) slForm = SavedListForm(request.POST) if lexForm.is_valid() and slForm.is_valid(): lex = Lexicon.objects.get(lexiconName=lexForm.cleaned_data['lexicon']) # lex doesn't matter if request.POST['action'] == 'savedListsFlashcardEntire': option = SavedListForm.RESTART_LIST_CHOICE elif request.POST['action'] == 'savedListsFlashcardFM': option = SavedListForm.FIRST_MISSED_CHOICE response = HttpResponse(json.dumps( {'url': reverse('flashcards_by_savedList_pk', args=(slForm.cleaned_data['wordList'].pk, option)), 'success': True} ), mimetype="application/javascript") response['Content-Type'] = 'text/plain; charset=utf-8' return response # don't do any checking right now for user access to other user lists. why? maybe people can share lists this way # as long as we're not letting the users delete lists, i think it should be fine. response = HttpResponse(json.dumps({'success': False, 'error': 'Did you select a list to ' 'flashcard?'}), mimetype="application/javascript") response['Content-Type'] = 'text/plain; charset=utf-8' return response
def createQuiz(request): if request.method == 'GET': return render_to_response('whitleyCards/index.html', {'accessedWithGet': True}, context_instance=RequestContext(request)) elif request.method == 'POST': action = request.POST.get('action') if action == 'searchParamsFlashcard': lexForm = LexiconForm(request.POST) fwForm = FindWordsForm(request.POST) # form bound to the POST data if lexForm.is_valid() and fwForm.is_valid(): lex = Lexicon.objects.get( lexiconName=lexForm.cleaned_data['lexicon']) asd = searchForAlphagrams(fwForm.cleaned_data, lex) #questionData = getWordDataByProb(alphasSearchDescription['min'], alphasSearchDescription['max']) response = HttpResponse(json.dumps({ 'url': reverse('flashcards_by_prob_pk_range', args=(asd['min'], asd['max'])), 'success': True }), mimetype="application/javascript") response['Content-Type'] = 'text/plain; charset=utf-8' return response elif action == 'namedListsFlashcard': lexForm = LexiconForm(request.POST) nlForm = NamedListForm(request.POST) if lexForm.is_valid() and nlForm.is_valid(): lex = Lexicon.objects.get( lexiconName=lexForm.cleaned_data['lexicon']) # lex doesn't matter response = HttpResponse(json.dumps({ 'url': reverse('flashcards_by_namedList_pk', args=(nlForm.cleaned_data['namedList'].pk, )), 'success': True }), mimetype="application/javascript") response['Content-Type'] = 'text/plain; charset=utf-8' return response elif action == 'savedListsFlashcardEntire' or action == 'savedListsFlashcardFM': lexForm = LexiconForm(request.POST) slForm = SavedListForm(request.POST) if lexForm.is_valid() and slForm.is_valid(): lex = Lexicon.objects.get( lexiconName=lexForm.cleaned_data['lexicon']) # lex doesn't matter if request.POST['action'] == 'savedListsFlashcardEntire': option = SavedListForm.RESTART_LIST_CHOICE elif request.POST['action'] == 'savedListsFlashcardFM': option = SavedListForm.FIRST_MISSED_CHOICE response = HttpResponse(json.dumps({ 'url': reverse('flashcards_by_savedList_pk', args=(slForm.cleaned_data['wordList'].pk, option)), 'success': True }), mimetype="application/javascript") response['Content-Type'] = 'text/plain; charset=utf-8' return response # don't do any checking right now for user access to other user lists. why? maybe people can share lists this way # as long as we're not letting the users delete lists, i think it should be fine. response = HttpResponse(json.dumps({ 'success': False, 'error': 'Did you select a list to ' 'flashcard?' }), mimetype="application/javascript") response['Content-Type'] = 'text/plain; charset=utf-8' return response