Exemple #1
0
def do_get(sess):

    base_name = []

    if 'scenario_id' in request.values:
        scenario_id = req_int('scenario_id')
        scenario_props = None
    else:
        year = req_int("finish_year")
        month = req_int("finish_month")
        months = req_int("months")
        start_date = Datetime(year, month, 1) - \
            relativedelta(months=months - 1)
        scenario_props = {
            'scenario_start': start_date, 'scenario_duration': months}
        scenario_id = None
        base_name.append('unified_supplies_monthly_duration')

    site_id = req_int('site_id') if 'site_id' in request.values else None
    supply_id = req_int('supply_id') if 'supply_id' in request.values else None
    user = g.user

    threading.Thread(
        target=content, args=(
            scenario_props, scenario_id, base_name, site_id, supply_id,
            user)).start()
    return chellow_redirect("/downloads", 303)
Exemple #2
0
def do_get(sess):
    contract_id = req_int('hhdc_contract_id')
    days_hidden = req_int('days_hidden')

    args = (contract_id, days_hidden, g.user)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #3
0
def do_get(session):
    user = g.user
    date = req_date('date')
    if 'supply_id' in request.values:
        supply_id = req_int('supply_id')
    else:
        supply_id = None

    if 'mpan_cores' in request.values:
        mpan_cores_str = req_str('mpan_cores')
        mpan_cores = mpan_cores_str.splitlines()
        if len(mpan_cores) == 0:
            mpan_cores = None
        else:
            for i in range(len(mpan_cores)):
                mpan_cores[i] = parse_mpan_core(mpan_cores[i])
    else:
        mpan_cores = None

    running_name, finished_name = chellow.dloads.make_names(
        'supplies_snapshot.csv', user)

    args = (running_name, finished_name, date, supply_id, mpan_cores)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #4
0
def do_get(sess):
    start_date = req_date('start')
    finish_date = req_date('finish')
    contract_id = req_int('mop_contract_id')
    args = (start_date, finish_date, contract_id, g.user)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #5
0
def do_get(sess):
    start_date = req_date('start')
    finish_date = req_date('finish')
    site_id = req_int('site_id') if 'site_id' in request.values else None
    args = (start_date, finish_date, site_id, g.user)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #6
0
def do_post(sess):
    start_date = req_date('start')
    finish_date = req_date('finish')
    supply_id = req_int('supply_id') if 'supply_id' in request.values else None

    if 'mpan_cores' in request.values:
        mpan_cores_str = req_str('mpan_cores')
        mpan_cores = mpan_cores_str.splitlines()
        if len(mpan_cores) == 0:
            mpan_cores = None
        else:
            for i in range(len(mpan_cores)):
                mpan_cores[i] = parse_mpan_core(mpan_cores[i])
    else:
        mpan_cores = None

    if finish_date < start_date:
        raise BadRequest("The finish date can't be before the start date.")

    is_zipped = req_bool('is_zipped')
    user = g.user

    threading.Thread(
        target=content, args=(
            start_date, finish_date, supply_id, mpan_cores, is_zipped, user)
        ).start()
    return chellow_redirect("/downloads", 303)
Exemple #7
0
def do_get(sess):
    supply_id = req_int('supply_id')
    start_date = req_date('start')
    finish_date = req_date('finish')

    args = supply_id, start_date, finish_date, g.user
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #8
0
def do_get(sess):
    start_date = req_hh_date('start')
    finish_date = req_hh_date('finish')
    supply_id = req_int('supply_id') if 'supply_id' in request.values else None
    thread = threading.Thread(
        target=content, args=(supply_id, start_date, finish_date, g.user))
    thread.start()
    return chellow_redirect("/downloads", 303)
Exemple #9
0
def do_get(sess):
    end_year = req_int('finish_year')
    end_month = req_int('finish_month')
    months = req_int('months')
    contract_id = req_int('supplier_contract_id')
    args = (contract_id, end_year, end_month, months, g.user)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #10
0
def do_get(sess):
    year = req_int('end_year')
    month = req_int('end_month')
    months = req_int('months')
    supply_id = req_int('supply_id') if 'supply_id' in request.values else None
    user = g.user
    threading.Thread(
        target=content, args=(year, month, months, supply_id, user)).start()
    return chellow_redirect("/downloads", 303)
