Skip to content

Commit f269b07

Browse files
authored
Merge pull request #3 from wmo-raf/dev
implement dynamic api path
2 parents 8bbb190 + e7df93d commit f269b07

File tree

6 files changed

+14
-17
lines changed

6 files changed

+14
-17
lines changed

forecastmanager/serializers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ def get_coordinates(self, obj):
2020
class ForecastSerializer(serializers.ModelSerializer):
2121

2222
city_detail = serializers.SerializerMethodField()
23-
condition_display = serializers.SerializerMethodField()
23+
# condition_display = serializers.SerializerMethodField()
2424
list_serializer_class = serializers.ListSerializer
2525

2626
class Meta:
2727
model = Forecast
28-
fields =['id','forecast_date','max_temp','min_temp', 'condition_display', 'city', 'city_detail', 'condition']
28+
fields =['id','forecast_date','max_temp','min_temp', 'city', 'city_detail', 'condition']
2929

3030

3131
@staticmethod
3232
def get_city_detail(obj):
3333
serializer = CitySerializer(obj.city)
3434
return serializer.data
3535

36-
def get_condition_display(self, obj):
37-
return obj.get_condition_display()
36+
# def get_condition_display(self, obj):
37+
# return obj.get_condition_display()
3838

3939
def to_representation(self, instance):
4040
representation = super().to_representation(instance)
@@ -47,8 +47,8 @@ def to_representation(self, instance):
4747
'forecast_date': representation['forecast_date'],
4848
'max_temp': representation['max_temp'],
4949
'min_temp': representation['min_temp'],
50-
'condition':representation['condition_display'],
51-
'condition_icon': f'static/forecastmanager/img/{representation["condition"]}.png',
50+
'condition':representation['condition'],
51+
'condition_icon': f'{representation["condition"]}.png',
5252
},
5353
"geometry": {
5454
"coordinates": representation['city_detail']['coordinates'],

forecastmanager/templates/forecastmanager/create_forecast.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ <h2 class="w-panel__heading">Add forecast</h2>
189189
var city_ls = JSON.parse('{{city_ls|escapejs}}')
190190

191191
const container = document.querySelector('#createTable');
192-
const BASE_URL = '{{request.get_full_path}}'
193-
194192

195193
const hot = new Handsontable(container, {
196194
width: '100%',
@@ -328,7 +326,7 @@ <h2 class="w-panel__heading">Add forecast</h2>
328326

329327
// Send the JSON data to a Django view via AJAX
330328
$.ajax({
331-
url: `${BASE_URL}/api/forecasts/`,
329+
url: `{% url 'forecast-list'%}`,
332330
type: 'POST',
333331
headers: {
334332
'X-CSRFToken': '{{ csrf_token }}', // Replace with the actual CSRF token value

forecastmanager/templates/forecastmanager/load_forecast.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ <h2 class="w-panel__heading">Latest Available Forecast</h2>
6565

6666
document.addEventListener("DOMContentLoaded", function() {
6767

68-
const BASE_URL = '{{request.get_full_path}}'
6968
// initialize map
7069
var forecastMap = new maplibregl.Map({
7170
container:'forecast_map',
@@ -150,10 +149,9 @@ <h2 class="w-panel__heading">Latest Available Forecast</h2>
150149

151150
}
152151

153-
function setForecastData(forecast_date){
154-
152+
function setForecastData(forecast_date){
155153
// Make an HTTP GET request to the API endpoint
156-
fetch(`${BASE_URL}api/forecasts?forecast_date=${forecast_date}`)
154+
fetch(`{% url 'forecast-list'%}?forecast_date=${forecast_date}`)
157155
.then(response => response.json()) // Parse the response as JSON
158156
.then(data => {
159157
// Process the retrieved data
@@ -168,7 +166,7 @@ <h2 class="w-panel__heading">Latest Available Forecast</h2>
168166
}
169167

170168
}
171-
img.src = `${BASE_URL}${icon.properties.condition_icon}`
169+
img.src = `{% static 'forecastmanager/img/${icon.properties.condition_icon}' %}`
172170
return img.src
173171

174172
})

forecastmanager/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from django.urls import path,include
2+
from django.urls import path,include, reverse
33
from .views import CityAPIView, ForecastAPIView
44
from rest_framework import routers
55

@@ -9,5 +9,5 @@
99

1010

1111
urlpatterns = [
12-
path('api/', include(router.urls)),
12+
path('api/', include(router.urls), name='api'),
1313
]

sandbox/sandbox/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,4 @@
173173
# Base URL to use when referring to full URLs within the Wagtail admin backend -
174174
# e.g. in notification emails. Don't include '/admin' or a trailing slash
175175
WAGTAILADMIN_BASE_URL = "http://example.com"
176+
# FORCE_SCRIPT_NAME='/cms'

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.0.5
3+
version = 0.0.6
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)