Skip to content

Commit

Permalink
Mutiple users
Browse files Browse the repository at this point in the history
  • Loading branch information
KunalSolanke committed Jun 23, 2020
1 parent d504a5e commit dd972a5
Show file tree
Hide file tree
Showing 88 changed files with 891 additions and 298 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
# testing
/coverage

/.env
# production
/build



# misc
.DS_Store
.env.local
Expand Down
Binary file modified Cabsharing/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified Cabsharing/__pycache__/routing.cpython-37.pyc
Binary file not shown.
Binary file modified Cabsharing/__pycache__/settings.cpython-37.pyc
Binary file not shown.
Binary file removed Cabsharing/__pycache__/wsgi.cpython-37.pyc
Binary file not shown.
31 changes: 25 additions & 6 deletions Cabsharing/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,44 @@

# setting my backend as postgres

# DATABASES = {
# 'default': {
# #'ENGINE': 'django.db.backends.sqlite3',
# #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# 'ENGINE': 'django.db.backends.postgresql',
# 'NAME': 'd5694qn4pfsgnb',
# 'USER' : 'pkozjzangfvkux' ,
# 'PASSWORD': '95932083794db167040e65833aca9d7a96eefe691df7e330d649f483d49749bd' ,

# # 'TEST': {
# # 'NAME': 'chattests'
# # },
# 'HOST':'ec2-54-175-117-212.compute-1.amazonaws.com'
# }
# }

