Skip to content

Commit

Permalink
Merge pull request #28 from wmo-raf/dev
Browse files Browse the repository at this point in the history
Add hooks
  • Loading branch information
erick-otenyo authored Jun 14, 2024
2 parents 359de46 + daf3bf5 commit 5d23e9d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions forecastmanager/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django import forms
from django.db.models import Q
from django.utils.translation import gettext_lazy as _
from wagtail import hooks
from wagtail.admin.forms import WagtailAdminModelForm

from forecastmanager.forecast_settings import (
Expand Down Expand Up @@ -134,6 +135,10 @@ def save(self, commit=True):

if commit:
forecast.save()

for fn in hooks.get_hooks("after_forecast_add_from_form"):
fn()

return forecast


Expand Down
4 changes: 4 additions & 0 deletions forecastmanager/management/commands/clear_old_forecasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.core.management.base import BaseCommand
from django.utils import timezone
from wagtail import hooks

from forecastmanager.models import Forecast

Expand All @@ -28,3 +29,6 @@ def handle(self, *args, **options):
old_forecasts.delete()

logger.info("Old forecasts deleted successfully.")

for fn in hooks.get_hooks("after_clear_old_forecasts"):
fn()
9 changes: 9 additions & 0 deletions forecastmanager/management/commands/generate_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dateutil.parser import parse
from django.core.management.base import BaseCommand
from django.utils import timezone
from wagtail import hooks
from wagtail.models import Site

from forecastmanager.constants import WEATHER_CONDITIONS_AS_DICT
Expand Down Expand Up @@ -188,6 +189,8 @@ def handle(self, *args, **options):
else:
cities_data[timezone_date] = [city_forecast]

created_forecast_pks = []

# Create the forecast for the cities
for forecast_date, city_forecasts in cities_data.items():
effective_time = f"{forecast_date.hour}:00"
Expand All @@ -208,3 +211,9 @@ def handle(self, *args, **options):
forecast.city_forecasts.add(city_forecast)

forecast.save()

# Add the forecast to the list of created forecasts
created_forecast_pks.append(forecast.pk)

for fn in hooks.get_hooks("after_generate_forecast"):
fn(created_forecast_pks)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = forecastmanager
version = 0.5.0
version = 0.5.1
description = Integration of Weather City Forecasts Manager in Wagtail Projects.
long_description = file:README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit 5d23e9d

Please sign in to comment.