Skip to content

Commit

Permalink
fix some APIs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gannetson committed Aug 24, 2022
1 parent 6981562 commit 6e3e7a5
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bluebottle/collect/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class CollectTypeList(TranslatedApiViewMixin, JsonApiViewMixin, ListAPIView):
pagination_class = NoPagination

def get_queryset(self):
return super().get_queryset().order_by('translations__name')
return super().get_queryset()


class CollectTypeDetail(TranslatedApiViewMixin, JsonApiViewMixin, RetrieveAPIView):
Expand Down
6 changes: 2 additions & 4 deletions bluebottle/geo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from django.template.defaultfilters import slugify
from django.utils.translation import gettext_lazy as _
from future.utils import python_2_unicode_compatible
from parler.models import TranslatedFields
from parler.models import TranslatedFields, TranslatableModel
from sorl.thumbnail import ImageField
from timezonefinder import TimezoneFinder

from bluebottle.utils.models import SortableTranslatableModel
from bluebottle.utils.validators import FileMimetypeValidator, validate_file_infection
from .validators import Alpha2CodeValidator, Alpha3CodeValidator, \
NumericCodeValidator
Expand All @@ -21,7 +20,7 @@


@python_2_unicode_compatible
class GeoBaseModel(SortableTranslatableModel):
class GeoBaseModel(TranslatableModel):
"""
Abstract base model for the UN M.49 geoscheme.
Refs: http://unstats.un.org/unsd/methods/m49/m49.htm
Expand Down Expand Up @@ -106,7 +105,6 @@ def code(self):
return self.alpha2_code

class Meta(GeoBaseModel.Meta):
ordering = ['translations__name']
verbose_name = _("country")
verbose_name_plural = _("countries")

Expand Down
13 changes: 7 additions & 6 deletions bluebottle/geo/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ def test_api_country_list_data(self):
"""
Ensure get request returns record with correct data.
"""
response = self.client.get(reverse('country-list'))

country = response.data[0]
response = self.client.get(
reverse('country-list'),
HTTP_X_APPLICATION_LANGUAGE='nl'
)

self.assertEqual(country['id'], self.country_1.id)
self.assertEqual(country['name'], self.country_1.name)
self.assertEqual(country['code'], 'GE')
countries = response.data
self.assertTrue('Abchazië' in [c['name'] for c in countries])
self.assertTrue('Zwitserland' in [c['name'] for c in countries])


class UsedCountryListTestCase(GeoTestCase):
Expand Down
3 changes: 2 additions & 1 deletion bluebottle/geo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def get(self, request, *args, **kwargs):

def get_queryset(self):
qs = super(CountryList, self).get_queryset()

if 'filter[used]' in self.request.GET:
qs = qs.filter(
Q(location__initiative__status='approved') |
Expand All @@ -33,7 +34,7 @@ def get_queryset(self):
Q(geolocation__dateactivityslot__activity__status__in=self.public_statuses) &
Q(geolocation__dateactivityslot__status__in=self.public_statuses)
)
).distinct()
)
return qs


Expand Down
2 changes: 1 addition & 1 deletion bluebottle/initiatives/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class ThemeList(TranslatedApiViewMixin, JsonApiViewMixin, ListAPIView):
pagination_class = NoPagination

def get_queryset(self):
return super().get_queryset().order_by('translations__name')
return super().get_queryset()


class ThemeDetail(TranslatedApiViewMixin, JsonApiViewMixin, RetrieveAPIView):
Expand Down
4 changes: 2 additions & 2 deletions bluebottle/time_based/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3211,14 +3211,14 @@ def setUp(self):
MemberPlatformSettings.objects.update(closed=True)
self.url = reverse('skill-list')
Skill.objects.all().delete()
self.skill = SkillFactory.create_batch(40)
SkillFactory.create_batch(10)
self.client = JSONAPITestClient()

def test_get_skills_authenticated(self):
user = BlueBottleUserFactory.create()
response = self.client.get(self.url, user=user)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data['results']), 40)
self.assertEqual(len(response.data['results']), 10)

def test_get_skills_unauthenticated(self):
response = self.client.get(self.url)
Expand Down
5 changes: 0 additions & 5 deletions bluebottle/time_based/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
ActivitySegmentPermission
)
from bluebottle.activities.views import RelatedContributorListView
from bluebottle.clients import properties
from bluebottle.initiatives.models import InitiativePlatformSettings
from bluebottle.members.models import MemberPlatformSettings
from bluebottle.segments.models import SegmentType
Expand Down Expand Up @@ -694,10 +693,6 @@ class SkillList(TranslatedApiViewMixin, JsonApiViewMixin, ListAPIView):
permission_classes = [TenantConditionalOpenClose, ]
pagination_class = SkillPagination

def get_queryset(self):
lang = self.request.LANGUAGE_CODE or properties.LANGUAGE_CODE
return super().get_queryset().translated(lang).order_by('translations__name')


class SkillDetail(TranslatedApiViewMixin, JsonApiViewMixin, RetrieveAPIView):
serializer_class = SkillSerializer
Expand Down
8 changes: 4 additions & 4 deletions bluebottle/utils/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mimetypes
import os
import re
from io import BytesIO
from operator import attrgetter

Expand All @@ -15,7 +16,6 @@
from django.views.generic import TemplateView
from django.views.generic.base import View
from django.views.generic.detail import DetailView
from parler.utils.i18n import get_language
from rest_framework import generics
from rest_framework import views, response
from rest_framework.pagination import PageNumberPagination
Expand All @@ -32,7 +32,7 @@
from bluebottle.utils.permissions import ResourcePermission
from .models import Language
from .serializers import LanguageSerializer
import re
from .utils import get_current_language

mime = magic.Magic(mime=True)

Expand Down Expand Up @@ -233,8 +233,8 @@ def get_queryset(self):
class TranslatedApiViewMixin(object):
def get_queryset(self):
qs = super(TranslatedApiViewMixin, self).get_queryset().active_translations(
get_language()
)
get_current_language()
).distinct('id').order_by('id')
qs = qs.order_by(*qs.model._meta.ordering)
return qs

Expand Down

0 comments on commit 6e3e7a5

Please sign in to comment.