-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expanded actions for friends to allow for invitations to games, invitations to tournaments #199
Open
ishiii-s
wants to merge
25
commits into
dev
Choose a base branch
from
users/friends-actions
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
cd62f2f
Update urls.py for remove, tournament, and game paths
ishiii-s c75d6aa
Wrote invitation classes for match and tournament
ishiii-s aa4bf56
Wrote functions to remove friend, invite to game, and invite to tourn…
ishiii-s 1b4bf2d
Update Tournament and Match definitions in views.py
ishiii-s 68266dc
Update models.py to deal with circular dependencies
ishiii-s c484edb
Merge branch 'dev' into users/friends-actions
ishiii-s b485e33
Update models.py to try to fix circular imports
ishiii-s a45bf4b
Attempt to fix error for invalid model reference
ishiii-s 418205c
Remove remove friend functionality
24raniwalar bb34f6e
Forgot to remove url
24raniwalar f7bc774
Needed to migrate
24raniwalar 26278aa
Merge branch 'dev' into users/friends-actions
ishiii-s a4b7378
Fix resulting errors from resolve merge conflicts urls.py
ishiii-s 56fe98c
Merge branch 'dev' into users/friends-actions
AndrewM131 6fa6bfa
fixed merge conflicts
6b34dec
fixed linting issues
5cedea3
fixed pytest issues
2469b37
fixed merge
a330f31
fixed lint
60c3102
added try/except and pk to url
b6dc528
Merge branch 'dev' into users/friends-actions
5e0476e
fixed pk
55ead9c
working tournament invite now
a1e9f5e
Merge branch 'dev' into users/friends-actions
5849ec5
fixed accidentally modified url path
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/chigame/users/migrations/0004_tournamentinvitation_gameinvitation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Generated by Django 4.2.4 on 2023-12-03 02:40 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("games", "0016_update_tournaments_2"), | ||
("users", "0003_merge_20231115_1525"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="TournamentInvitation", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("accepted", models.BooleanField(default=False)), | ||
("timestamp", models.DateTimeField(auto_now_add=True)), | ||
( | ||
"receiver", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="tournament_invitations_received", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
( | ||
"sender", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="tournament_invitations_sent", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
("tournament", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="games.tournament")), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="GameInvitation", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("accepted", models.BooleanField(default=False)), | ||
("timestamp", models.DateTimeField(auto_now_add=True)), | ||
("match", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="games.match")), | ||
( | ||
"receiver", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="game_invitations_received", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
( | ||
"sender", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="game_invitations_sent", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ | |
from rest_framework import status | ||
from rest_framework.response import Response | ||
|
||
from .models import FriendInvitation, Notification, UserProfile | ||
from chigame.games.models import Match, Tournament | ||
|
||
from .models import FriendInvitation, GameInvitation, Notification, TournamentInvitation, UserProfile | ||
from .tables import UserTable | ||
|
||
User = get_user_model() | ||
|
@@ -159,6 +161,25 @@ def cancel_friend_invitation(request, pk): | |
|
||
|
||
@login_required | ||
def invite_to_game(request, pk, match_id): | ||
sender = User.objects.get(pk=request.user.id) | ||
receiver = User.objects.get(pk=pk) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything should be in a try statement because there is no error handling for if the receiver or match don't exist. Same goes for tournament |
||
match = Match.objects.get(pk=match_id) | ||
GameInvitation.objects.create(sender=sender, receiver=receiver, match=match) | ||
messages.success(request, "Invitation to game sent successfully.") | ||
return redirect(reverse("users:user-profile", kwargs={"pk": request.user.pk})) | ||
|
||
|
||
@login_required | ||
def invite_to_tournament(request, pk, tournament_id): | ||
sender = User.objects.get(pk=request.user.id) | ||
receiver = User.objects.get(pk=pk) | ||
tournament = Tournament.objects.get(pk=tournament_id) | ||
TournamentInvitation.objects.create(sender=sender, receiver=receiver, tournament=tournament) | ||
messages.success(request, "Invitation to tournament sent successfully.") | ||
return redirect(reverse("users:user-profile", kwargs={"pk": request.user.pk})) | ||
|
||
|
||
def accept_friend_invitation(request, pk): | ||
try: | ||
friendship = FriendInvitation.objects.get(pk=pk) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these urls are correct because they don't have the pk for the match which is needed for the view