Skip to content

Commit

Permalink
Opti, champs manquants
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Gombert authored and Lgt2x committed Jun 6, 2021
1 parent b0c41e2 commit fc38d3c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 2 additions & 0 deletions mobi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 7 additions & 5 deletions mobi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Model serializers go here...

class CommentSerializer(ModelSerializer):
email_perm = ReadOnlyField()
class Meta:
model = ExchangeReview
fields = (
Expand All @@ -13,7 +14,10 @@ class Meta:
'surname',
'year',
'semester',
'datetime',
'email_perm',
'mobility_type',
'univ_appartment',
'visa'
)


Expand Down Expand Up @@ -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
Expand All @@ -122,8 +124,8 @@ class Meta:
'name',
'city_name',
'country_name',
'placesExchange',
'placesDD'
'latitude',
'longitude'
)


Expand Down
21 changes: 10 additions & 11 deletions mobi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit fc38d3c

Please sign in to comment.