def dynamic_form(schema):
    schema_url = f"{current_app.config['SCHEMA_URL']}/{schema}-schema.json"
    title = schema.replace('-', ' ').capitalize()
    schema_json = requests.get(schema_url).json()
    form_object = formfactory(schema_json)
    if request.method == 'POST':
        form = form_object(obj=request.form)
        if form.validate():
            entry_data = form.data
            del entry_data['csrf_token']
            entry = DynamicModel(schema=schema,
                                 json_blob=json_serialiser(entry_data))
            db.session.add(entry)
            db.session.commit()
            obj = db.session.query(DynamicModel).order_by(
                DynamicModel.id.desc()).first()
            return redirect(
                url_for('frontend.check', schema=schema, row=obj.id))
    else:
        form = form_object()

    return render_template('dynamicform.html',
                           form=form,
                           schema=schema,
                           title=title)
Example #2
0
def edit(schema, row):
    schema = schema
    schema_url = f"{current_app.config['SCHEMA_URL']}/{schema}-schema.json"
    schema_json = requests.get(schema_url).json()
    form_object = formfactory(schema_json)
    entry = DynamicModel.query.filter_by(uuid=row).first()
    data = entry.json_blob
    for k, v in data.items():
        if "date" in k and v is not None:
            data[k] = datetime.datetime.strptime(v, '%Y-%m-%d').date()
    title = "Editing the form"
    form = form_object(**data)
    if request.method == 'POST':
        form = form_object(obj=request.form)
        if form.validate():
            entry_data = form.data
            del entry_data['csrf_token']
            entry.json_blob = json_serialiser(entry_data)
            db.session.add(entry)
            db.session.commit()
            return redirect(url_for('frontend.check', schema=schema, row=row))

    return render_template('edit.html',
                           form=form,
                           schema=schema,
                           title=title,
                           row=row)
def edit(schema, row):
    schema = schema
    schema_url = f"{current_app.config['SCHEMA_URL']}/{schema}-schema.json"
    schema_json = requests.get(schema_url).json()
    form_object = formfactory(schema_json)
    entry = DynamicModel.query.filter_by(id=row).first()
    data = entry.json_blob
    for k, v in data.items():
        if "date" in k and v is not None:
            data[k] = datetime.datetime.strptime(v, '%Y-%m-%d').date()
    title = "Editing the form"
    form = form_object(**data)

    return render_template('dynamicform.html',
                           form=form,
                           schema=schema,
                           title=title)
Example #4
0
def edit(schema, row):
    schema = schema
    schema_url = f"{current_app.config['SCHEMA_URL']}/{schema}-schema.json"
    schema_json = requests.get(schema_url).json()
    form_object = formfactory(schema_json)
    file_name = "draft-" + schema
    index_number = int(float(row)) - 1
    data = csv_dict(file_name, index_number)
    for k, v in data.items():
        if "date" in k and v is not None:
            data[k] = datetime.datetime.strptime(v, '%Y-%m-%d').date()
    title = "Editing the form"
    form = form_object(**data)
    print("This is the editing form")

    return render_template('dynamicform.html',
                           form=form,
                           schema=schema,
                           title=title)
Example #5
0
def dynamic_form(schema):
    schema_url = f"{current_app.config['SCHEMA_URL']}/{schema}-schema.json"
    draft_file_name = "draft-" + schema
    title = schema.replace('-', ' ').capitalize()
    schema_json = requests.get(schema_url).json()
    form_object = formfactory(schema_json)
    if request.method == 'POST':
        form = form_object(obj=request.form)
        if form.validate():
            update_csv(draft_file_name, form.data)
            row_count = sum(1 for row in csv_view(draft_file_name))
            return redirect(
                url_for('frontend.check', schema=schema, row=row_count))
    else:
        form = form_object()

    return render_template('dynamicform.html',
                           form=form,
                           schema=schema,
                           title=title)