def do_get(sess):
    start_date = req_date('start')
    finish_date = req_date('finish')
    g_contract_id = req_int('g_contract_id')

    threading.Thread(target=content,
                     args=(start_date, finish_date, g_contract_id,
                           g.user)).start()
    return chellow_redirect("/downloads", 303)
Exemple #12
0
def do_get(sess):
    supply_id = req_int('supply_id')
    file_name = 'supply_virtual_bills_' + str(supply_id) + '.csv'
    start_date = req_date('start')
    finish_date = req_date('finish')
    args = (supply_id, file_name, start_date, finish_date, g.user)

    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
def do_get(sess):
    g_supply_id = req_int("g_supply_id")
    file_name = "g_supply_virtual_bill_" + str(g_supply_id) + ".csv"
    start_date = req_date("start")
    finish_date = req_date("finish")
    args = (g_supply_id, file_name, start_date, finish_date, g.user)

    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #14
0
def do_get(sess):
    start_date = req_date('start')
    finish_date = req_date('finish')
    if 'site_id' in request.values:
        site_id = req_int('site_id')
    else:
        site_id = None

    args = (sess, start_date, finish_date, site_id, g.user)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #15
0
def do_get(sess):
    if "g_batch_id" in request.values:
        g_batch_id = req_int("g_batch_id")
        g_bill_id = None
    elif "g_bill_id" in request.values:
        g_bill_id = req_int("g_bill_id")
        g_batch_id = None
    else:
        raise BadRequest("The bill check needs a g_batch_id or g_bill_id.")

    threading.Thread(target=content, args=(g_batch_id, g_bill_id, g.user)).start()
    return chellow_redirect("/downloads", 303)
Exemple #16
0
def do_get(sess):
    end_year = req_int("end_year")
    end_month = req_int("end_month")
    months = req_int("months")
    contract_id = req_int('hhdc_contract_id')

    user = g.user

    threading.Thread(
        target=content, args=(contract_id, end_year, end_month, months, user)
        ).start()
    return chellow_redirect("/downloads", 303)
Exemple #17
0
def do_get(sess):
    end_year = req_int("end_year")
    end_month = req_int("end_month")
    months = req_int("months")
    contract_id = req_int('dc_contract_id')

    user = g.user

    threading.Thread(target=content,
                     args=(contract_id, end_year, end_month, months,
                           user)).start()
    return chellow_redirect("/downloads", 303)
def do_get(sess):
    show_ignored = req_bool("show_ignored")
    report_run = ReportRun.insert(
        sess,
        FNAME,
        g.user,
        FNAME,
        {},
    )
    sess.commit()
    threading.Thread(target=content, args=(g.user, show_ignored, report_run.id)).start()
    return chellow_redirect(f"/report_runs/{report_run.id}", 303)
Exemple #19
0
def handle_request(mpan_cores=None):
    start_date = req_date('start')
    finish_date = req_date('finish')
    imp_related = req_bool('imp_related')
    channel_type = req_str('channel_type')
    is_zipped = req_bool('is_zipped')
    supply_id = req_int('supply_id') if 'supply_id' in request.values else None
    user = g.user
    threading.Thread(target=content,
                     args=(start_date, finish_date, imp_related, channel_type,
                           is_zipped, supply_id, mpan_cores, user)).start()
    return chellow_redirect("/downloads", 303)
Exemple #20
0
def do_get(sess):
    if 'batch_id' in request.values:
        batch_id = req_int("batch_id")
        bill_id = None
    elif 'bill_id' in request.values:
        bill_id = req_int("bill_id")
        batch_id = None
    else:
        raise BadRequest("The bill check needs a batch_id or bill_id.")

    user = g.user
    threading.Thread(target=content, args=(batch_id, bill_id, user)).start()
    return chellow_redirect('/downloads', 303)
