Ejemplo n.º 1
0
def xhr(request):
    if request.method == 'POST':
        form = SimpleForm(request.POST)
        if form.is_valid():
            session = DBSession()
            query = simple_query(form, session)
            o = query.all()
            return HttpResponse(o)
    return HttpResponse("Error in form")
Ejemplo n.º 2
0
def view_with_form(request):
    if request.method == 'POST':
        form = SimpleForm(request.POST)
        if form.is_valid():
            messages.info(request, 'Form has been successfully submited')
            return redirect('homepage')
    else:
        form = SimpleForm()

    return render_to_response("form.html", {
        'form': form,
    }, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def landing_form(request):
    if request.method == "POST":
        form = SimpleForm(request.POST)
        if form.is_valid():
            img_name = 'data-maps/test.jpg'
            print img_name, 'name'
            return render(request, 'properties/post_edit.html', {
                'form': form,
                'img': img_name
            })
    else:
        form = SimpleForm()
    return render(request, 'properties/post_edit.html', {'form': form})
Ejemplo n.º 4
0
def view_with_form(request):
    if request.method == 'POST':
        form = SimpleForm(request.POST)
        if form.is_valid():
            messages.info(request, 'Form has been successfully submited')
            return redirect('homepage')
    else:
        form = SimpleForm()

    return render_to_response("form.html", {
        'form': form,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 5
0
def degrees():
    form = SimpleForm()
    degrees = models.Degree.query.all()
    subjects = models.Subject.query.all()

    if form.validate_on_submit():
        # Empty list to store degrees filtered by university
        uni_degrees = []

        if form.uni_data.data:
            # Get uni id from form
            university_filter = (form.uni_data.data)
            print(university_filter)

            # Filter degrees by uni using set
            for degree in degrees:
                unis = [university.id for university in degree.universities]
                for uni in unis:
                    if str(uni) in university_filter:
                        uni_degrees.append(degree)

        else:
            uni_degrees = set(degrees)

        if form.subject_data.data:
            # Get subject ids from form
            subject_filter = (form.subject_data.data)
            subjects = models.Prerequisites.query.filter(
                models.Prerequisites.sid.in_(subject_filter)).all()

            # Get degree id for every subject filtered
            subjects = [subject.did for subject in subjects]
            sub_degrees = models.Degree.query.filter(
                models.Degree.id.in_(subjects)).all()

            # Get degrees that are in both sets
            degrees = list(set(uni_degrees) & set(sub_degrees))
            print(degrees)

        # If no subject filters:
        else:
            degrees = uni_degrees

    else:
        print(form.errors)

    # Sort degrees by name
    degrees = sorted(degrees, key=lambda degree: degree.name)

    return render_template('degrees.html', degrees=degrees, forms=form)
Ejemplo n.º 6
0
def setup():
    global setup_session_step, setup_session_max_step
    if setup_session_step < setup_session_max_step:
        form = SimpleForm()
        doc_vector = create_random_user_vector()
        articles = get_articles(doc_vector)
        if form.validate_on_submit() and form.example.data:
            print(form.example.data)
            setup_session_step += 1
            if setup_session_step == setup_session_max_step:
                return redirect(url_for("main"))
            else:
                return redirect(url_for("setup"))
        else:
            pass
            # return redirect(url_for("setup"))
    return render_template("setup.html",
                           title="Setup",
                           form=form,
                           articles=articles)