Skip to content

Commit

Permalink
i
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Dec 5, 2024
1 parent ceece0c commit ff25448
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 86 deletions.
2 changes: 0 additions & 2 deletions chellow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def create_app(testing=False, instance_path=None):
props = configuration.make_properties()
api_props = props.get("api", {})
api.description = api_props.get("description", "Access Chellow data")
chellow.utils.url_root_map = props.get("url_root_map", {})

chellow.dloads.startup(Path(app.instance_path), run_deleter=(not testing))

Expand All @@ -115,7 +114,6 @@ def before_request():
)
)
print(msg)
chellow.utils.url_root = chellow.utils.url_root_map.get(request.host, "")

@app.before_request
def check_permissions(*args, **kwargs):
Expand Down
8 changes: 1 addition & 7 deletions chellow/e/computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

from zish import dumps

import chellow.bank_holidays
import chellow.utils
from chellow.models import (
Bill,
BillType,
Expand Down Expand Up @@ -218,11 +216,7 @@ def hh_rate(sess, caches, contract_id_or_name, date, market_role_code=None):
f"The market role code {market_role_code} isn't recognized."
)

vals = PropDict(
f"the rate script {chellow.utils.url_root}{seg}{rs.id} ",
loads(rs.script),
[],
)
vals = PropDict(f"the rate script {seg}{rs.id} ", loads(rs.script), [])
for dt in hh_range(caches, cstart, cfinish):
if dt not in cont_cache:
cont_cache[dt] = vals
Expand Down
32 changes: 13 additions & 19 deletions chellow/e/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
flash,
g,
make_response,
redirect,
render_template as rtemplate,
request,
)
Expand Down Expand Up @@ -105,14 +106,13 @@
utc_datetime_now,
)
from chellow.views import (
chellow_redirect as credirect,
hx_redirect as chx_redirect,
requires_editor,
)


def chellow_redirect(path, code=None):
return credirect(f"/e{path}", code)
return redirect(f"/e{path}", code)


def hx_redirect(path, code=None):
Expand Down Expand Up @@ -726,9 +726,9 @@ def dc_batch_file_download_get(file_id):
batch_file = BatchFile.get_by_id(g.sess, file_id)

output = make_response(batch_file.data)
output.headers["Content-Disposition"] = (
f'attachment; filename="{batch_file.filename}"'
)
output.headers[
"Content-Disposition"
] = f'attachment; filename="{batch_file.filename}"'
output.headers["Content-type"] = "application/octet-stream"
return output

Expand Down Expand Up @@ -1421,9 +1421,7 @@ def dno_rate_script_edit_delete(dno_rate_script_id):
dno = Party.get_dno_by_code(g.sess, contract.name, rate_script.start_date)
contract.delete_rate_script(g.sess, rate_script)
g.sess.commit()
res = make_response()
res.headers["HX-Redirect"] = f"{chellow.utils.url_root}/e/dnos/{dno.id}"
return res
return hx_redirect(f"/dnos/{dno.id}")
except BadRequest as e:
flash(e.description)
return render_template(
Expand Down Expand Up @@ -2820,9 +2818,9 @@ def mop_batch_file_download_get(file_id):
batch_file = BatchFile.get_by_id(g.sess, file_id)

output = make_response(batch_file.data)
output.headers["Content-Disposition"] = (
f'attachment; filename="{batch_file.filename}"'
)
output.headers[
"Content-Disposition"
] = f'attachment; filename="{batch_file.filename}"'
output.headers["Content-type"] = "application/octet-stream"
return output

Expand Down Expand Up @@ -5026,9 +5024,9 @@ def supplier_batch_file_download_get(file_id):
batch_file = BatchFile.get_by_id(g.sess, file_id)

output = make_response(batch_file.data)
output.headers["Content-Disposition"] = (
f'attachment; filename="{batch_file.filename}"'
)
output.headers[
"Content-Disposition"
] = f'attachment; filename="{batch_file.filename}"'
output.headers["Content-type"] = "application/octet-stream"
return output

Expand Down Expand Up @@ -6020,11 +6018,7 @@ def supply_note_edit_delete(supply_id, index):
del supply_note["notes"][index]
supply.note = dumps(supply_note)
g.sess.commit()
res = make_response()
res.headers["HX-Redirect"] = (
f"{chellow.utils.url_root}/e/supplies/{supply_id}/notes"
)
return res
return hx_redirect(f"/supplies/{supply_id}/notes")
except BadRequest as e:
flash(e.description)
supply_note = loads(supply.note)
Expand Down
4 changes: 1 addition & 3 deletions chellow/gas/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from zish import dumps, loads

import chellow.bank_holidays
from chellow.e.computer import hh_rate
from chellow.models import (
BillType,
Expand Down Expand Up @@ -323,8 +322,7 @@ def g_rates(sess, caches, g_contract_id_or_name, date, is_industry):
prefix = "industry" if g_contract.is_industry else "supplier"

vals = PropDict(
f"the rate script {chellow.utils.url_root}/g/{prefix}_rate_scripts/"
f"{rs.id} ",
f"the rate script /g/{prefix}_rate_scripts/{rs.id} ",
loads(rs.script),
[],
)
Expand Down
5 changes: 1 addition & 4 deletions chellow/reports/report_87.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ def create_csv(f, sess, start_date, finish_date, contract_id):
)
writer.writerow(csv_make_val(vals.get(t)) for t in titles)
except BadRequest as e:
raise BadRequest(
f"Problem with {chellow.utils.url_root}eras/{era.id}/edit "
f"{e.description}"
)
raise BadRequest(f"Problem with /e/eras/{era.id}/edit {e.description}")

sess.rollback() # Avoid long-running transaction

Expand Down
3 changes: 0 additions & 3 deletions chellow/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

from zish import ZishException, loads

url_root_map = {}
url_root = ""

HH = relativedelta(minutes=30)
MONTH = relativedelta(months=1)
YEAR = relativedelta(years=1)
Expand Down
Loading

0 comments on commit ff25448

Please sign in to comment.