diff --git a/Dockerfile b/Dockerfile index 5643b3e..469694a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Use the official Python 3.11 image -FROM --platform=arm64 python:3.11.4-bookworm +# FROM --platform=arm64 python:3.11.4-bookworm # ARG BUILDPLATFORM -# FROM --platform=${BUILDPLATFORM} python:3.11.4-bookworm +FROM python:3.11.4-bookworm ENV PYTHONBUFFERED 1 diff --git a/stude/config/settings.py b/stude/config/settings.py index 44796a2..19281c7 100644 --- a/stude/config/settings.py +++ b/stude/config/settings.py @@ -267,17 +267,17 @@ LEAFLET_CONFIG = { REDIS_HOST = os.getenv('REDIS_HOST') REDIS_PORT = os.getenv('REDIS_PORT') - # Django Redis Cache -CACHES = { - "default": { - "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": "redis://redis:6379/0", - "OPTIONS": { - "CLIENT_CLASS": "django_redis.client.DefaultClient", - } - } -} +# CACHES = { +# "default": { +# "BACKEND": "django_redis.cache.RedisCache", +# "LOCATION": "redis://redis:6379/0", +# "OPTIONS": { +# "CLIENT_CLASS": "django_redis.client.DefaultClient", +# } +# } +# } + SESSION_ENGINE = "django.contrib.sessions.backends.cache" SESSION_CACHE_ALIAS = "default" diff --git a/stude/study_groups/urls.py b/stude/study_groups/urls.py index f8ea1f6..44c37c9 100644 --- a/stude/study_groups/urls.py +++ b/stude/study_groups/urls.py @@ -1,7 +1,8 @@ from django.urls import include, path -from .views import StudyGroupListView, StudyGroupMembershipViewSet +from .views import StudyGroupListView, StudyGroupListNearView, StudyGroupMembershipViewSet urlpatterns = [ path('', StudyGroupListView.as_view()), + path('near/', StudyGroupListNearView.as_view()), path('membership/', StudyGroupMembershipViewSet.as_view()), ] diff --git a/stude/study_groups/views.py b/stude/study_groups/views.py index aa70158..9894aee 100644 --- a/stude/study_groups/views.py +++ b/stude/study_groups/views.py @@ -5,6 +5,10 @@ from rest_framework.permissions import IsAuthenticated from .serializers import StudyGroupSerializer from .models import StudyGroup from subjects.models import Subject +from student_status.models import StudentStatus +from rest_framework import generics, viewsets, exceptions +from django.contrib.gis.geos import fromstr +from django.contrib.gis.db.models.functions import Distance # Create your views here. @@ -37,6 +41,42 @@ class StudyGroupListView(generics.ListAPIView): return studygroups +class StudyGroupListNearView(generics.ListAPIView): + permission_classes = [IsAuthenticated] + serializer_class = StudyGroupSerializer + queryset = StudyGroup.objects.all() + + def get_queryset(self): + user = self.request.user + user_status = StudentStatus.objects.filter(user=user).first() + user_location = fromstr( + user_status.location, srid=4326) + + if user_status.active is False: + raise exceptions.ValidationError("Student Status is not active") + + if not user.is_student: + raise PermissionDenied( + "You must be a student to view study groups" + ) + + # Get the user's course + user_course = user.course + print(user_course) + + # Get subject names related to the user's course + subject_names = Subject.objects.filter( + course=user_course + ).values_list('subject', flat=True) + + print(subject_names) + + # Now fetch the StudyGroups with the matching subject names that are within 50m + studygroups = StudyGroup.objects.filter(subject_name__in=subject_names).annotate( + distance=Distance('location', user_location)).filter(distance__lte=50) + return studygroups + + class StudyGroupMembershipViewSet(generics.ListAPIView): serializer_class = StudyGroupSerializer queryset = StudyGroup.objects.all()