def search_params_submit(user, post): """ Called when user submits a search params query. """ lexForm = LexiconForm(post) timeForm = TimeForm(post) fwForm = FindWordsForm(post) num_q_form = NumQuestionsForm(post) # form bound to the POST data if not (lexForm.is_valid() and timeForm.is_valid() and fwForm.is_valid() and num_q_form.is_valid()): return response({'success': False, 'error': _('There was something wrong with your ' 'search parameters or time selection.')}) lex = Lexicon.objects.get( lexiconName=lexForm.cleaned_data['lexicon']) quiz_time = int(round(timeForm.cleaned_data['quizTime'] * 60)) questions_per_round = num_q_form.cleaned_data['num_questions'] search = searchForAlphagrams(fwForm.cleaned_data, lex) wwg = WordwallsGame() tablenum = wwg.initialize_by_search_params(user, search, quiz_time, questions_per_round) return response({'url': reverse('wordwalls_table', args=(tablenum,)), 'success': True})
def search_params_submit(user, post): """ Called when user submits a search params query. """ lexForm = LexiconForm(post) timeForm = TimeForm(post) fwForm = FindWordsForm(post) # form bound to the POST data if not (lexForm.is_valid() and timeForm.is_valid() and fwForm.is_valid()): return response({ 'success': False, 'error': 'There was something wrong with your ' 'search parameters or time selection.' }) lex = Lexicon.objects.get(lexiconName=lexForm.cleaned_data['lexicon']) quizTime = int(round(timeForm.cleaned_data['quizTime'] * 60)) alphasSearchDescription = searchForAlphagrams(fwForm.cleaned_data, lex) wwg = WordwallsGame() tablenum = wwg.initializeBySearchParams(user, alphasSearchDescription, quizTime) 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 homepage(request): #unbound forms lexForm = LexiconForm() timeForm = TimeForm() fwForm = FindWordsForm() dcForm = DailyChallengesForm() ulForm = UserListForm() slForm = SavedListForm() nlForm = NamedListForm() profile = request.user.get_profile() if request.method == 'POST': return handle_homepage_post(profile, request) lengthCounts = dict([(l.lexiconName, l.lengthCounts) for l in Lexicon.objects.all()]) # Create a random token for socket connection and store in Redis # temporarily. # conn_token = get_connection_token(request.user) profile = request.user.get_profile() try: data = json.loads(profile.additional_data) except (TypeError, ValueError): data = {} return render( request, 'wordwalls/index.html', { 'fwForm': fwForm, 'dcForm': dcForm, 'challengeTypes': [(n.pk, n.name) for n in DailyChallengeName.objects.all()], 'ulForm': ulForm, 'slForm': slForm, 'lexForm': lexForm, 'timeForm': timeForm, 'nlForm': nlForm, 'lengthCounts': json.dumps(lengthCounts), 'upload_list_limit': wordwalls.settings.UPLOAD_FILE_LINE_LIMIT, 'dcTimes': json.dumps(dcTimeMap), 'defaultLexicon': profile.defaultLexicon, # 'connToken': conn_token, 'chatEnabled': not data.get('disableChat', False), 'socketUrl': settings.SOCKJS_SERVER, 'CURRENT_VERSION': CURRENT_VERSION })
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