Skip to content

Commit

Permalink
Merge pull request #204 from Georiviere/feat_add_portal_seo
Browse files Browse the repository at this point in the history
 Add portal SEO
  • Loading branch information
LePetitTim authored Aug 3, 2023
2 parents 0861e47 + 25dedc4 commit bdbb880
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ CHANGELOG
* Send mail to managers when contribution is created
* Send mail to contributor when contribution is created
* Add linked objects on contributions
* Add portal SEO informations
* Add min zoom, max zoom extent portal


1.1.0 (2023-13-06)
-------------------------
Expand Down
8 changes: 7 additions & 1 deletion georiviere/portal/serializers/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ def get_bounds(self, obj):
class PortalSerializer(ModelSerializer):
map = MapSerializer(many=False, source='*')
flatpages = SerializerMethodField()
extent = SerializerMethodField()

class Meta:
model = Portal
fields = (
'id', 'name', 'map', 'flatpages'
'id', 'name', 'map', 'flatpages', 'description', 'title', 'main_color', 'max_zoom', 'min_zoom',
'extent'
)

def get_extent(self, obj):
if obj.spatial_extent:
return obj.spatial_extent.transform(4326, clone=True).extent

def get_flatpages(self, obj):
return FlatpagePortalSerializer(obj.flatpages, many=True,
context={'portal_pk': self.context.get('portal_pk')}).data
Expand Down
12 changes: 8 additions & 4 deletions georiviere/portal/tests/test_serializers/test_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,27 @@ def setUpTestData(cls):

def test_portal_content(self):
data = self.serializer_portal.data
self.assertSetEqual(set(data.keys()), {'id', 'map', 'name', 'flatpages'})
self.assertSetEqual(set(data.keys()), {'id', 'map', 'name', 'flatpages', 'title', 'description', 'extent',
'max_zoom', 'min_zoom', 'main_color'})
self.assertEqual(len(data['map']['group'][0]['layers']), 5)

def test_portal_all_layers_grouped_content(self):
data = self.serializer_portal_layers_all_group.data
self.assertEqual(len(data['map']['group']), 1)
self.assertEqual(data['map']['group'][0]['label'], 'Bar')
self.assertSetEqual(set(data.keys()), {'id', 'map', 'name', 'flatpages'})
self.assertSetEqual(set(data.keys()), {'id', 'map', 'name', 'flatpages', 'title', 'description', 'extent',
'max_zoom', 'min_zoom', 'main_color'})
self.assertEqual(len(data['map']['group'][0]['layers']), 5)

def test_portal_without_se_content(self):
data = self.serializer_portal_without_spatial_extent.data
self.assertSetEqual(set(data.keys()), {'id', 'map', 'name', 'flatpages'})
self.assertSetEqual(set(data.keys()), {'id', 'map', 'name', 'flatpages', 'title', 'description', 'extent',
'max_zoom', 'min_zoom', 'main_color'})
self.assertAlmostEqual(data['map']['bounds'][0], -5.5006, delta=4)
self.assertAlmostEqual(data['map']['bounds'][3], 51.314, delta=4)

def test_portal_with_flatpages_content(self):
data = self.serializer_portal_with_flatpages.data
self.assertSetEqual(set(data.keys()), {'id', 'map', 'name', 'flatpages'})
self.assertSetEqual(set(data.keys()), {'id', 'map', 'name', 'flatpages', 'title', 'description', 'extent',
'max_zoom', 'min_zoom', 'main_color'})
self.assertEqual(set(data['flatpages'][0]), {'order', 'url', 'title', 'hidden'})
4 changes: 3 additions & 1 deletion georiviere/portal/tests/test_views/test_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def test_portal_structure(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

self.assertEqual(list(response.json().keys()), ['id', 'name', 'map', 'flatpages'])
self.assertEqual(list(response.json().keys()), ['id', 'name', 'map', 'flatpages',
'description', 'title', 'mainColor',
'maxZoom', 'minZoom', 'extent'])
self.assertEqual(len(response.json()['map']['group']), 1)
self.assertEqual(response.json()['map']['group'][0]['label'], None)

0 comments on commit bdbb880

Please sign in to comment.