Example #1
0
def saved_lists_submit(user, post):
    lexForm = LexiconForm(post)
    timeForm = TimeForm(post)
    slForm = SavedListForm(post)
    num_q_form = NumQuestionsForm(post)
    if not (lexForm.is_valid() and timeForm.is_valid() and slForm.is_valid()
            and num_q_form.is_valid()):
        return response({'success': False,
                         'error': _('Please check that you have selected '
                                    'a word list and a time 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.initialize_by_saved_list(
        lex, user, slForm.cleaned_data['wordList'],
        slForm.cleaned_data['listOption'], quizTime,
        num_q_form.cleaned_data['num_questions'])
    if tablenum == 0:
        raise Http404
    return response({'url': reverse('wordwalls_table',
                                    args=(tablenum,)),
                     'success': True})
Example #2
0
def saved_lists_submit(user, post):
    lexForm = LexiconForm(post)
    timeForm = TimeForm(post)
    slForm = SavedListForm(post)
    if not (lexForm.is_valid() and timeForm.is_valid() and slForm.is_valid()):
        return response({
            'success':
            False,
            'error':
            'Please check that you have selected '
            'a word list and a time 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.initializeBySavedList(lex, user,
                                         slForm.cleaned_data['wordList'],
                                         slForm.cleaned_data['listOption'],
                                         quizTime)
    if tablenum == 0:
        raise Http404
    return response({
        'url': reverse('wordwalls_table', args=(tablenum, )),
        'success': True
    })
Example #3
0
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)
Example #4
0
def saved_list_delete(user, post):
    lexForm = LexiconForm(post)
    slForm = SavedListForm(post)
    if not (lexForm.is_valid() and slForm.is_valid()):
        return response({'success': False,
                         'error': _('You did not select a list to delete.')})
    deletedListPk = slForm.cleaned_data['wordList'].pk
    deleteSavedList(slForm.cleaned_data['wordList'], user)
    return response({'deleted': True,
                     'wordList': deletedListPk})
Example #5
0
def saved_list_delete(user, post):
    lexForm = LexiconForm(post)
    slForm = SavedListForm(post)
    if not (lexForm.is_valid() and slForm.is_valid()):
        return response({
            'success': False,
            'error': 'You did not select a list to delete.'
        })
    deletedListPk = slForm.cleaned_data['wordList'].pk
    deleteSavedList(slForm.cleaned_data['wordList'], user)
    return response({'deleted': True, 'wordList': deletedListPk})
Example #6
0
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
        })
Example #7
0
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)
Example #8
0
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
Example #9
0
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