Skip to content

Commit

Permalink
Add macrogroup_id to group serializer. (#761)
Browse files Browse the repository at this point in the history
* Add `macrogroup_id` to group serializer.

* 🐛 Client
  g3w-suite/g3w-client#579

* ✨ Client
  g3w-suite/g3w-client#579

* ✨ Client
  g3w-suite/g3w-client@ebb57cd

* Typo: fix 'nomacrogroup' filter.

* Typo.

* Fix testing.

* 🐛 Client
 g3w-suite/g3w-client#590

---------

Co-authored-by: wlorenzetti <[email protected]>
Co-authored-by: volterra79 <[email protected]>
Co-authored-by: Raruto <[email protected]>
  • Loading branch information
4 people authored Mar 4, 2024
1 parent ccbbefd commit ee5486e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
14 changes: 9 additions & 5 deletions g3w-admin/about/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def filter_queryset(self, request, queryset, view):


class UserProjectFilter(BaseFilterBackend):
"""A filter backend for portal module for qdjango project"""
"""A filter backend for about module for qdjango project"""

def filter_queryset(self, request, queryset, view):
"""
Expand All @@ -47,20 +47,24 @@ def filter_queryset(self, request, queryset, view):


class GroupProjectFilter(BaseFilterBackend):
"""A filter backend for portal module for qdjango project , filter by group"""
"""A filter backend for about module for qdjango project , filter by group"""

def filter_queryset(self, request, queryset, view):
"""
Return a filtered queryset by group_id
"""

if 'group_id' in view.kwargs:
queryset = queryset.filter(group_id=view.kwargs['group_id']).order_by('order')

if resolve(request.path_info).url_name == 'about-group-without-macrogroup-api-list':
queryset = queryset.filter(macrogroups__pk=None)

return queryset


class MacroGroupGroupFilter(BaseFilterBackend):
"""A filter backend for portal module for group, filter by macrogroup"""
"""A filter backend for about module for group, filter by macrogroup"""

def filter_queryset(self, request, queryset, view):
"""
Expand All @@ -70,14 +74,14 @@ def filter_queryset(self, request, queryset, view):
queryset = queryset.filter(macrogroups__pk=view.kwargs['macrogroup_id'])

# check for group without macrogroup
if resolve(request.path_info).url_name == 'portal-group-without-macrogroup-api-list':
if resolve(request.path_info).url_name == 'about-group-without-macrogroup-api-list':
queryset = queryset.filter(macrogroups__pk=None)

return queryset


class PanoramicProjectFilter(BaseFilterBackend):
"""A filter backend for portal module for qdjango project , filter by not panoramic"""
"""A filter backend for about module for qdjango project , filter by not panoramic"""

def filter_queryset(self, request, queryset, view):

Expand Down
13 changes: 9 additions & 4 deletions g3w-admin/about/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def setUpTestData(cls):

cls.project_group2.save()

cls.project_group3 = CoreGroup(name='Group3', title='Group3', header_logo_img='',
srid=G3WSpatialRefSys.objects.get(auth_srid=3857))

cls.project_group3.save()

# create macrogroups
cls.macrogroup = MacroGroup(title='Macrogroup1', logo_img='macrogroup.png')
cls.macrogroup.save()
Expand Down Expand Up @@ -173,7 +178,7 @@ def test_group(self):
response = client.get(url)
self.assertEqual(response.status_code, 200)
jcontent = json.loads(response.content)
self.assertEqual(len(jcontent), 2)
self.assertEqual(len(jcontent), 3)
feature = jcontent[0]
self.assertIn('edit_url', feature)
group = CoreGroup.objects.filter(pk=feature['id'])[0]
Expand Down Expand Up @@ -318,7 +323,7 @@ def test_macrogroup(self):
response = client.get(url)
self.assertEqual(response.status_code, 200)
jcontent = json.loads(response.content)
self.assertEqual(len(jcontent), 2)
self.assertEqual(len(jcontent), 1)

# ad new group without macrogroup
new_group = CoreGroup(name='Group33', title='Group33', header_logo_img='',
Expand All @@ -328,8 +333,8 @@ def test_macrogroup(self):
response = client.get(url)
self.assertEqual(response.status_code, 200)
jcontent = json.loads(response.content)
self.assertEqual(len(jcontent), 3)
self.assertEqual(jcontent[2]['name'], 'Group33')
self.assertEqual(len(jcontent), 2)
self.assertEqual(jcontent[1]['name'], 'Group33')

client.logout()

Expand Down
2 changes: 1 addition & 1 deletion g3w-admin/client/static/client/js/app.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions g3w-admin/core/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ def to_representation(self, instance):
mapcontrol.name: options
})

# Macrogroups
ret['macrogroup_id'] = [macrogroup.id for macrogroup in instance.macrogroups.all()]

return ret

class Meta:
Expand Down
3 changes: 2 additions & 1 deletion g3w-admin/editing/static/editing/js/plugin.js

Large diffs are not rendered by default.

0 comments on commit ee5486e

Please sign in to comment.