Пример #1
0
def write_email_tbl(email_status, recipients, subject, body, user_id):
    db = psql_api.PostgresAPI(get_db())
    db.exec_query(q_main.ins_email, {'email_status': email_status,
                                     'recipients': recipients,
                                     'subject': subject,
                                     'body': body,
                                     'create_by': user_id})
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
def hd_home():
    l_user_tickets = []
    if current_user.is_authenticated:
        db = psql_api.PostgresAPI(get_db())
        db.exec_query(q_hd.get_user_tickets, {'user_id': current_user.id})
        l_user_tickets = db.lod()
        flask.session['prv_page'] = flask.request.path
    return flask.render_template('hd_home.html', l_user_tickets=l_user_tickets)
Пример #5
0
def my_team_ticket():
    db = psql_api.PostgresAPI(get_db())
    db.exec_query(q_hd.get_my_teams_tickets_header,
                  {'user_id': current_user.id})
    l_my_teams_tickets = db.lod()
    flask.session['prv_page'] = flask.request.path
    return flask.render_template('my_team_ticket.html',
                                 l_my_teams_tickets=l_my_teams_tickets)
Пример #6
0
def get_children_category():
    db = psql_api.PostgresAPI(get_db())
    db.exec_query(
        q_hd.get_children_cat_sql, {
            'parent_id': flask.request.args['cat_id'],
            'level': flask.request.args['cat_level']
        })
    return flask.jsonify(db.lod())
Пример #7
0
def add_ticket_user_note():
    db = psql_api.PostgresAPI(get_db())
    fd = flask.request.form
    db.exec_query(
        q_hd.ins_user_ticket_note, {
            'ticket_id': fd['ticket_id'],
            'ticket_note_type_id': 2,
            'note_text': fd['note_text'],
            'create_by': current_user.id
        })
    return flask.jsonify(None)
Пример #8
0
def download_hd_ticket_file(gen_file_name):
    db = psql_api.PostgresAPI(get_db())
    db.exec_query(q_hd.get_orig_filename, {'gen_file_name': gen_file_name},
                  one=True)
    full_path = os.path.join(app.config['UPLOAD_FOLDER'], 'hd')
    file_data = db.lod()
    return flask.send_from_directory(
        full_path,
        gen_file_name,
        attachment_filename=file_data['file_name'],
        as_attachment=True,
        mimetype=file_data['mimetype'])
Пример #9
0
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)
Пример #10
0
def ticket():
    prv_page = ''
    if 'prv_page' in flask.session.keys():
        prv_page = flask.session['prv_page']
        flask.session.pop('prv_page')
    ticket_id = flask.request.args.get('id', default=None, type=int)
    db = psql_api.PostgresAPI(get_db())
    db.exec_query(q_hd.get_1st_cat)
    cat_1_l = db.lod()
    db.exec_query(q_hd.get_ticket_close_reason)
    close_reason_l = db.lod()
    return flask.render_template('ticket.html',
                                 ticket_id=ticket_id,
                                 cat_1_l=cat_1_l,
                                 close_reason_l=close_reason_l,
                                 prv_page=prv_page)
Пример #11
0
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)
Пример #12
0
def close_ticket():
    db = psql_api.PostgresAPI(get_db())
    fd = flask.request.form
    db.exec_query(
        q_hd.ins_user_ticket_note, {
            'ticket_id': fd['ticket_id'],
            'ticket_note_type_id': 3,
            'note_text': fd['note_text'],
            'create_by': current_user.id
        })
    db.exec_query(
        q_hd.close_ticket_status, {
            'close_by': current_user.id,
            'close_reason_id': fd['close_reason_id'],
            'ticket_id': fd['ticket_id']
        })
    return flask.jsonify(None)
Пример #13
0
def set_ticket_header():
    db = psql_api.PostgresAPI(get_db())
    fd = flask.request.form
    db.exec_query(q_hd.update_ticket_category, {
        'category3id': fd['cat_3_id'],
        'ticket_id': fd['ticket_id']
    },
                  one=True)
    old_category3id = db.lod()
    new_category3id = {'category3id': fd['cat_3_id']}
    note_text = "עדכון סיווג"
    db.exec_query(
        q_hd.ins_user_ticket_note_log, {
            'ticket_id': fd['ticket_id'],
            'note_text': note_text,
            'old_data': json.dumps(old_category3id),
            'new_data': json.dumps(new_category3id),
            'create_by': current_user.id
        })
    return flask.jsonify(None)
Пример #14
0
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)
Пример #15
0
def update_select_category():
    db = psql_api.PostgresAPI(get_db())
    db.exec_query(q_hd.get_top_ticket_category,
                  {'level': flask.request.args['hd_category_level']})
    return flask.jsonify(db.lod())
Пример #16
0
def home():
    db = psql_api.PostgresAPI(get_db())
    db.exec_query('select now()', one=True)
    d = db.lod()
    return flask.render_template('home.html', d=d['now'])
Пример #17
0
import sys
import time
import traceback
from datetime import datetime
from random import shuffle
from setup import get_config, get_engine, get_db
from scrapebot.database import *


print('[' + str(datetime.now()) + '] ScrapeBot initiated (this is server time)')
config = get_config(False)
db = get_db(get_engine(config))

this_instance_name = config.get('Instance', 'name')
this_instance = None
try:
    if this_instance_name == '' or db.query(Instance).filter(Instance.name == this_instance_name).count() == 0:
        print('Error: Instance not found')
        db.close()
        exit(1)
    else:
        print('Authenticated as instance "' + this_instance_name + '"')
        this_instance = db.query(Instance).filter(Instance.name == this_instance_name).one()
except:
    print('Error: Initial database query failed')
    error = sys.exc_info()[0]
    if error is not None:
        print('- ' + str(error))
        print('- ' + traceback.format_exc())
    db.close()
    exit(1)
Пример #18
0
def get_ticket_header():
    db = psql_api.PostgresAPI(get_db())
    db.exec_query(q_hd.get_ticket_header,
                  {'ticket_id': flask.request.args['ticket_id']},
                  one=True)
    return flask.jsonify(db.lod())
Пример #19
0
def get_ticket_user_files():
    db = psql_api.PostgresAPI(get_db())
    db.exec_query(q_hd.get_ticket_files,
                  {'ticket_id': flask.request.args['ticket_id']})
    return flask.jsonify(db.lod())