-
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
base: dev
Are you sure you want to change the base?
Changes from 3 commits
cd62f2f
c75d6aa
aa4bf56
1b4bf2d
68266dc
c484edb
b485e33
a45bf4b
418205c
bb34f6e
f7bc774
26278aa
a4b7378
56fe98c
6fa6bfa
6b34dec
5cedea3
2469b37
a330f31
60c3102
b6dc528
5e0476e
55ead9c
a1e9f5e
5849ec5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
from django.utils.translation import gettext_lazy as _ | ||
from django.views.generic import DetailView, RedirectView, UpdateView | ||
|
||
from .models import FriendInvitation, Notification, UserProfile | ||
from .models import FriendInvitation, Notification, UserProfile, GameInvitation, TournamentInvitation | ||
|
||
User = get_user_model() | ||
|
||
|
@@ -120,3 +120,31 @@ def cancel_friend_invitation(request, pk): | |
else: | ||
messages.error(request, "Something went wrong please try again later!") | ||
return redirect(reverse("users:user-profile", kwargs={"pk": request.user.pk})) | ||
|
||
|
||
@login_required | ||
def remove_friend(request, pk): | ||
sender = User.objects.get(pk=request.user.id) | ||
receiver = User.objects.get(pk=pk) | ||
sender_profile = sender.profile | ||
sender_profile.friends.remove(receiver) | ||
messages.success(request, "Friend removed successfully.") | ||
return redirect(reverse("users:user-profile", kwargs={"pk": request.user.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 = User.objects.get(pk=match_id) | ||
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. when defining match, I think you defined it incorrectly, and it should be Match.objects instead of User.objects, as the User model doesn't have a match_id |
||
GameInvitation.objects.create(sender=sender, receiver=receiver, group=group, match=match) | ||
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. When did you define group in the function? Currently it isn't defined, and may be why you aren't passing the checks. |
||
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 = User.objects.get(pk=tournament_id) | ||
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. Same thing here where it should be Tournament.obkects instead of User.objects , as the User model doesn't have a 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})) |
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