This commit is contained in:
rizwanisready
2024-03-10 17:17:08 +05:30
parent c37592fb44
commit 34d60bf735
12 changed files with 67 additions and 41 deletions

View File

@@ -6,10 +6,10 @@ app_name = "chat_api"
urlpatterns = [
path("<str:room_name>/", views.EnterRoomApi.as_view(), name="enter_room"),
path(
"chat_group/<int:game_id>/", views.ChatGroupAPIView.as_view(), name="chat_group"
"chat_group/<int:event_id>/", views.ChatGroupAPIView.as_view(), name="chat_group"
),
path(
"chat_messages/<str:game_name>/",
"chat_messages/<str:event_name>/",
views.ChatMessageAPIView.as_view(),
name="chat_messages",
),

View File

@@ -28,8 +28,8 @@ class ChatGroupAPIView(APIView):
authentication_classes = [JWTAuthentication]
permission_classes = [IsAuthenticated]
def get(self, request, game_id):
group_name = f"game_{game_id}"
def get(self, request, event_id):
group_name = f"event_{event_id}"
chat_group, created = models.ChatGroup.objects.get_or_create(name=group_name)
serializer = serializers.ChatGroupSerializer(chat_group)
@@ -52,8 +52,8 @@ class ChatMessageAPIView(generics.ListAPIView):
pagination_class = CustomPagination
def get_queryset(self):
game_name = f"game_{self.kwargs['game_name']}"
return models.ChatMessage.objects.filter(group__name=game_name).order_by(
event_name = f"event_{self.kwargs['event_name']}"
return models.ChatMessage.objects.filter(group__name=event_name).order_by(
"-timestamp"
)

View File

@@ -22,7 +22,7 @@ class ChatConsumer(AsyncWebsocketConsumer):
self.scope.get("url_route", {}).get("kwargs", {}).get("room_name")
)
print("self.room_name: ", self.room_name)
token_key = self.scope["url_route"]["kwargs"]["user"]
token_key = self.scope["url_route"]["kwargs"]["token"]
print("token_key: ", token_key)
self.user = await self.get_user_async(token_key)
print("self.user: ", self.user)

View File

@@ -28,4 +28,4 @@ class ChatMessage(models.Model):
)
def __str__(self):
return self.group
return f"{self.user} - {self.message}"

View File

@@ -1,8 +1,9 @@
from django.urls import re_path, path
from django.urls import path, re_path
from . import consumers
websocket_urlpatterns = [
path("ws/chat/<str:room_name>/<str:user>", consumers.ChatConsumer.as_asgi()),
# path("ws/chat/<str:room_name>/<str:token>", consumers.ChatConsumer.as_asgi()),
re_path(r'^ws/chat/(?P<room_name>\w+)/(?P<token>[^/]+)/$', consumers.ChatConsumer.as_asgi()),
# path("ws/chat/<str:room_name>", consumers.ChatConsumer.as_asgi()),
]

View File

