From fc38d3cbed6ebd958c84b1f4f80db633695ab65e Mon Sep 17 00:00:00 2001 From: Louis Gombert Date: Sun, 6 Jun 2021 19:21:30 +0200 Subject: [PATCH] Opti, champs manquants --- mobi/models.py | 2 ++ mobi/serializers.py | 12 +++++++----- mobi/views.py | 21 ++++++++++----------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/mobi/models.py b/mobi/models.py index c2c0cf9..7e5e7ac 100644 --- a/mobi/models.py +++ b/mobi/models.py @@ -381,6 +381,8 @@ class ExchangeReview(models.Model): verbose_name="Type de mobilité", ) + def email_perm(self): + return self.email if self.contact else '' univ_appartment = models.BooleanField(verbose_name="Appartements disponibles sur le campus") rent = models.IntegerField(blank=True, null=True, verbose_name="Approximation du loyer") diff --git a/mobi/serializers.py b/mobi/serializers.py index 94637cf..3a52636 100644 --- a/mobi/serializers.py +++ b/mobi/serializers.py @@ -5,6 +5,7 @@ # Model serializers go here... class CommentSerializer(ModelSerializer): + email_perm = ReadOnlyField() class Meta: model = ExchangeReview fields = ( @@ -13,7 +14,10 @@ class Meta: 'surname', 'year', 'semester', - 'datetime', + 'email_perm', + 'mobility_type', + 'univ_appartment', + 'visa' ) @@ -112,8 +116,6 @@ class Meta: class UniversityShortSerializer(ModelSerializer): city_name = ReadOnlyField() country_name = ReadOnlyField() - placesExchange = PlacesExchangeSerializer(many=True, read_only=True) - placesDD = PlacesDDSerializer(many=True, read_only=True) class Meta: model = University @@ -122,8 +124,8 @@ class Meta: 'name', 'city_name', 'country_name', - 'placesExchange', - 'placesDD' + 'latitude', + 'longitude' ) diff --git a/mobi/views.py b/mobi/views.py index 793dc13..8a580c5 100644 --- a/mobi/views.py +++ b/mobi/views.py @@ -60,33 +60,32 @@ def search(request): if 'country' in request.data: uni_country = request.data['country'] queryset = queryset.filter(city__country__name__icontains=uni_country) - if 'nightlife_min' in request.data: + if 'nightlife_min' in request.data and request.data['nightlife_min'] > 0: uni_nightlife_min = request.data['nightlife_min'] - id_univ = [university.id for university in University.objects.all() + id_univ = [university.id for university in queryset if university.night_life()['night_life__avg'] >= uni_nightlife_min] queryset = queryset.filter(id__in=id_univ) - if 'course_difficulty' in request.data: + if 'course_difficulty' in request.data and request.data['course_difficulty'] > 0: uni_courses_diff = request.data['course_difficulty'] - id_univ = [university.id for university in University.objects.all() + id_univ = [university.id for university in queryset if university.courses_difficulty()['courses_difficulty__avg'] >= uni_courses_diff] queryset = queryset.filter(id__in=id_univ) - if 'uni_cultural_min' in request.data: + if 'uni_cultural_min' in request.data and request.data['uni_cultural_min'] > 0: uni_cultural_min = request.data['uni_cultural_min'] - id_univ = [university.id for university in University.objects.all() + id_univ = [university.id for university in queryset if university.culture()['culture__avg'] >= uni_cultural_min] queryset = queryset.filter(id__in=id_univ) if 'department_availability' in request.data and request.data['department_availability'] != 'all': dep = request.data['department_availability'] - id_dep_available = [university.id for university in University.objects.all() if dep in university.department()] + id_dep_available = [university.id for university in queryset if dep in university.department()] queryset = queryset.filter(id__in=id_dep_available) - if 'cost_living_grade_min' in request.data: + if 'cost_living_grade_min' in request.data and request.data['cost_living_grade_min'] > 0: uni_cost_living_grade_min = request.data['cost_living_grade_min'] - id_univ = [university.id for university in University.objects.all() if university.cost_of_living()['cost_of_living__avg'] >= uni_cost_living_grade_min] + id_univ = [university.id for university in queryset if university.cost_of_living()['cost_of_living__avg'] >= uni_cost_living_grade_min] queryset = queryset.filter(id__in=id_univ) - serializer = UniversitySerializer(queryset, many=True) + serializer = UniversityShortSerializer(queryset, many=True) print(len(queryset)) - # print(serializer.data) return Response(serializer.data)