DATABASES = {
'default': {
'default': {
#'ENGINE': 'django.db.backends.sqlite3',
#'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'd5694qn4pfsgnb',
'USER' : 'pkozjzangfvkux' ,
'PASSWORD': '95932083794db167040e65833aca9d7a96eefe691df7e330d649f483d49749bd' ,
# 'NAME': 'd5694qn4pfsgnb',
'NAME':'cabsharing',
# 'USER' : 'pkozjzangfvkux' ,
'USER':'postgres',
# 'PASSWORD': '95932083794db167040e65833aca9d7a96eefe691df7e330d649f483d49749bd' ,
'PASSWORD':'1234',

# 'TEST': {
# 'NAME': 'chattests'
# },
'HOST':'ec2-54-175-117-212.compute-1.amazonaws.com'
# 'HOST':'ec2-54-175-117-212.compute-1.amazonaws.com'
'HOST':'localhost'
}
}




# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

Expand Down
Binary file modified Humrahi/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified Humrahi/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file modified Humrahi/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file removed Humrahi/__pycache__/pyrebase_set.cpython-37.pyc
Binary file not shown.
Binary file removed Humrahi/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file removed Humrahi/__pycache__/views.cpython-37.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Humrahi/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.0.4 on 2020-04-07 09:09
# Generated by Django 3.0.4 on 2020-06-22 13:27

import django.contrib.auth.models
import django.contrib.auth.validators
Expand Down
Binary file modified Humrahi/migrations/__pycache__/0001_initial.cpython-37.pyc
Binary file not shown.
Binary file modified Humrahi/migrations/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified Notifications/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified Notifications/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file modified Notifications/__pycache__/consusmers.cpython-37.pyc
Binary file not shown.
Binary file modified Notifications/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file modified Notifications/__pycache__/routing.cpython-37.pyc
Binary file not shown.
94 changes: 68 additions & 26 deletions Notifications/consusmers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
class NoteConsumer(WebsocketConsumer) :

def fetch_notifications(self,data):

notifications = Notification.objects.filter(To__username = data['username']

).order_by('-publish_time')[:20]
user = User.objects.filter(username=data['username'])
notifications = Notification.objects.filter(To__in = user
).order_by('-publish_time')[:20]

print(data['username'])
print(notifications)


context ={
'command': 'notifications',
Expand All @@ -38,12 +41,6 @@ def new_notification(self,data) :

#Todo this is for multiple users in the ride

# if Booked_rides.objects.get(pk=data['bookfromid']).exits() :
# ride=Booked_rides.objects.get(pk=data['bookfromid'])
# ride.bookings.add(bookings1)
# if(len(ride.bookings))==4 :
# ride.is_complete=True ;
# ride.save()

# else :
# ride=Booked_rides.objects.create(is_complete=False)
Expand All @@ -56,26 +53,65 @@ def new_notification(self,data) :


author_user = User.objects.get(username = data['from'])
to_user = User.objects.get(username=data['to'])
notification = Notification.objects.create(From=author_user,To=to_user
notification = Notification.objects.create(From=author_user
,notification =data['notification'],notification_type = data['type'])


if data['type'] == 'confirm':
print(data)
if Booked_rides.objects.filter(pk=data['booktoid']).exists() :
try:
ride=Booked_rides.objects.get(pk=data['booktoid'])
to=ride.users
u=User.objects.get(username=data['to'])
ride.users.add(u)
book=Bookings.objects.get(pk=data['bookfromid'])
ride.bookings.add(book)
notification.To.add(to)
notification.save()
ride.total+=1
if ride.total==4 :
ride.is_complete=True ;
ride.save()
except:
return
else :
to_user = User.objects.get(username=data['to'])
bookings1= Bookings.objects.get(pk = data['bookfromid'])
bookings2= Bookings.objects.get(pk = data['booktoid'])
ride =Booked_rides.objects.create(is_complete=False)
ride.users.add(to_user)
ride.users.add(author_user)
ride.bookings.add(bookings1)
ride.bookings.add(bookings2)
ride.total=2
if ride.total==4:
ride.is_complete=True

ride.save()
bookfrom = Bookings.objects.get(pk = data['bookfromid'])
bookfrom.is_booked= True
bookfrom.save()
bookto= Bookings.objects.get(pk = data['booktoid'])
bookto.is_booked= True
bookto.save()
notification.To.set(ride.users.all().exclude(username=data['from']))
notification.save()
else :
if Booked_rides.objects.filter(pk=data['booktoid']).exists():
ride=Booked_rides.objects.get(pk=data['booktoid'])
to=ride.users
for u in ride.users.all() :
notification.To.add(u)
notification.save()

else :
print(data['to'])
to_user = User.objects.get(username=data['to'])

notification.To.add(to_user)
notification.save()

bookings1= Bookings.objects.get(pk = data['bookfromid'])
bookings2= Bookings.objects.get(pk = data['booktoid'])
ride =Booked_rides.objects.create(is_matched=True,bookings1= bookings1,bookings2= bookings2)
ride.user1.add(author_user)
ride.user2.add(to_user)
ride.is_matched = True
ride.save()
bookfrom = Bookings.objects.get(pk = data['bookfromid'])
bookfrom.is_booked= True
bookfrom.save()
bookto= Bookings.objects.get(pk = data['booktoid'])
bookto.is_booked= True
bookto.save()



Expand Down Expand Up @@ -104,9 +140,15 @@ def messages_to_json(self,notifications) :


def message_to_json(self,notification):
sendingto=[]
print(notification.To.all())
for user in notification.To.all():

sendingto.append(user.username)
print(sendingto)
return {
'id':notification.id,
'to':notification.To.username,
'to':sendingto,
'author':notification.From.username ,
'content':notification.notification,
'timestamp':str(notification.timestamp),
Expand Down
5 changes: 3 additions & 2 deletions Notifications/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.0.4 on 2020-04-11 17:27
# Generated by Django 3.0.4 on 2020-06-22 14:41

from django.conf import settings
from django.db import migrations, models
Expand All @@ -21,8 +21,9 @@ class Migration(migrations.Migration):
('timestamp', models.DateTimeField(auto_now=True)),
('publish_time', models.DateTimeField(auto_now_add=True)),
('notification', models.TextField(blank=True)),
('notification_type', models.CharField(blank=True, max_length=10)),
('From', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='from1', to=settings.AUTH_USER_MODEL)),
('To', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='to2', to=settings.AUTH_USER_MODEL)),
('To', models.ManyToManyField(related_name='to2', to=settings.AUTH_USER_MODEL)),
],
),
]
18 changes: 0 additions & 18 deletions Notifications/migrations/0002_notification_notification_type.py

This file was deleted.

Binary file modified Notifications/migrations/__pycache__/0001_initial.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file modified Notifications/migrations/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
7 changes: 4 additions & 3 deletions Notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Notification(models.Model) :
From = models.ForeignKey(settings.AUTH_USER_MODEL,related_name='from1',on_delete= models.CASCADE)
To = models.ForeignKey(settings.AUTH_USER_MODEL,related_name='to2',on_delete= models.CASCADE)
To = models.ManyToManyField(settings.AUTH_USER_MODEL,related_name='to2')
timestamp = models.DateTimeField(auto_now=True)
publish_time =models.DateTimeField(auto_now_add=True)
notification = models.TextField(blank= True)
Expand All @@ -26,8 +26,9 @@ def __str__(self) :
@receiver(post_save,sender=settings.AUTH_USER_MODEL)
def create_notification(sender,instance,created,**kwargs) :
if created :
Notification.objects.create(From= User.objects.get(pk=1),To=instance,notification='Welcome User!THis is A Cab Sharing Site For IITG campus')

