Esempio n. 1
0
def edit_in_progress_document(document_id):
    '''
    Allows updating and deleting of individual documents.
    '''
    document_base = dm.get_single_document(document_id)
    if request.args.get('method') == 'DELETE':
        if dm.delete_document(document_base):
            return redirect(url_for('generator.in_progress_documents'))
        return abort(403)
Esempio n. 2
0
def edit_in_progress_document(document_id):
    '''
    Allows updating and deleting of individual documents.
    '''
    document_base = dm.get_single_document(document_id)
    if request.args.get('method') == 'DELETE':
        if dm.delete_document(document_base):
            return redirect(url_for('generator.in_progress_documents'))
        return abort(403)
Esempio n. 3
0
    def test_get_documents(self):
        documents = dm.get_all_documents()
        self.assertEquals(len(documents), 1)
        util.insert_new_document(self.template.id, name='second test doc')
        documents = dm.get_all_documents()
        self.assertEquals(len(documents), 2)

        document = dm.get_single_document(2)
        self.assertEquals(document.template_id, self.template.id)
Esempio n. 4
0
def edit_document_sections(document_id, section_id=None):
    '''
    View to handle building a new RFP document

    GET - Returns a new document generator based on the template
    POST - TODO
    '''
    document_base = dm.get_single_document(document_id)
    template_base = tp.get_single_template(document_base.template_id)

    if template_base is None or document_base is None:
        return render_template('404.html')

    if section_id is None:
        return redirect(url_for(
            'generator.edit_document_sections', document_id=document_id,
            section_id=template_base.section_order[0]
        ))

    sections = sc.get_template_sections(template_base)
    current_section = sc.get_single_section(section_id, template_base.id)
    placeholders = dm.get_document_placeholders(document_base.id)

    class F(Form):
        pass

    if current_section.section_type == 'text':
        # if we have a text section, we need to prep the page for the rivets
        # two-way data binding
        current_section_text = current_section.text
        for placeholder in placeholders:
            # add a data_input value onto the placeholder
            placeholder.rv_data_input = 'placeholder_' + '_'.join(strip_tags(placeholder.display_name).split())
            # format the section text
            current_section_text = create_rivets_bindings(placeholder, current_section_text)
            # set up the form
            setattr(
                F, placeholder.display_name,
                TYPE_VARIABLES_MAP[placeholder.type](placeholder.display_name, validators=[validators.Optional()])
            )

    form = F()

    if form.validate_on_submit():
        dm.save_document_section(placeholders, request.form)
        flash('Changes successfully saved!', 'alert-success')
        return redirect(url_for(
            'generator.edit_document_sections', document_id=document_base.id, section_id=current_section.id)
        )
    for field in form.__iter__():
        # set the rv_data_input value on the form field as well as on the placeholder
        setattr(field, 'rv_data_input', 'template.placeholder_' + '_'.join(strip_tags(field.name).split()))
        setattr(field, 'label', field.name)

    return render_template('generator/build-document.html',
        document=document_base, template=template_base,
        sections=sections, placeholders=placeholders,
        current_section=current_section,
        current_section_text=current_section_text or None,
        form=form
    )
Esempio n. 5
0
def edit_document_sections(document_id, section_id=None):
    '''
    View to handle building a new RFP document

    GET - Returns a new document generator based on the template
    POST - TODO
    '''
    document_base = dm.get_single_document(document_id)
    template_base = tp.get_single_template(document_base.template_id)

    if template_base is None or document_base is None:
        return render_template('404.html')

    if section_id is None:
        return redirect(
            url_for('generator.edit_document_sections',
                    document_id=document_id,
                    section_id=template_base.section_order[0]))

    sections = sc.get_template_sections(template_base)
    current_section = sc.get_single_section(section_id, template_base.id)
    placeholders = dm.get_document_placeholders(document_base.id)

    class F(Form):
        pass

    if current_section.section_type == 'text':
        # if we have a text section, we need to prep the page for the rivets
        # two-way data binding
        current_section_text = current_section.text
        for placeholder in placeholders:
            # add a data_input value onto the placeholder
            placeholder.rv_data_input = 'placeholder_' + '_'.join(
                strip_tags(placeholder.display_name).split())
            # format the section text
            current_section_text = create_rivets_bindings(
                placeholder, current_section_text)
            # set up the form
            setattr(
                F, placeholder.display_name,
                TYPE_VARIABLES_MAP[placeholder.type](
                    placeholder.display_name,
                    validators=[validators.Optional()]))

    form = F()

    if form.validate_on_submit():
        dm.save_document_section(placeholders, request.form)
        flash('Changes successfully saved!', 'alert-success')
        return redirect(
            url_for('generator.edit_document_sections',
                    document_id=document_base.id,
                    section_id=current_section.id))
    for field in form.__iter__():
        # set the rv_data_input value on the form field as well as on the placeholder
        setattr(
            field, 'rv_data_input',
            'template.placeholder_' + '_'.join(strip_tags(field.name).split()))
        setattr(field, 'label', field.name)

    return render_template('generator/build-document.html',
                           document=document_base,
                           template=template_base,
                           sections=sections,
                           placeholders=placeholders,
                           current_section=current_section,
                           current_section_text=current_section_text or None,
                           form=form)