def add_tableinfo(did): form = NewTableInfoForm() if form.validate_on_submit(): # create & insert entry into TableInfo table descriptive_name = dao.stripinputstring(form.descriptive_name.data) table_name = dao.stripinputstring(form.table_name.data.lower()) tableinfo = TableInfo(descriptive_name=descriptive_name, table_name=table_name, department_id=did, table_status="1") db.session.add(tableinfo) # create the table itself table = db.Table(table_name, db.metadata, db.Column('id', db.Integer)) try: table.create(db.engine) db.session.commit() except exc.SQLAlchemyError: db.session.rollback() return redirect(url_for('admin')) return render_template('add_tableinfo.html', form=form)
def add_department(): form = NewDepartmentForm() if form.validate_on_submit(): name = dao.stripinputstring(form.departmentname.data) department = Department(name=name) db.session.add(department) db.session.commit() return redirect(url_for('admin')) return render_template('add_department.html', form=form)
def add_field(iid): form = NewFieldForm() tableinfo = TableInfo.query.filter_by(id=iid).first() if form.validate_on_submit(): fieldname = dao.stripinputstring(form.fieldname.data) fieldtype = form.fieldtype.data dao.add_field(tableinfo, fieldname, fieldtype) return redirect(url_for('fields', iid=iid)) return render_template('add_field.html', form=form, tableinfo=tableinfo)
def bulk_add_fields(iid): form = BulkFieldsForm() tableinfo = TableInfo.query.filter_by(id=iid).first() if form.validate_on_submit(): data = form.upload.data file_name = secure_filename(data.filename) file_path = path.join(basedir, theapp.config['UPLOAD_FOLDER'], file_name) data.save(file_path) wb = load_workbook(file_path, data_only=True, read_only=True) sheet = wb.get_active_sheet() allrows = sheet.iter_rows() #this is a generator for row in allrows: if (row[0].value is not None) or (row[1].value is not None): fieldname = dao.stripinputstring( row[0].value) #field name stripped fieldtypetext = dao.stripinputstring(row[1].value) if fieldtypetext == "Text": fieldtype = FieldType.query.filter_by(name="Text").first() elif fieldtypetext == "Number": fieldtype = FieldType.query.filter_by( name="Number").first() elif fieldtypetext == "Date": fieldtype = FieldType.query.filter_by(name="Date").first() else: fieldtype = FieldType.query.filter_by(name="Text").first() dao.add_field(tableinfo, fieldname, fieldtype) return redirect(url_for('fields', iid=iid)) return render_template('bulk_add_fields.html', form=form, tableinfo=tableinfo)