@@ -8,9 +8,17 @@ https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
"""
import os
from django.urls import path
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from chat.routing import websocket_urlpatterns
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "goodtimes.settings")
application = get_asgi_application()
django_asgi_app = get_asgi_application()
application = ProtocolTypeRouter(
{
"http": django_asgi_app,
"websocket": URLRouter(websocket_urlpatterns),
}
)

View File

@@ -387,24 +387,28 @@ class InteractionCalculator:
class EventFilterService:
@staticmethod
def filter_events_by_search(query):
def filter_events_by_search(search_query=None):
today = timezone.now().date()
# Basic search filtering on title and key_guest, excluding deleted and draft events
events = Event.objects.filter(
Q(title__icontains=query) | Q(key_guest__icontains=query),
deleted=False, # Assuming there's a `deleted` field to check if an event is deleted
active=True, # Assuming there's an `active` field to check if an event is active
draft=False, # Assuming there's a `draft` field to filter out drafts
filtered_events = Event.objects.filter(
key_guest__isnull=False,
deleted=False,
active=True,
draft=False
)
# Further filtering to ensure only current and future events are considered
current_and_future_events_query = Q(active=True, deleted=False) & (
Q(start_date__lte=today, end_date__gte=today) | Q(start_date__gt=today)
)
events = events.filter(current_and_future_events_query).distinct()
# Optional search filtering on title and key_guest (modify as needed)
if search_query:
filtered_events = filtered_events.filter(
Q(title__icontains=search_query) | Q(key_guest__icontains=search_query)
)
return events
# Filter for current, future, or ongoing events
current_and_future_events_query = Q(
start_date__lte=today, end_date__gte=today
) | Q(start_date__gt=today)
filtered_events = filtered_events.filter(current_and_future_events_query).distinct()
return filtered_events
@staticmethod
def filter_events(filter_type, principal=None):

View File

@@ -306,7 +306,7 @@ CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
# "hosts": [("192.168.29.219", 6379)],
# "hosts": [("192.168.0.101", 6379)],
"hosts": [("127.0.0.1", 6379)],
},
},

View File

@@ -47,8 +47,8 @@ urlpatterns = [
path("communications/", include("manage_communications.urls")),
path('api/communications/', include("manage_communications.api.urls")),
# path('chat/', include('chat.urls')),
# path('api/chat/', include("chat.api.urls")),
path('chat/', include('chat.urls')),
path('api/chat/', include("chat.api.urls")),
path("subscriptions/", include("manage_subscriptions.urls")),
path("api/subscriptions/", include("manage_subscriptions.api.urls")),

View File

@@ -23,6 +23,7 @@ class EventMasterAdmin(admin.ModelAdmin):
class EventAdmin(admin.ModelAdmin):
list_display = (
"id",
"title",
"category",
"event_master",

View File

@@ -9,6 +9,7 @@ from accounts.models import IAmPrincipalLocation
from accounts.permission import IsOwnerOrReadOnly
from goodtimes import constants
from django.db.models import Q
from django.utils.dateparse import parse_date
from goodtimes import services
from goodtimes.utils import ApiResponse, CapacityError
from rest_framework.permissions import IsAuthenticated
@@ -115,7 +116,7 @@ class EventsAPIView(APIView):
"today",
"tomorrow",
"category",
"search",
"key_guest",
]
if filter not in params:
return ApiResponse.error(
@@ -129,8 +130,10 @@ class EventsAPIView(APIView):
events = services.EventFilterService.filter_events_for_today()
elif filter == "tomorrow":
events = services.EventFilterService.filter_events_for_tomorrow()
elif filter == "search":
events = services.EventFilterService.filter_events_by_search(query)
elif filter == "key_guest":
events = services.EventFilterService.filter_events_by_search(
search_query=query
)
elif filter == "category" and category_id is not None:
events = services.EventFilterService.filter_events_by_category(
int(category_id)
@@ -291,7 +294,9 @@ class VenueDetailView(generics.RetrieveUpdateDestroyAPIView):
def get_queryset(self):
# This ensures a user can only access their own venues
return self.queryset.filter(created_by=self.request.user, deleted=False, active=True)
return self.queryset.filter(
created_by=self.request.user, deleted=False, active=True
)
class GeocodeAPIView(APIView):
@@ -620,17 +625,24 @@ class EventDateRangeAPIView(APIView):
permission_classes = [IsAuthenticated]
def get(self, request, *args, **kwargs):
serializer = EventDateRangeSerializer(data=request.data)
if not serializer.is_valid():
start_date_str = request.query_params.get("start_date")
end_date_str = request.query_params.get("end_date")
# Attempt to parse the dates from the query parameters
start_date = parse_date(start_date_str)
end_date = parse_date(end_date_str)
# Validate the parsed dates
if not start_date or not end_date:
return ApiResponse.error(
errors=serializer.errors,
errors={
"start_date": "Invalid or missing",
"end_date": "Invalid or missing",
},
message=constants.FAILURE,
status=status.HTTP_400_BAD_REQUEST,
)
start_date = serializer.validated_data["start_date"]
end_date = serializer.validated_data["end_date"]
events = Event.objects.filter(
Q(end_date__gte=start_date)
& Q(start_date__lte=end_date)

View File

@@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no">
<title>Nifty11 </title>
<title> Good Times Ltd </title>
{% load static %}
<link rel="icon" type="image/x-icon" href="../src/assets/img/favicon.ico"/>
<link href="../layouts/collapsible-menu/css/light/loader.css" rel="stylesheet" type="text/css" />