Add tests for accounts, and fix allowing user to delete friend code with active trade offers and in-game-name not being set on signup
This commit is contained in:
parent
65ca344582
commit
23d334c596
6 changed files with 658 additions and 10 deletions
|
|
@ -6,6 +6,7 @@ from django.views.generic import ListView, CreateView, DeleteView, View, Templat
|
|||
from accounts.models import FriendCode, CustomUser
|
||||
from accounts.forms import FriendCodeForm, UserSettingsForm
|
||||
from django.db.models import Case, When, Value, BooleanField
|
||||
from trades.models import TradeOffer, TradeAcceptance
|
||||
|
||||
class ListFriendCodesView(LoginRequiredMixin, ListView):
|
||||
"""
|
||||
|
|
@ -99,8 +100,11 @@ class DeleteFriendCodeView(LoginRequiredMixin, DeleteView):
|
|||
)
|
||||
return redirect(self.success_url)
|
||||
|
||||
# Also check if this friend code is referenced by any trade offer.
|
||||
if self.object.initiated_trade_offers.exists() or self.object.trade_acceptances.exists():
|
||||
# Use the unfiltered manager and filter by the friend code's primary key
|
||||
trade_offer_exists = TradeOffer.all_offers.filter(initiated_by_id=self.object.pk).exists()
|
||||
trade_acceptance_exists = TradeAcceptance.objects.filter(accepted_by_id=self.object.pk).exists()
|
||||
|
||||
if trade_offer_exists or trade_acceptance_exists:
|
||||
messages.error(
|
||||
request,
|
||||
"Cannot remove this friend code because there are existing trade offers associated with it."
|
||||
|
|
@ -110,7 +114,7 @@ class DeleteFriendCodeView(LoginRequiredMixin, DeleteView):
|
|||
# Proceed to safe deletion.
|
||||
self.object.delete()
|
||||
messages.success(request, "Friend code removed successfully.")
|
||||
return redirect(self.success_url + "?deleted=true")
|
||||
return redirect(self.success_url)
|
||||
|
||||
class ChangeDefaultFriendCodeView(LoginRequiredMixin, View):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue