Example #1
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})
Example #2
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})
Example #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
    })
Example #4
0
def add_times(swim_id):
    form = TimeForm()
    if request.method == 'POST' and form.validate():
        swim_date = form.dateOfTime.data
        swim_date = swim_date.split(',')
        #swim_date = date(int(swim_date[0]), int(swim_date[1]), int(swim_date[2]))

        if form.minutes.data == "":
            time_min = 0
        else:
            time_min = int(form.minutes.data)

        swimTime = time(0, time_min, int(form.seconds.data),
                        int(form.milliseconds.data) * 10000)

        distance, stroke = form.event.data.split()
        distance = int(distance)

        for cur in session.query(race).filter_by(distance=distance).filter_by(
                stroke=stroke):
            event_id = cur.id
        session.add(
            swimmer_race(swimmer_id=swim_id,
                         race_id=event_id,
                         time=swimTime,
                         date_of_time=date(int(swim_date[0]),
                                           int(swim_date[1]),
                                           int(swim_date[2]))))
        session.commit()

        return redirect('/swimmer_page=' + swim_id)
    return render_template('new_time.html', form=form, swim_id=swim_id)
Example #5
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
    })
Example #6
0
def time():
    form = TimeForm()
    if form.validate_on_submit():
        session['time_number1'] = form.match_number.data
        session['time_number2'] = form.match_number.data
        session['name_number'] = form.name_number.data
        session['time_row'] = form.match_row.data
        session['robot_number'] = form.robot_number.data
        return redirect(url_for('match2'))
    return render_template('time.html', form=form, num=0)
Example #7
0
File: app.py Project: aliasxu/Timer
def custom():
    form = TimeForm()
    if form.validate_on_submit():
        times = form.timer.data
        if times[-1] not in 'smh':
            flash(u'请输入正确的格式,如20s,15m,2h')
            return redirect(url_for('timer', form=form))
        else:
            type = {'s': 'seconds', 'm': 'minutes', 'h': 'hours'}
            return redirect(url_for(type[times[-1]], num=int(times[:-1])))
    return redirect(url_for('index', form=form))
Example #8
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 #9
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.")
Example #10
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)
Example #11
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})
Example #12
0
def admin_page():
    time_form = TimeForm(prefix='time_form')
    monThings = EduSchedu.query.filter(EduSchedu.dow == 0).order_by(
        EduSchedu.time.asc()).all()
    tueThings = EduSchedu.query.filter(EduSchedu.dow == 1).order_by(
        EduSchedu.time.asc()).all()
    wedThings = EduSchedu.query.filter(EduSchedu.dow == 2).order_by(
        EduSchedu.time.asc()).all()
    thuThings = EduSchedu.query.filter(EduSchedu.dow == 3).order_by(
        EduSchedu.time.asc()).all()
    friThings = EduSchedu.query.filter(EduSchedu.dow == 4).order_by(
        EduSchedu.time.asc()).all()
    satThings = EduSchedu.query.filter(EduSchedu.dow == 5).order_by(
        EduSchedu.time.asc()).all()
    sunThings = EduSchedu.query.filter(EduSchedu.dow == 6).order_by(
        EduSchedu.time.asc()).all()

    if time_form.validate_on_submit():
        eduschedu = EduSchedu(classname=time_form.classname.data,
                              time=time_form.time.data,
                              dow=time_form.dow.data,
                              zoomlink=time_form.zoomlink.data)
        database.session.add(eduschedu)
        database.session.commit()
        flash('Class Updated!', 'info')
        if time_form.enroll.data == True:
            print('sup')
            usertest = User.query.first()
            eduscheduler = EduSchedu.query.order_by(
                EduSchedu.id.desc()).first()
            eduscheduler.students.append(usertest)
            database.session.commit()
        return redirect(url_for('admin_page'))

    return render_template('admin_page.html',
                           time_form=time_form,
                           monThings=monThings,
                           tueThings=tueThings,
                           wedThings=wedThings,
                           thuThings=thuThings,
                           friThings=friThings,
                           satThings=satThings,
                           sunThings=sunThings)
Example #13
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})