예제 #1
0
def index():
    form = LineConfigForm()
    configs_lines_api_url = os.path.join(current_app.config['DAC_HOST_URL'],
                                         current_app.config['DAC_API_CONFIGS_LINES_URL'])
    try:
        conn = HTTPConnection(current_app.config['DAC_HOST_URL'])
        conn.request("GET", configs_lines_api_url)
        resp = conn.getresponse()
        if resp.code == 200:
            data = json.loads(resp.read().decode())
        else:
            raise HTTPException()
    except HTTPException:
        data = {}
        flash(_("Can not connect to DAC server."))
    except ConnectionError:
        data = {}
        flash(_("Can not connect to DAC server."))
    finally:
        conn.close()

    if data != {}:
        lines = [line for line in data['data']['configs'].keys()]
        configs = data['data']['configs']
    else:
        lines = []
        configs = {}

    return render_template('config_view.html', form=form, data=configs, lines=lines, totail_lines=form.line_no.choices)
예제 #2
0
def index():
    form = LineConfigForm()
    configs_lines_api_url = os.path.join(
        current_app.config['DAC_HOST_URL'],
        current_app.config['DAC_API_CONFIGS_LINES_URL'])
    try:
        conn = HTTPConnection(current_app.config['DAC_HOST_URL'])
        conn.request("GET", configs_lines_api_url)
        resp = conn.getresponse()
        if resp.code == 200:
            data = json.loads(resp.read().decode())
        else:
            raise HTTPException()
    except HTTPException:
        data = {}
        flash(_("Can not connect to DAC server."))
    except ConnectionError:
        data = {}
        flash(_("Can not connect to DAC server."))
    finally:
        conn.close()

    if data != {}:
        lines = [line for line in data['data']['configs'].keys()]
        configs = data['data']['configs']
    else:
        lines = []
        configs = {}

    return render_template('config_view.html',
                           form=form,
                           data=configs,
                           lines=lines,
                           totail_lines=form.line_no.choices)
예제 #3
0
def upload():
    form = ScheduleForm()
    if form.validate_on_submit():
        schedule_date = form.date.data.strftime('%Y%m%d')
        schedule_type = form.type.data  # request.form['type']
        schedule_file = form.file.data
        # .read().decode('utf-8')
        filename = secure_filename(schedule_file.filename)
        upload_api = os.path.join(current_app.config['DAC_API_SCHEDULES_URL'],
                                  schedule_date, schedule_type)
        #upload_api = current_app.config['DAC_API_SCHEDULES_URL'] + schedule_date + '/' + schedule_type
        print(upload_api)
        headers = {
            "Content-type": "application/x-www-form-urlencoded",
            "Accept": "text/plain"
        }
        data = parse.urlencode({
            'file': schedule_file.read().decode('utf-8'),
            'fname': filename,
        })

        try:
            conn = HTTPConnection(current_app.config['DAC_HOST_URL'])
            conn.request("POST", upload_api, data, headers)
            resp = conn.getresponse()
            if resp.code == 200:
                resp_data = json.loads(resp.read().decode('utf-8'))
            else:
                raise HTTPException()

        except HTTPException:
            resp_data = {}
            flash(_("Can not connect to DAC server."))

        except ConnectionError:
            data = {}
            flash(_("Can not connect to DAC server."))
        finally:
            conn.close()
        flash(resp_data)

        return redirect(url_for('schedule.upload'))

    return render_template('schedule_view.html', form=form)
예제 #4
0
def upload():
    form = ScheduleForm()
    if form.validate_on_submit():
        schedule_date = form.date.data.strftime('%Y%m%d')
        schedule_type = form.type.data  # request.form['type']
        schedule_file = form.file.data
        # .read().decode('utf-8')
        filename = secure_filename(schedule_file.filename)
        upload_api = os.path.join(current_app.config['DAC_API_SCHEDULES_URL'], schedule_date, schedule_type)
        # print(upload_url)
        headers = {"Content-type": "application/x-www-form-urlencoded",
                   "Accept": "text/plain"}
        data = parse.urlencode({
            'file': schedule_file.read().decode('utf-8'),
            'fname': filename,
        })

        try:
            conn = HTTPConnection(current_app.config['DAC_HOST_URL'])
            conn.request("POST", upload_api, data, headers)
            resp = conn.getresponse()
            if resp.code == 200:
                resp_data = json.loads(resp.read().decode('utf-8'))
                print(resp_data)
            else:
                raise HTTPException()

        except HTTPException:
            resp_data = {}
            flash(_("Can not connect to DAC server."))

        except ConnectionError:
            data = {}
            flash(_("Can not connect to DAC server."))
        finally:
            conn.close()
        flash(resp_data)

        return redirect(url_for('schedule.upload'))

    return render_template('schedule_view.html', form=form)
예제 #5
0
# coding:utf-8
"""
    train.settings
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

    train settings config.
    :copyright: (c) 2015 by Vito.
    :license: GNU, see LICENSE for more details.
"""
from tcc3portal.tcc_core.babel import _

LINES = [
    ("01", _("L1")),
    ("02", _("L2")),
    ("04", _("L4")),
    ("05", _("L5")),
    ("06", _("L6")),
    ("07", _("L7")),
    ("08", _("L8")),
    ("09", _("L9")),
    ("10", _("L10")),
    ("13", _("L13")),
    ("14", _("L14")),
    ("15", _("L15")),
    ("94", _("L94")),
    ("95", _("L95")),
    ("96", _("L96")),
    ("97", _("L97")),
    ("98", _("L98")),
]
예제 #6
0
# coding:utf-8
"""
    train.settings
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

    train settings config.
    :copyright: (c) 2015 by Vito.
    :license: GNU, see LICENSE for more details.
"""
from tcc3portal.tcc_core.babel import _

LINES = [
    ("01", _("L1")),
    ("02", _("L2")),
    ("04", _("L4")),
    ("05", _("L5")),
    ("06", _("L6")),
    ("07", _("L7")),
    ("08", _("L8")),
    ("09", _("L9")),
    ("10", _("L10")),
    ("13", _("L13")),
    ("14", _("L14")),
    ("15", _("L15")),
    ("16", _("L16")),
    ("94", _("L94")),
    ("95", _("L95")),
    ("96", _("L96")),
    ("97", _("L97")),
    ("98", _("L98")),
]