def users(): db = psql_api.PostgresAPI(get_db()) if flask.request.method == 'POST': fd = flask.request.form db.exec_query(q_main.ins_user, { 'user_name': fd['username'], 'user_class_id': fd['user-class-select-list'], 'first_name': fd['f_name'], 'last_name': fd['l_name'], 'passkey': fd['password'], 'email': fd['email'], 'phone': fd['phone'], 'create_by': current_user.id }, one=True) user_id = db.lod()['user_id'] for ut in fd.getlist('teams-select-list'): db.exec_query(q_main.ins_teams_assignment, { 'team_id': ut, 'user_id': user_id }) flask.flash('היוזר נוסף בהצלחה', 'success') return flask.redirect(flask.url_for('index.users')) db.exec_query(q_main.get_all_users) l_users = db.lod() db.exec_query(q_main.get_all_user_class) l_user_class = db.lod() db.exec_query(q_main.get_all_teams) l_teams = db.lod() return flask.render_template('users.html', l_users=l_users, l_user_class=l_user_class, l_teams=l_teams)
def setup_hd_categories(): db = psql_api.PostgresAPI(get_db()) if flask.request.method == 'POST': fd = flask.request.form db.exec_query(q_hd.ins_ticket_category, { 'parent_id': 0 if int(fd['hd_category_level']) == 1 else fd['hd_category_parent_id'], 'level': fd['hd_category_level'], 'category_name': fd['hd_category_name'], 'sla_days': fd['hd_category_sla_days'] if int(fd['hd_category_level']) == 3 else 0 }, one=True) if int(fd['hd_category_level']) == 3: cat3_id = db.lod()['id'] for ut in fd.getlist('teams-select-list'): db.exec_query(q_hd.ins_cat3_teams, { 'cat3_id': cat3_id, 'team_id': ut }) flask.flash('הסיווג נוסף בהצלחה', 'success') return flask.redirect(flask.url_for('hd.setup_hd_categories')) db.exec_query(q_hd.get_all_ticket_category) category_data = db.lod() db.exec_query(q_main.get_all_teams) l_teams = db.lod() return flask.render_template('setup_category.html', category_data=category_data, l_teams=l_teams)
def teams(): db = psql_api.PostgresAPI(get_db()) if flask.request.method == 'POST': fd = flask.request.form db.exec_query(q_main.ins_team, { 'team_name': fd['team_name'], 'team_desc': fd['team_desc'] }) flask.flash('הקבוצה נפתחה בהצלחה', 'success') return flask.redirect(flask.url_for('index.teams')) db.exec_query(q_main.get_all_teams) l_teams = db.lod() return flask.render_template('teams.html', l_teams=l_teams)
def open_hd_ticket(): db = psql_api.PostgresAPI(get_db()) if flask.request.method == 'POST': fd = flask.request.form db.exec_query(q_hd.ins_ticket, { 'category3id': fd['hd-cat-3'], 'assign_cust_id': fd['assign-cust'] if int(fd['assign-cust']) != 0 else current_user.id, 'create_by': current_user.id }, one=True) ticket_id = db.lod()['ticket_id'] db.exec_query( q_hd.ins_ticket_note, { 'ticket_id': ticket_id, 'ticket_note_id': 1, 'note_text': fd['hd_ticket_note'], 'create_by': current_user.id }) for i, file in enumerate( flask.request.files.getlist('hd_ticket_multi_file')): if file and tools.allowed_file(file.filename): gen_file_name, file_length, mimetype = tools.save_file( 'hd', file) db.exec_query( q_hd.ins_ticket_file, { 'ticket_id': ticket_id, 'file_name': file.filename, 'gen_file_name': gen_file_name, 'mimetype': mimetype, 'file_size': file_length, 'create_by': current_user.id }) flask.flash('הפניה נפתחה בהצלחה - מספר {}'.format(ticket_id), 'success') return flask.redirect(flask.url_for('hd.hd_home')) db.exec_query(q_hd.get_1st_cat) cat_1_l = db.lod() db.exec_query(q_hd.get_user_ticket_assign_data, {'current_user_id': current_user.id}) assign_user_id_l = db.lod() return flask.render_template('open_ticket.html', cat_1_l=cat_1_l, assign_user_id_l=assign_user_id_l)
def login(): pg_api = psql_api.PostgresAPI(get_db()) if flask.request.method == 'POST': username = flask.request.form['username'] # password = passwords.hash_password(flask.request.form['password']) password = flask.request.form['password'] pg_api.exec_query(q_main.get_user_id, { 'username': username, 'passkey': password }, True) sql_data = pg_api.lod() if len(sql_data) > 0: user = User(sql_data['user_id']) login_user(user) flask.flash('התחברת בהצלחה', 'success') return redirect_dest(fallback=flask.url_for('index.home')) else: flask.flash('התחברות נכשלה', 'error') if 'url_args' not in flask.session: flask.session['url_args'] = dict(flask.request.args) if 'next' in flask.session['url_args']: flask.session['url_args'].pop('next') return flask.render_template('login.html', csrf=csrf)
def logout(): # user_instances.remove(current_user.id) logout_user() flask.flash('יצאת בהצלחה', 'success') return flask.redirect(flask.url_for('index.home'))