Ejemplo n.º 1
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
        })
Ejemplo n.º 2
0
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
    })
Ejemplo n.º 3
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)
Ejemplo n.º 4
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