def create_default_records(): ''' create database necessary records, if not existing. ''' tables = [ data.Display_store, data.Touch_store, data.Slides_c, data.Settings, data.Vid, data.Printer, data.Aliases ] # NOTE: Create default records, if non-existing. for table in tables: if not table.query.first(): db.session.add(table()) db.session.commit() data.Roles.load_roles() # NOTE: Add default user account if not existing if not data.User.query.first(): db.session.add( data.User(name=DEFAULT_USER, password=DEFAULT_PASSWORD, role_id=1)) db.session.commit() for task, settings in BACKGROUNDTASKS_DEFAULTS.items(): task_settings = data.BackgroundTask.get(name=task) if not task_settings: db.session.add(data.BackgroundTask(task, **settings)) db.session.commit()
def user_a(): ''' to add a user ''' form = UserForm() if form.validate_on_submit(): if data.User.query.filter_by(name=form.name.data).first() is not None: flash('Error: user name already exists, choose another name', 'danger') return redirect(url_for('administrate.user_a')) db.session.add( data.User(form.name.data, form.password.data, form.role.data)) db.session.commit() if form.role.data == 3: db.session.add( data.Operators( data.User.query.filter_by(name=form.name.data).first().id, form.offices.data)) db.session.commit() flash('Notice: user has been added .', 'info') return redirect(url_for('administrate.users')) return render_template('user_add.html', form=form, navbar='#snb3', page_title='Add user', offices_count=data.Office.query.count())
def create_default_records(): ''' create database necessary records, if not existing. ''' tables = [data.Display_store, data.Touch_store, data.Slides_c, data.Settings, data.Vid, data.Printer, data.Aliases] # NOTE: Create default records, if non-existing. for table in tables: if not table.query.first(): db.session.add(table()) db.session.commit() data.Roles.load_roles() # NOTE: Add default user account if not existing if not data.User.query.first(): db.session.add(data.User(name=DEFAULT_USER, password=DEFAULT_PASSWORD, role_id=1)) db.session.commit()