notification= Notification.objects.create(From= User.objects.get(pk=1),notification='Welcome User!THis is A Cab Sharing Site For IITG campus')
notification.To.add(instance)
notification.save()
# @receiver(post_save,sender=settings.AUTH_USER_MODEL)
# def update_profile(sender,instance,created,**kwargs) :
# try:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ Humraahi is a Cab sharing Website for IIT-G Campus.
1.There is one major issue currently only two people share the ride.


-I have added the code in comments to change it to multiple users but have not tested
-I have added the code in respective to change it to multiple users but needs to be tested

these changes are in :
1.Booking model user/models
2.Matchlist view users/userapi/views
3.Notifications model and consumer Notifications/models and Notifications/consumers
4.Booked_ride model user/models
[*] 1.Booking model user/models
[*] 2.Matchlist view users/userapi/views
[*] 3.Notifications model and consumer Notifications/models and Notifications/consumers
[*]4.Booked_ride model user/models




on frontend not much
Needs frontend improvement in ui



Expand Down
Binary file modified chatService/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified chatService/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file modified chatService/__pycache__/consumers.cpython-37.pyc
Binary file not shown.
Binary file modified chatService/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file modified chatService/__pycache__/routing.cpython-37.pyc
Binary file not shown.
Binary file removed chatService/__pycache__/tests.cpython-37.pyc
Binary file not shown.
Binary file removed chatService/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file modified chatService/__pycache__/views.cpython-37.pyc
Binary file not shown.
Binary file modified chatService/api/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file modified chatService/api/__pycache__/views.cpython-37.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions chatService/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework.routers import DefaultRouter
from .views import ChatView
from django.urls import path,re_path

from django.urls import path,re_path,include
from django.conf.urls import url
router = DefaultRouter()
router.register(r'(?P<username>.+)/chats',ChatView,basename='chats')
urlpatterns = router.urls
urlpatterns = [url('',include(router.urls))]
2 changes: 1 addition & 1 deletion chatService/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ChatView(viewsets.ModelViewSet) :
def get_queryset(self) :
username = self.kwargs['username']
# username = self.request.query_params.get('username',None)

print('query')
contact = get_user_contact(username)
queryset= contact.chats.all()

Expand Down
28 changes: 25 additions & 3 deletions chatService/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .views import get_last_10_messages,get_user_contact,get_curent_chat
# from user.models import Message


from Humrahi.models import User
#User=settings.AUTH_USER_MODEL

class ChatConsumer(WebsocketConsumer):
Expand All @@ -25,8 +25,28 @@ def fetch_messages(self,data):



def typing(self,data) :
person = User.objects.get(username=data['username'])

context ={
'command':'typing',
'type':data['type'],
'message':{
'name':person.username
}
}
self.send_chat_message(context)


def online(self,data) :
person= User.objects.get(username=data['username'])
context ={
'command':'online',
'message':{
'name':person.username
}
}
self.send_chat_message(context)



Expand Down Expand Up @@ -69,8 +89,10 @@ def message_to_json(self,message):

commands ={
'fetch_messages': fetch_messages,
'new_message' : new_messages
}
'new_message' : new_messages,
'online':online,
'typing':typing
}

def connect(self):
self.room_name = self.scope['url_route']['kwargs']['room_name']
Expand Down
4 changes: 2 additions & 2 deletions chatService/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.0.4 on 2020-04-07 09:10
# Generated by Django 3.0.4 on 2020-06-22 14:42

from django.conf import settings
from django.db import migrations, models
Expand Down Expand Up @@ -36,7 +36,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('messages', models.ManyToManyField(blank=True, to='chatService.Messages')),
('participants', models.ManyToManyField(related_name='chats', to=settings.AUTH_USER_MODEL)),
('participants', models.ManyToManyField(related_name='chats', to='chatService.Contact')),
],
),
]
18 changes: 0 additions & 18 deletions chatService/migrations/0002_auto_20200407_1619.py

This file was deleted.

Binary file modified chatService/migrations/__pycache__/0001_initial.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file modified chatService/migrations/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Loading

0 comments on commit dd972a5

Please sign in to comment.