handle deleted user in stats
This commit is contained in:
@ -8,7 +8,7 @@ class User(models.Model):
|
|||||||
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, default="/static/img/default_pfp.jpg")
|
pfp = models.CharField(max_length=1024, default="/static/img/default_pfp.jpg")
|
||||||
banner = models.CharField(max_length=1024, default="/static/img/default_banner.jpg")
|
banner = models.CharField(max_length=1024, default="/static/img/default_banner.jpg")
|
||||||
mail_verified = models.BooleanField(default=True)
|
mail_verified = models.BooleanField(default=False)
|
||||||
github_link = models.CharField(max_length=1024, null=True, blank=True, default=None)
|
github_link = models.CharField(max_length=1024, null=True, blank=True, default=None)
|
||||||
discord_username = models.CharField(max_length=1024, null=True, blank=True, default=None)
|
discord_username = models.CharField(max_length=1024, null=True, blank=True, default=None)
|
||||||
last_login = models.DateTimeField()
|
last_login = models.DateTimeField()
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/09/20 00:16:57 by edbernar #+# #+# #
|
# Created: 2024/09/20 00:16:57 by edbernar #+# #+# #
|
||||||
# Updated: 2024/11/20 13:57:49 by tomoron ### ########.fr #
|
# Updated: 2024/11/20 14:39:07 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -24,9 +24,15 @@ def getHistory(user, games):
|
|||||||
opponent = None
|
opponent = None
|
||||||
if(x.player1 == user):
|
if(x.player1 == user):
|
||||||
player = {"score":int(x.p1Score)}
|
player = {"score":int(x.p1Score)}
|
||||||
|
if(x.player2 == None):
|
||||||
|
opponent = {"score":int(x.p2Score), "username": "[deleted]", "pfp": "/static/img/default_pfp.jpg"}
|
||||||
|
else:
|
||||||
opponent = {"score":int(x.p2Score), "username":x.player2.username, "pfp":x.player2.pfp}
|
opponent = {"score":int(x.p2Score), "username":x.player2.username, "pfp":x.player2.pfp}
|
||||||
else:
|
else:
|
||||||
player = {"score":int(x.p2Score)}
|
player = {"score":int(x.p2Score)}
|
||||||
|
if(x.player1 == None):
|
||||||
|
opponent = {"score":int(x.p2Score), "username": "[deleted]", "pfp": "/static/img/default_pfp.jpg"}
|
||||||
|
else:
|
||||||
opponent = {"score":int(x.p1Score), "username":x.player1.username, "pfp":x.player1.pfp}
|
opponent = {"score":int(x.p1Score), "username":x.player1.username, "pfp":x.player1.pfp}
|
||||||
res.append({
|
res.append({
|
||||||
"id":x.id,
|
"id":x.id,
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/08/04 13:44:11 by edbernar #+# #+# #
|
# Created: 2024/08/04 13:44:11 by edbernar #+# #+# #
|
||||||
# Updated: 2024/11/20 14:20:37 by tomoron ### ########.fr #
|
# Updated: 2024/11/20 14:49:59 by tomoron ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -17,14 +17,13 @@ import json
|
|||||||
|
|
||||||
@sync_to_async
|
@sync_to_async
|
||||||
def sendPrivateMessage(socket, content):
|
def sendPrivateMessage(socket, content):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
dest = User.objects.filter(id=content["to"])
|
dest = User.objects.filter(id=content["to"])
|
||||||
if(not dest.exists()):
|
if(not dest.exists()):
|
||||||
socket.sendError("User not found", 9008)
|
socket.sendError("User not found", 9008)
|
||||||
return
|
return
|
||||||
user = User.objects.filter(id=socket.id)
|
user = User.objects.filter(id=socket.id)
|
||||||
if(int(content["to"]) == user[0].id or len(content["content"]) == 0 or len(content["content"] > 2000)):
|
if(int(content["to"]) == user[0].id or len(content["content"]) == 0 or len(content["content"]) > 2000):
|
||||||
socket.sendError("Invalid message sent", 9009)
|
socket.sendError("Invalid message sent", 9009)
|
||||||
new_msg = Message.objects.create(sender=user[0], to=dest[0], content=content["content"])
|
new_msg = Message.objects.create(sender=user[0], to=dest[0], content=content["content"])
|
||||||
new_msg.save()
|
new_msg.save()
|
||||||
|
Reference in New Issue
Block a user