Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated ajax calls #272

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,16 +1235,23 @@ def graph_costs(
# assign optimized capacity to storage components
storages = df.parent_asset__name.dropna().unique()
for ess in storages:
df.loc[
(df.parent_asset__name == ess) & (df.direction.isna() == True),
"optimized_capacity",
] = df.loc[

opt_cap = df.loc[
(df.parent_asset__name == ess) & (df.direction == "out"),
"optimized_capacity",
].values[
0
]

if opt_cap.empty is False:
df.loc[
(df.parent_asset__name == ess) & (df.direction.isna() == True),
"optimized_capacity",
] = df.loc[
(df.parent_asset__name == ess) & (df.direction == "out"),
"optimized_capacity",
].values[
0
]

df = df.fillna(0)
# TODO costs for batteries are skewed as battery capacity does not exists in fancy results
# TODO costs for dso not implemented yet
Expand Down
13 changes: 6 additions & 7 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def project_sensitivity_analysis(request, proj_id, sa_id=None):
def report_create_item(request, proj_id):
"""This ajax view is triggered by clicking on "create" in the form to add a report item"""

if request.is_ajax():
if request.headers.get("x-requested-with") == "XMLHttpRequest":
qs = request.POST
multi_scenario = request.session.get(COMPARE_VIEW, False)
report_form = ReportItemForm(qs, proj_id=proj_id, multi_scenario=multi_scenario)
Expand Down Expand Up @@ -469,7 +469,7 @@ def sensitivity_analysis_create_graph(request, proj_id):
@require_http_methods(["POST"])
def report_delete_item(request, proj_id):
"""This ajax view is triggered by clicking on "delete" in the report item top right menu options"""
if request.is_ajax():
if request.headers.get("x-requested-with") == "XMLHttpRequest":
qs = request.POST
report_item_id = qs.get("report_item_id")
if "reportItem" in report_item_id:
Expand Down Expand Up @@ -498,7 +498,7 @@ def report_delete_item(request, proj_id):
@json_view
@require_http_methods(["POST"])
def ajax_get_graph_parameters_form(request, proj_id):
if request.is_ajax():
if request.headers.get("x-requested-with") == "XMLHttpRequest":
# Prefill the form with initial values
initial_values = {}
initial_values["title"] = request.POST.get("title")
Expand Down Expand Up @@ -538,7 +538,7 @@ def ajax_get_graph_parameters_form(request, proj_id):
@login_required
@require_http_methods(["POST"])
def ajax_get_sensitivity_analysis_parameters(request):
if request.is_ajax():
if request.headers.get("x-requested-with") == "XMLHttpRequest":
qs = request.POST
sa_id = int(qs.get("sa_id"))
sa_item = get_object_or_404(SensitivityAnalysis, id=sa_id)
Expand All @@ -561,7 +561,7 @@ def ajax_get_sensitivity_analysis_parameters(request):
def update_selected_single_scenario(request, proj_id, scen_id):
proj_id = str(proj_id)
scen_id = str(scen_id)
if request.is_ajax():
if request.headers.get("x-requested-with") == "XMLHttpRequest":
status_code = 200
selected_scenarios_per_project = request.session.get("selected_scenarios", {})
selected_scenario = selected_scenarios_per_project.get(proj_id, [])
Expand Down Expand Up @@ -600,7 +600,7 @@ def update_selected_multi_scenarios(request, proj_id):
if scen_ids is not None:
scen_ids = json.loads(scen_ids)

if request.is_ajax():
if request.headers.get("x-requested-with") == "XMLHttpRequest":
status_code = 200
selected_scenarios_per_project = request.session.get("selected_scenarios", {})
selected_scenarios = selected_scenarios_per_project.get(proj_id, [])
Expand Down Expand Up @@ -1050,7 +1050,6 @@ def scenario_visualize_stacked_timeseries(request, scen_id):

# TODO exclude sink components
def scenario_visualize_capacities(request, proj_id, scen_id=None):

if scen_id is None:
selected_scenario = get_selected_scenarios_in_cache(request, proj_id)
else:
Expand Down
3 changes: 2 additions & 1 deletion app/projects/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import pickle
import os
import json
Expand Down Expand Up @@ -85,7 +86,7 @@ def set_parameter_info(param_name, field, parameters=PARAMETERS):
if default_value == "None":
default_value = None
else:
print(f"{param_name} not in the parameters file")
logging.debug(f"{param_name} not in the parameters file")

if verbose is not None:
field.label = verbose
Expand Down
2 changes: 1 addition & 1 deletion app/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def project_revoke_access(request, proj_id=None):
@require_http_methods(["POST"])
def ajax_project_viewers_form(request):

if request.is_ajax():
if request.headers.get("x-requested-with") == "XMLHttpRequest":
proj_id = int(request.POST.get("proj_id"))
project = get_object_or_404(Project, id=proj_id)

Expand Down
Loading