Example #1
0
def addSubSection(id_survey, id_section):
    parentSection = Section.query.get(id_section)
    form = SectionForm()
    if form.validate_on_submit():
        section = Section(title = form.title.data,
            description = form.description.data,
            sequence = form.sequence.data,
            percent = form.percent.data,
            parent = parentSection)
        db.session.add(section)
        db.session.commit()
        flash('Adding subsection.')
        return redirect(url_for('researcher.editSection',id_survey = id_survey, id_section = id_section))
    # heuristics of the next sequence
    section = Section.query.filter(Section.parent_id==id_section).order_by(Section.sequence.desc())
    if section.count()>=2 and section[0].sequence==section[1].sequence:
        # see the last and  penultimate
        form.sequence.data= section[0].sequence
    elif section.count()>=1:
        form.sequence.data= section[0].sequence + 1
    else:
        form.sequence.data =1
    path=tips_path(parentSection)
    return render_template('/researcher/addEditSection.html',
        title = "Section",
        form = form,
        survey = Survey.query.get(id_survey),
        sections = Survey.query.get(id_survey).sections.all(),
        addSubSection = True,
        path = path)
Example #2
0
def editSection(id_survey, id_section):
    section = Section.query.get(id_section)
    form = SectionForm()
    sections = Survey.query.get(id_survey).sections.all()
    if form.validate_on_submit():
        section.title = form.title.data
        section.description = form.description.data
        section.sequence = form.sequence.data
        section.percent = form.percent.data
        db.session.add(section)
        db.session.commit()
        flash('Save changes')
        return redirect(url_for('researcher.editSection',id_survey = id_survey, id_section = id_section))
    elif request.method != "POST":
        form.title.data = section.title
        form.description.data = section.description
        form.sequence.data = section.sequence
        form.percent.data = section.percent
    path=tips_path(section)
    return render_template('/researcher/addEditSection.html',
        title = "Section",
        form = form,
        survey = Survey.query.get(id_survey),
        sections = sections,
        editSection = True,
        id_section = id_section,
        path = path)
Example #3
0
def addSection(id_survey):
    survey = Survey.query.get(id_survey)
    form = SectionForm()
    if form.validate_on_submit():
        section = Section(title = form.title.data,
            description = form.description.data,
            sequence = form.sequence.data,
            percent = form.percent.data,
            survey = survey
            )
        db.session.add(section)
        db.session.commit()
        flash('Adding section.')
        return redirect(url_for('researcher.editSurvey',id_survey = survey.id))
    # heuristics of the next sequence
    section = Section.query.filter(Section.survey_id==id_survey).order_by(Section.sequence.desc())
    if section.count()>=2 and section[0].sequence==section[1].sequence:
        # see the last and  penultimate
        form.sequence.data= section[0].sequence
    elif section.count()>=1:
        form.sequence.data= section[0].sequence + 1
    else:
        form.sequence.data =1
    return render_template('/researcher/addEditSection.html',
        title = "Section",
        form = form,
        survey = survey,
        sections = survey.sections.all(),
        #add = true, you is adding a new section
        addSection = True)
Example #4
0
def section_edit(name, section):
    space = ProposalSpace.query.filter_by(name=section).first()
    section  = ProposalSpaceSection.query.filter_by(name=section).first()
    form = SectionForm(obj=section)
    if form.validate_on_submit():
        form.populate_obj(section)
        db.session.commit()
        flash("Your section has been edited", 'info')
        return redirect(space.url_for('viewspace', name=space.name), code=303)
    return render_template('autoform.html', form=form, title="Edit section", submit="Save changes")
Example #5
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")
Example #6
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 #7
0
    def post(self, request, section_id=None):
        section = Section()
        if section_id:
            section = Section.objects.get(pk=section_id)

        form = SectionForm(request.POST, request.FILES, instance=section)

        if form.is_valid():
            form.save()
            return redirect("inventory_section")
        else:
            return self.render_to_response({
                "form": form,
            })