Beispiel #1
0
def add_customer_preference(userid):
    form = PreferenceForm(request.form)
    user = userid_to_object(userid)
    if request.method == 'POST' and form.validate():
        insert_preference(userid, form.preference.data)
    preferences = get_preferences(userid)
    return render_template('/customerreptasks/preferences.html',
                           form=form,
                           preferences=preferences,
                           user=user)
Beispiel #2
0
def preference(request):
    saved = False
    instance = Preference.objects.get(user=request.user)
    preference = PreferenceForm(instance=instance)
    if request.method == "POST":
        preference = PreferenceForm(data=request.POST, instance=instance)
        if preference.is_valid():
            p = preference.save(commit=False)
            p.save()
            saved = True
    return render_to_response("preference.html", {"form": preference, "saved": saved}, RequestContext(request))
Beispiel #3
0
def chpref_page():
    form=PreferenceForm()
    global data
    if not data.pref:
        flash("Preferences not yet registered")
        return redirect(url_for('mkpref_page'))    
    return render_template('mkpref.html', student=data, form=form, title='Change Preferences')
Beispiel #4
0
def preference(request):
    saved = False
    instance = Preference.objects.get(user=request.user)
    preference = PreferenceForm(instance=instance)
    if request.method == 'POST':
        preference = PreferenceForm(data=request.POST, instance=instance)
        if preference.is_valid():
            p = preference.save(commit=False)
            p.save()
            saved = True
    return render_to_response('preference.html', {
        'form': preference,
        'saved': saved
    }, RequestContext(request))
Beispiel #5
0
def mkpref_page():
    form=PreferenceForm()
    global data
    if request.method=='POST':
        #Transform preferences into required form to be stored
        check_pref=list(request.form['p'+str(i)] for i in range(1,10))
        if choice_check(check_pref):  #Call choice_check to check if all preferences chosen are unique
            for student in UserData.query.all():    #If successful, update the database
                if student.username==data.username:
                    student.pref=str(list(request.form['p'+str(i)] for i in range(1,10)))
                    db.session.commit()
                    check_login()
                    flash("Preferences registered")
                    return redirect(url_for('user_page'))
        else:
            flash("Choices not unique")
            return render_template('mkpref.html', student=data, form=form, title='Change Preferences')
    else:
        if data.pref:
            flash("Choice already submitted once")
            return redirect(url_for('vwpref_page'))
        return render_template('mkpref.html', student=data, form=form, title='Make Preferences')
Beispiel #6
0
def preferences():
    form = PreferenceForm(request.form)
    if request.method == 'POST' and form.validate():
        insert_preference(session['userid'], form.preference.data)
    preferences = get_preferences(session['userid'])
    return render_template('/usertasks/preferences.html', form=form, preferences=preferences)