From bc181b12d95ae5ba7bb539799067b366bba48d79 Mon Sep 17 00:00:00 2001 From: badbl0cks <4161747+badbl0cks@users.noreply.github.com> Date: Fri, 14 Mar 2025 09:50:49 -0700 Subject: [PATCH] Add in_game_name field to FriendCode model --- accounts/forms.py | 25 +++++++++- accounts/migrations/0001_initial.py | 3 +- accounts/models.py | 1 + accounts/views.py | 2 +- cards/migrations/0001_initial.py | 2 +- home/views.py | 3 +- seed/0005_TestUsers.json | 2 + theme/templates/_messages.html | 5 +- theme/templates/account/settings.html | 2 +- theme/templates/account/signup.html | 6 +++ theme/templates/base.html | 4 +- .../friend_codes/add_friend_code.html | 20 ++++++-- .../friend_codes/list_friend_codes.html | 16 ++++--- theme/templates/home/home.html | 8 ++-- .../templates/trades/_friend_code_select.html | 4 +- theme/templatetags/trade_offer.html | 14 +++--- trades/migrations/0001_initial.py | 2 +- trades/templatetags/trade_offer_tags.py | 4 +- trades/views.py | 46 +++++++++++++------ 19 files changed, 113 insertions(+), 56 deletions(-) diff --git a/accounts/forms.py b/accounts/forms.py index 2cb1037..c8909e8 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -2,6 +2,7 @@ from django import forms from django.contrib.auth.forms import UserCreationForm, UserChangeForm from .models import CustomUser, FriendCode from allauth.account.forms import SignupForm +from crispy_tailwind.tailwind import CSSContainer class CustomUserChangeForm(UserChangeForm): @@ -12,7 +13,7 @@ class CustomUserChangeForm(UserChangeForm): class FriendCodeForm(forms.ModelForm): class Meta: model = FriendCode - fields = ["friend_code"] + fields = ["friend_code", "in_game_name"] def clean_friend_code(self): friend_code = self.cleaned_data.get("friend_code", "").strip() @@ -30,12 +31,32 @@ class CustomUserCreationForm(SignupForm): model = CustomUser fields = ['email', 'username', 'friend_code'] + email = forms.EmailField( + required=True, + label="Email", + widget=forms.TextInput(attrs={'placeholder': 'Email', 'class':'dark:bg-base-100'}) + ) + + username = forms.CharField( + max_length=24, + required=True, + label="Username", + widget=forms.TextInput(attrs={'placeholder': 'Username', 'class':'dark:bg-base-100'}) + ) + friend_code = forms.CharField( max_length=19, required=True, label="Friend Code", help_text="Enter your friend code in the format XXXX-XXXX-XXXX-XXXX.", - widget=forms.TextInput(attrs={'placeholder': 'XXXX-XXXX-XXXX-XXXX'}) + widget=forms.TextInput(attrs={'placeholder': 'XXXX-XXXX-XXXX-XXXX', 'class':'dark:bg-base-100'}) + ) + in_game_name = forms.CharField( + max_length=16, + required=True, + label="In-Game Name", + help_text="Enter your in-game name.", + widget=forms.TextInput(attrs={'placeholder': 'In-Game Name', 'class':'dark:bg-base-100'}) ) def __init__(self, *args, **kwargs): diff --git a/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py index 4b2ade7..cc88c8d 100644 --- a/accounts/migrations/0001_initial.py +++ b/accounts/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.2 on 2025-03-13 01:46 +# Generated by Django 5.1.2 on 2025-03-14 05:35 import django.contrib.auth.models import django.contrib.auth.validators @@ -48,6 +48,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('friend_code', models.CharField(max_length=19)), + ('in_game_name', models.CharField(max_length=16)), ('created_at', models.DateTimeField(auto_now_add=True)), ('updated_at', models.DateTimeField(auto_now=True)), ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='friend_codes', to=settings.AUTH_USER_MODEL)), diff --git a/accounts/models.py b/accounts/models.py index ca2b979..96337be 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -27,6 +27,7 @@ class CustomUser(AbstractUser): class FriendCode(models.Model): friend_code = models.CharField(max_length=19) + in_game_name = models.CharField(max_length=16, null=False, blank=False) user = models.ForeignKey(CustomUser, on_delete=models.PROTECT, related_name='friend_codes') created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) diff --git a/accounts/views.py b/accounts/views.py index b739952..20a1f4d 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -89,7 +89,7 @@ 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_by.exists() or self.object.accepted_by.exists(): + if self.object.initiated_trade_offers.exists() or self.object.trade_acceptances.exists(): messages.error( request, "Cannot remove this friend code because there are existing trade offers associated with it." diff --git a/cards/migrations/0001_initial.py b/cards/migrations/0001_initial.py index 47bfc0f..35fdeaf 100644 --- a/cards/migrations/0001_initial.py +++ b/cards/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.2 on 2025-03-13 01:46 +# Generated by Django 5.1.2 on 2025-03-14 05:35 import django.db.models.deletion from django.db import migrations, models diff --git a/home/views.py b/home/views.py index a5dd201..5b9b0a7 100644 --- a/home/views.py +++ b/home/views.py @@ -51,7 +51,8 @@ class HomePageView(TemplateView): "want_cards__decks", "want_cards__rarity", "want_cards__cardset", - "acceptances" + "acceptances", + ) .select_related("initiated_by__user") ) diff --git a/seed/0005_TestUsers.json b/seed/0005_TestUsers.json index 9f5a9c2..66e4853 100644 --- a/seed/0005_TestUsers.json +++ b/seed/0005_TestUsers.json @@ -42,6 +42,7 @@ "pk": 1, "fields": { "friend_code": "9167-8051-9691-8032", + "in_game_name": "badblocks", "user": 1, "created_at": "2025-03-13T04:21:05.166Z", "updated_at": "2025-03-13T04:21:05.166Z" @@ -52,6 +53,7 @@ "pk": 2, "fields": { "friend_code": "1234-2938-7848-7636", + "in_game_name": "backrolls", "user": 2, "created_at": "2025-03-13T04:52:29.166Z", "updated_at": "2025-03-13T04:52:29.166Z" diff --git a/theme/templates/_messages.html b/theme/templates/_messages.html index a6c9c6f..a52048b 100644 --- a/theme/templates/_messages.html +++ b/theme/templates/_messages.html @@ -1,8 +1,9 @@ {% if messages %}