Exemple #21
0
def do_get(sess):
    if 'g_batch_id' in request.values:
        g_batch_id = req_int('g_batch_id')
        g_bill_id = None
    elif 'g_bill_id' in request.values:
        g_bill_id = req_int('g_bill_id')
        g_batch_id = None
    else:
        raise BadRequest("The bill check needs a g_batch_id or g_bill_id.")

    threading.Thread(
        target=content, args=(g_batch_id, g_bill_id, g.user)).start()
    return chellow_redirect('/downloads', 303)
Exemple #22
0
def handle_request(mpan_cores=None):
    start_date = req_date('start')
    finish_date = req_date('finish')
    imp_related = req_bool('imp_related')
    channel_type = req_str('channel_type')
    is_zipped = req_bool('is_zipped')
    supply_id = req_int('supply_id') if 'supply_id' in request.values else None
    user = g.user
    threading.Thread(
        target=content, args=(
            start_date, finish_date, imp_related, channel_type, is_zipped,
            supply_id, mpan_cores, user)).start()
    return chellow_redirect("/downloads", 303)
Exemple #23
0
def do_get(sess):
    months = req_int('months')
    finish_year = req_int('finish_year')
    finish_month = req_int('finish_month')

    finish_date = Datetime(finish_year, finish_month, 1, tzinfo=pytz.utc) + \
        relativedelta(months=1) - HH
    start_date = finish_date + HH - relativedelta(months=months)

    typ = req_str('type')
    site_id = req_int('site_id')
    args = (start_date, finish_date, site_id, typ, g.user)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #24
0
def do_post(sess):
    file_item = request.files["file"]
    file_path = file_item.filename
    file_head, file_name = os.path.split(file_path)
    file_title, file_ext = os.path.splitext(file_name)
    if file_ext != ".zip":
        raise BadRequest(
            f"The file name should have the extension .zip, but in fact it "
            f"has the extension '{file_ext}'.")
    f = BytesIO(file_item.read())
    f.seek(0)

    threading.Thread(target=content, args=(f, g.user)).start()
    return chellow_redirect("/downloads", 303)
Exemple #25
0
def do_get(sess):
    months = req_int('months')
    finish_year = req_int('finish_year')
    finish_month = req_int('finish_month')

    finish_date = Datetime(finish_year, finish_month, 1, tzinfo=pytz.utc) + \
        relativedelta(months=1) - HH
    start_date = finish_date + HH - relativedelta(months=months)

    typ = req_str('type')
    site_id = req_int('site_id')
    args = (start_date, finish_date, site_id, typ, g.user)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #26
0
def do_get(sess):
    months = req_int("months")
    finish_year = req_int("finish_year")
    finish_month = req_int("finish_month")

    month_list = list(
        c_months_u(finish_year=finish_year,
                   finish_month=finish_month,
                   months=months))
    start_date, finish_date = month_list[0][0], month_list[-1][-1]

    typ = req_str("type")
    site_id = req_int("site_id")
    args = (start_date, finish_date, site_id, typ, g.user)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #27
0
def do_get(sess):
    year = req_int("finish_year")
    month = req_int("finish_month")
    months = req_int("months")

    st_id = req_int('site_id') if 'site_id' in request.values else None

    finish_date = Datetime(year, month, 1, tzinfo=pytz.utc) + \
        relativedelta(months=1) - HH
    start_date = Datetime(year, month, 1, tzinfo=pytz.utc) - \
        relativedelta(months=months-1)
    user = g.user
    threading.Thread(
        target=long_process, args=(
            start_date, finish_date, st_id, months, year, month, user)).start()
    return chellow_redirect("/downloads", 303)
Exemple #28
0
def do_get(sess):
    start_year = req_int('start_year')
    start_month = req_int('start_month')
    start_day = req_int("start_day")

    finish_year = req_int('finish_year')
    finish_month = req_int('finish_month')
    finish_day = req_int('finish_day')

    is_import = req_bool('is_import')
    supply_id = req_int('supply_id')

    threading.Thread(
        target=content, args=(
            start_year, start_month, start_day, finish_year, finish_month,
            finish_day, is_import, supply_id, g.user)).start()
    return chellow_redirect("/downloads", 303)
