Skip to content

Commit

Permalink
Fix upgrading issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dalonsoa committed Nov 16, 2023
1 parent 48694ac commit 60a30b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions validated/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def create_daily_df(
daily["value_difference_error_count"] = (
daily_group_all["value_difference_error"].sum(numeric_only=False).to_numpy()
)

daily["date"] = pd.to_datetime(daily["date"])
daily["day_interval"] = (daily["date"] - daily["date"].shift(1)).dt.days
daily.loc[0, "day_interval"] = 1
daily["date_error"] = np.where(daily["day_interval"].gt(1), 3, 1)
Expand Down Expand Up @@ -606,7 +606,7 @@ def calculate_extra_data_daily(
)
extra_data_count["date"] = pd.to_datetime(
extra_data_count["time_truncated"]
).dt.date
)

extra_data_daily_group = extra_data_count[
extra_data_count["extra_values_count"] > 0
Expand Down Expand Up @@ -706,6 +706,7 @@ def daily_report(
# Final touches and extracting relevant parts from other dataframes
daily.index.name = "id"
daily.reset_index(inplace=True)
daily["date"] = daily["date"].dt.date
return (
daily,
selected[["time"] + value_fields],
Expand Down Expand Up @@ -1297,3 +1298,11 @@ def calculate_monthly(variable):
monthly = Monthly(**record)
monthly.save()
daily_block.update(used_for_monthly=True)


def is_ajax(request):
"""Check if a requests is an Ajax one.
Following suggestion in https://stackoverflow.com/a/70419609/3778792
"""
return request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
6 changes: 3 additions & 3 deletions validated/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class DailyValidation(FormView):
def post(self, request, *args, **kwargs):
form = DailyValidationForm(self.request.POST or None)
if form.is_valid():
if self.request.is_ajax():
if functions.is_ajax(self.request):
variable = form.cleaned_data["variable"]
station = form.cleaned_data["station"]
start_date = form.cleaned_data["start_date"]
Expand All @@ -325,7 +325,7 @@ class DetailList(ListView):
template_name = "home/message.html"

def get(self, request, *args, **kwargs):
if self.request.is_ajax():
if functions.is_ajax(self.request):
station_id = kwargs.get("station_id")
variable_id = kwargs.get("variable_id")
date = kwargs.get("date")
Expand Down Expand Up @@ -401,7 +401,7 @@ class DataReport(FormView):
def post(self, request, *args, **kwargs):
form = DataReportForm(self.request.POST or None)
if form.is_valid():
if self.request.is_ajax():
if functions.is_ajax(self.request):
temporality = form.cleaned_data["temporality"]
station = form.cleaned_data["station"]
variable = form.cleaned_data["variable"]
Expand Down

0 comments on commit 60a30b6

Please sign in to comment.