Ejemplo n.º 1
0
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})
Ejemplo n.º 2
0
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})
Ejemplo n.º 3
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.º 4
0
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
    })
Ejemplo n.º 5
0
def update(request, id):
    note = Note.objects.get(id=id)

    if request.user == note.author:
        c = Context({'object': note})
        if request.method == 'POST':
            form = NoteForm(request.POST, instance=note)
            if note.is_event:
                timeform = TimeForm(request.POST)
                c.update({'timeform': timeform})

            if form.is_valid():
                if not note.is_event:
                    note.save()
                    return HttpResponseRedirect(note.get_absolute_url())

                else:
                    if timeform.is_valid():
                        pprint.pprint(timeform.cleaned_data)

                        note.end = datetime.datetime.combine(
                                timeform.cleaned_data['end_date'],
                                timeform.cleaned_data['end_time']
                            )

                        note.start = datetime.datetime.combine(
                                timeform.cleaned_data['start_date'],
                                timeform.cleaned_data['start_time']
                            )

                        note.save()
                        return HttpResponseRedirect(note.get_absolute_url())
        else:
            form = NoteForm(instance=note)
            if note.is_event:
                c.update({'timeform': TimeForm({
                    'start_date': note.start.date(),
                    'start_time': note.start.time(),
                    'end_date': note.end.date(),
                    'end_time': note.end.time(),
                    })
                })

        c.update({'form': form, 'is_event': note.is_event})
        return render(request, "corkboard/note_form.html", c)
    else:
        return HttpResponseForbidden("Du har ikke tilladelse til at redigere dette opslag.")
Ejemplo n.º 6
0
def create(request, event):
    if request.user.is_authenticated():
        c = {}
        if request.method == 'POST':
            form = NoteForm(request.POST)
            if event:
                timeform = TimeForm(request.POST)
                c.update({'timeform': timeform})

            if form.is_valid():
                note = form.save(commit=False)
                note.author = request.user
                note.pub_date = datetime.datetime.now()

                if not event:
                    note.save()
                    return HttpResponseRedirect(note.get_absolute_url())

                else:
                    #pprint.pprint(timeform.data)

                    if timeform.is_valid():
                        #pprint.pprint(timeform.cleaned_data)

                        note.end = datetime.datetime.combine(
                                timeform.cleaned_data['end_date'],
                                timeform.cleaned_data['end_time']
                            )

                        note.start = datetime.datetime.combine(
                                timeform.cleaned_data['start_date'],
                                timeform.cleaned_data['start_time']
                            )

                        note.is_event = True
                        note.save()
                        return HttpResponseRedirect(note.get_absolute_url())

        else:
            form = NoteForm()
            if event:
                c.update({'timeform': TimeForm()})

        c.update({'form': form, 'is_event': event})
        return render(request, "corkboard/note_form.html", c)
    else:
        return redirect_to_login(request.path)
Ejemplo n.º 7
0
def add(request, map_id):
    """
    Dodaje nowy wynik na wskazanej trasie, jeśli formularz został poprawnie uzupełniony.

    :returns: formularz, mapa

    .. include:: ../source/login_required.rst

    """
    map = Map.objects.get(pk=map_id)
    form = TimeForm(request.POST)
    if form.is_valid():
        time = form.save(commit=False)
        time.map = map
        time.user = request.user
        time.save()
        messages.success(request, ADDED)
        return redirect('my-profile')
    return direct_to_template(request, 'stats/new.html', { 'form': form, 'map': map})
Ejemplo n.º 8
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})