change sql request for getPrivateMessageUser and add default profile picture for users
This commit is contained in:
@ -6,7 +6,7 @@ class User(models.Model):
|
|||||||
mail = models.EmailField(unique=True)
|
mail = models.EmailField(unique=True)
|
||||||
password = models.CharField(max_length=100)
|
password = models.CharField(max_length=100)
|
||||||
id42 = models.DecimalField(max_digits=15, decimal_places=0, null=True, unique=True)
|
id42 = models.DecimalField(max_digits=15, decimal_places=0, null=True, unique=True)
|
||||||
pfp = models.CharField(max_length=1024)
|
pfp = models.CharField(max_length=1024, default="/static/default_pfp.jpg")
|
||||||
|
|
||||||
class Message(models.Model):
|
class Message(models.Model):
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# By: edbernar <edbernar@student.42.fr> +#+ +:+ +#+ #
|
# By: edbernar <edbernar@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/08/03 15:10:23 by edbernar #+# #+# #
|
# Created: 2024/08/03 15:10:23 by edbernar #+# #+# #
|
||||||
# Updated: 2024/08/25 21:23:08 by tomoron ### ########.fr #
|
# Updated: 2024/08/26 20:07:57 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -59,7 +59,14 @@ def getPrivateListUser(socket, content=None):
|
|||||||
# (ceux qui ont eu conversation avec l'utilisateur)
|
# (ceux qui ont eu conversation avec l'utilisateur)
|
||||||
# Si user existe pas, faire ça : socket.sendError("User not found", 9008)
|
# Si user existe pas, faire ça : socket.sendError("User not found", 9008)
|
||||||
id = socket.scope["session"].get("id", 0)
|
id = socket.scope["session"].get("id", 0)
|
||||||
res = User.objects.raw("SELECT DISTINCT server_user.id AS id,'online' AS status, username, pfp FROM server_user RIGHT JOIN server_message ON server_message.to_id=server_user.id WHERE sender_id=%s;", [id])
|
request = """
|
||||||
|
SELECT DISTINCT server_user.id AS id,'online' AS status, username, pfp
|
||||||
|
FROM server_user
|
||||||
|
LEFT JOIN server_message AS sended ON sended.to_id=server_user.id
|
||||||
|
LEFT JOIN server_message AS received ON received.sender_id=server_user.id
|
||||||
|
WHERE sended.sender_id=%s OR received.to_id=%s;
|
||||||
|
"""
|
||||||
|
res = User.objects.raw(request,[id,id])
|
||||||
data = []
|
data = []
|
||||||
for x in res:
|
for x in res:
|
||||||
data.append({"name":x.username, "status":x.status, "pfp":x.pfp, "id":x.id})
|
data.append({"name":x.username, "status":x.status, "pfp":x.pfp, "id":x.id})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
INSERT INTO "server_user" ("username", "mail", "password", "id42", "pfp") VALUES
|
INSERT INTO "server_user" ("username", "mail", "password", "id42", "pfp") VALUES
|
||||||
('tomoron', 'a@a.com', 'a5f1efc32bcc4dc53e471f9620b78ca9', NULL, 'https://localhost/img.jpg'),
|
('tomoron', 'a@a.com', 'a5f1efc32bcc4dc53e471f9620b78ca9', NULL, '/static/default_pfp.jpg'),
|
||||||
('patate', 'b@b.com', '5e547979d3f20f43c87e5e0e8406f267', NULL, 'https://localhost/pfp.jpg');
|
('patate', 'b@b.com', '5e547979d3f20f43c87e5e0e8406f267', NULL, '/static/default_pfp.jpg');
|
||||||
|
|
||||||
INSERT INTO "server_message" ("date", "sender_id", "to_id", "content") VALUES
|
INSERT INTO "server_message" ("date", "sender_id", "to_id", "content") VALUES
|
||||||
('2024-08-25 18:10:54.27476+00', 1, 2, 'coucou'),
|
('2024-08-25 18:10:54.27476+00', 1, 2, 'coucou'),
|
||||||
|
@ -2,6 +2,5 @@ until pg_isready -h "$DB_HOST"; do sleep 0.5 ;echo "waiting for database";done
|
|||||||
cd /var/www/djangoserver/server
|
cd /var/www/djangoserver/server
|
||||||
python3.12 manage.py makemigrations server
|
python3.12 manage.py makemigrations server
|
||||||
python3.12 manage.py migrate
|
python3.12 manage.py migrate
|
||||||
python3.12 manage.py collectstatic
|
|
||||||
#python3 manage.py runserver 0.0.0.0:8000
|
#python3 manage.py runserver 0.0.0.0:8000
|
||||||
daphne -p 8000 -b 0.0.0.0 server.asgi:application
|
daphne -p 8000 -b 0.0.0.0 server.asgi:application
|
||||||
|
BIN
docker-compose/requirements/nginx/static/img/default_pfp.jpg
Normal file
BIN
docker-compose/requirements/nginx/static/img/default_pfp.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
Reference in New Issue
Block a user