Example #1
0
def add_section(request):
    if request.method == 'POST':
        raw_data = SectionForm(request.POST)
        if raw_data.is_valid():
            data = raw_data.cleaned_data
            Sections.objects.create(**data)
            return redirect(view_sections)
        context = {'section_form': raw_data}
        return render(request, 'homework6_add_section.html', context)
    else:
        sections = Sections.objects.filter()
        context = {'section_form': SectionForm(), 'sections': sections}
        return render(request, 'homework6_add_section.html', context)
Example #2
0
def newsection(name):
    space = ProposalSpace.query.filter_by(name=name).first()
    if not space:
        abort(404)
    form = SectionForm()
    if form.validate_on_submit():
        section = ProposalSpaceSection(proposal_space=space)
        form.populate_obj(section)
        db.session.add(section)
        db.session.commit()
        flash("Your new section has been added", "info")
        return redirect(url_for('viewspace', name=space.name), code=303)
    return render_template('autoform.html', form=form, title="New section", submit="Create section")