Exemple #29
0
def do_get(sess):
    batch_id = bill_id = contract_id = start_date = finish_date = None
    if "mpan_cores" in request.values:
        mpan_cores = req_str("mpan_cores").splitlines()
    else:
        mpan_cores = []

    fname_additional = ""

    if "batch_id" in request.values:
        batch_id = req_int("batch_id")
        batch = Batch.get_by_id(sess, batch_id)
        fname_additional = f"_batch_{batch.reference}"
    elif "bill_id" in request.values:
        bill_id = req_int("bill_id")
        bill = Bill.get_by_id(sess, bill_id)
        fname_additional = "bill_" + str(bill.id)
    elif "contract_id" in request.values:
        contract_id = req_int("contract_id")
        contract = Contract.get_by_id(sess, contract_id)

        start_date = req_date("start_date")
        finish_date = req_date("finish_date")

        s = ["contract", str(contract.id)]
        for dt in (start_date, finish_date):
            s.append(hh_format(dt).replace(" ", "T").replace(":", ""))
        fname_additional = "_".join(s)
    else:
        raise BadRequest(
            "The bill check needs a batch_id, a bill_id or a start_date "
            "and finish_date.")

    args = (
        batch_id,
        bill_id,
        contract_id,
        start_date,
        finish_date,
        g.user,
        mpan_cores,
        fname_additional,
    )
    print(args)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #30
0
def do_get(sess):
    batch_id = bill_id = contract_id = start_date = finish_date = None
    if 'batch_id' in request.values:
        batch_id = req_int("batch_id")
    elif 'bill_id' in request.values:
        bill_id = req_int("bill_id")
    elif 'contract_id' in request.values:
        contract_id = req_int("contract_id")
        start_date = req_date("start_date")
        finish_date = req_date("finish_date")
    else:
        raise BadRequest(
            "The bill check needs a batch_id, a bill_id or a start_date "
            "and finish_date.")

    args = batch_id, bill_id, contract_id, start_date, finish_date, g.user
    threading.Thread(target=content, args=args).start()
    return chellow_redirect('/downloads', 303)
Exemple #31
0
def do_get(sess):
    start_date = req_date('start', 'day')
    finish_date = req_date('finish', 'day')
    finish_date = finish_date + relativedelta(days=1) - HH

    if 'site_id' in request.values:
        site_id = req_int('site_id')
        file_name = "sites_hh_data_" + str(site_id) + "_" + \
            finish_date.strftime('%Y%m%d%H%M') + ".csv"
    else:
        site_id = None
        file_name = "supplies_hh_data_" + \
            finish_date.strftime('%Y%m%d%H%M') + ".zip"

    content = none_content if site_id is None else site_content
    args = (site_id, start_date, finish_date, g.user, file_name)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #32
0
def do_get(sess):
    start_date = req_date('start', 'day')
    finish_date = req_date('finish', 'day')
    finish_date = finish_date + relativedelta(days=1) - HH

    if 'site_id' in request.values:
        site_id = req_int('site_id')
        file_name = "sites_hh_data_" + str(site_id) + "_" + \
            finish_date.strftime('%Y%m%d%H%M') + ".csv"
    else:
        site_id = None
        file_name = "supplies_hh_data_" + \
            finish_date.strftime('%Y%m%d%H%M') + ".zip"

    content = none_content if site_id is None else site_content
    args = (site_id, start_date, finish_date, g.user, file_name)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #33
0
def do_post(sess):
    file_item = request.files["file"]
    file_path = file_item.filename
    file_head, file_name = os.path.split(file_path)
    file_title, file_ext = os.path.splitext(file_name)
    if not file_ext == '.csv':
        raise BadRequest(
            "The file name should have the extension .csv, but in fact it "
            "has the extension '" + file_ext + "'.")
    idx = file_title.rfind('_')
    table = file_title[:idx]
    version = file_title[idx+1:]
    f = io.StringIO(str(file_item.read(), 'utf8'))
    f.seek(0)

    args = (table, version, f, g.user)
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #34
0
def do_post(sess):
    user = g.user
    file_item = request.files["asset_file"]

    report_run = ReportRun.insert(
        sess,
        FNAME,
        user,
        FNAME,
        {
            "STATUSES_ACTIVE": STATUSES_ACTIVE,
            "STATUSES_INACTIVE": STATUSES_INACTIVE,
            "STATUSES_IGNORE": STATUSES_IGNORE,
        },
    )
    sess.commit()
    args = user, StringIO(file_item.read().decode("utf8")), report_run.id
    threading.Thread(target=content, args=args).start()
    return chellow_redirect(f"/report_runs/{report_run.id}", 303)
