Skip to content

Commit 5d23e9d

Browse files
authored
Merge pull request #28 from wmo-raf/dev
Add hooks
2 parents 359de46 + daf3bf5 commit 5d23e9d

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

forecastmanager/forms.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django import forms
22
from django.db.models import Q
33
from django.utils.translation import gettext_lazy as _
4+
from wagtail import hooks
45
from wagtail.admin.forms import WagtailAdminModelForm
56

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

135136
if commit:
136137
forecast.save()
138+
139+
for fn in hooks.get_hooks("after_forecast_add_from_form"):
140+
fn()
141+
137142
return forecast
138143

139144

forecastmanager/management/commands/clear_old_forecasts.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from django.core.management.base import BaseCommand
44
from django.utils import timezone
5+
from wagtail import hooks
56

67
from forecastmanager.models import Forecast
78

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

3031
logger.info("Old forecasts deleted successfully.")
32+
33+
for fn in hooks.get_hooks("after_clear_old_forecasts"):
34+
fn()

forecastmanager/management/commands/generate_forecast.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dateutil.parser import parse
55
from django.core.management.base import BaseCommand
66
from django.utils import timezone
7+
from wagtail import hooks
78
from wagtail.models import Site
89

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

192+
created_forecast_pks = []
193+
191194
# Create the forecast for the cities
192195
for forecast_date, city_forecasts in cities_data.items():
193196
effective_time = f"{forecast_date.hour}:00"
@@ -208,3 +211,9 @@ def handle(self, *args, **options):
208211
forecast.city_forecasts.add(city_forecast)
209212

210213
forecast.save()
214+
215+
# Add the forecast to the list of created forecasts
216+
created_forecast_pks.append(forecast.pk)
217+
218+
for fn in hooks.get_hooks("after_generate_forecast"):
219+
fn(created_forecast_pks)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = forecastmanager
3-
version = 0.5.0
3+
version = 0.5.1
44
description = Integration of Weather City Forecasts Manager in Wagtail Projects.
55
long_description = file:README.md
66
long_description_content_type = text/markdown

0 commit comments

Comments
 (0)