def do_get(sess):
    finish_year = req_int("finish_year")
    finish_month = req_int("finish_month")
    months = req_int("months")

    site_id = req_int("site_id") if "site_id" in request.values else None

    if "g_supply_id" in request.values:
        g_supply_id = req_int("g_supply_id")
    else:
        g_supply_id = None

    if "compression" in request.values:
        compression = req_bool("compression")
    else:
        compression = True

    user = g.user
    args = (site_id, g_supply_id, user, compression, finish_year, finish_month,
            months)

    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)
Exemple #36
0
def do_get(sess):
    year = req_int('year')
    supply_id = req_int('supply_id') if 'supply_id' in request.values else None
    user = g.user
    threading.Thread(target=content, args=(year, supply_id, user)).start()
    return chellow_redirect("/downloads", 303)
Exemple #37
0
def do_post(sess):

    base_name = []
    now = utc_datetime_now()

    if "scenario_id" in request.values:
        scenario_id = req_int("scenario_id")
        scenario = Scenario.get_by_id(sess, scenario_id)
        scenario_props = scenario.props
        base_name.append(scenario.name)

        start_year = scenario_props["scenario_start_year"]
        start_month = scenario_props["scenario_start_month"]
        start_date_ct = ct_datetime(now.year, now.month, 1)
        if start_year is None:
            scenario_props["scenario_start_year"] = start_date_ct.year
        if start_month is None:
            scenario_props["scenario_start_month"] = start_date_ct.month
    else:
        year = req_int("finish_year")
        month = req_int("finish_month")
        months = req_int("months")
        start_date, _ = next(
            c_months_c(finish_year=year, finish_month=month, months=months))
        by_hh = req_bool("by_hh")
        scenario_props = {
            "scenario_start_year": start_date.year,
            "scenario_start_month": start_date.month,
            "scenario_duration": months,
            "by_hh": by_hh,
        }
        base_name.append("monthly_duration")

    try:
        site_id = req_int("site_id") if "site_id" in request.values else None
        if "site_codes" in request.values:
            site_codes = req_str("site_codes").splitlines()

            # Check sites codes are valid
            for site_code in site_codes:
                Site.get_by_code(sess, site_code)

        else:
            site_codes = []

        if "supply_id" in request.values:
            supply_id = req_int("supply_id")
        else:
            supply_id = None

        if "compression" in request.values:
            compression = req_bool("compression")
        else:
            compression = True
        user = g.user

        args = (
            scenario_props,
            base_name,
            site_id,
            supply_id,
            user,
            compression,
            site_codes,
            now,
        )
        threading.Thread(target=content, args=args).start()
        return chellow_redirect("/downloads", 303)
    except BadRequest as e:
        flash(e.description)
        now = Datetime.utcnow()
        month_start = Datetime(now.year, now.month,
                               1) - relativedelta(months=1)
        month_finish = Datetime(now.year, now.month, 1) - HH
        return make_response(
            render_template(
                "ods_monthly_duration.html",
                month_start=month_start,
                month_finish=month_finish,
            ),
            400,
        )
Exemple #38
0
def do_get(sess):
    year = req_int("year")
    supply_id = req_int("supply_id") if "supply_id" in request.values else None
    threading.Thread(target=content, args=(year, supply_id, g.user)).start()
    return chellow_redirect("/downloads", 303)
Exemple #39
0
def do_get(sess):
    site_id = req_int('site_id') if 'site_id' in request.values else None
    year = req_int('year')
    threading.Thread(target=content, args=(year, site_id, g.user)).start()
    return chellow_redirect("/downloads", 303)
Exemple #40
0
def do_get(sess):
    args = (g.user, )
    threading.Thread(target=content, args=args).start()
    return chellow_redirect("/downloads", 303)