From 01becbee48b5eb6d9b0b2d65408cba857ef965ed Mon Sep 17 00:00:00 2001 From: badbl0cks <4161747+badbl0cks@users.noreply.github.com> Date: Thu, 3 Apr 2025 17:09:51 -0700 Subject: [PATCH] Fixes to trade expansion and trade acceptance appearance --- accounts/urls.py | 3 -- accounts/views.py | 52 +++++++------------ home/views.py | 2 - static/css/base.css | 11 ++++ theme/templates/account/dashboard.html | 18 +++---- theme/templates/base.html | 8 +-- theme/templates/cards/card_detail.html | 12 ++++- theme/templates/cards/card_list.html | 10 +++- .../friend_codes/add_friend_code.html | 3 -- .../confirm_delete_friend_code.html | 2 +- .../friend_codes/edit_friend_code.html | 2 +- .../friend_codes/list_friend_codes.html | 43 --------------- theme/templates/home/home.html | 4 +- .../trades/trade_acceptance_create.html | 3 -- .../trades/trade_acceptance_update.html | 6 --- .../templates/trades/trade_offer_detail.html | 3 +- .../templates/trades/trade_offer_update.html | 1 - theme/templatetags/trade_acceptance.html | 23 ++++---- theme/templatetags/trade_offer.html | 46 +++++++++------- trades/urls.py | 1 - 20 files changed, 105 insertions(+), 148 deletions(-) delete mode 100644 theme/templates/friend_codes/list_friend_codes.html diff --git a/accounts/urls.py b/accounts/urls.py index 88c27f4..8e9b106 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -1,6 +1,5 @@ from django.urls import path from .views import ( - ListFriendCodesView, AddFriendCodeView, DeleteFriendCodeView, ChangeDefaultFriendCodeView, @@ -9,8 +8,6 @@ from .views import ( ) urlpatterns = [ - # ... other account URLs ... - path("friend-codes/", ListFriendCodesView.as_view(), name="list_friend_codes"), path("friend-codes/add/", AddFriendCodeView.as_view(), name="add_friend_code"), path("friend-codes/edit//", EditFriendCodeView.as_view(), name="edit_friend_code"), path("friend-codes/delete//", DeleteFriendCodeView.as_view(), name="delete_friend_code"), diff --git a/accounts/views.py b/accounts/views.py index b37162a..c549b40 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -10,27 +10,8 @@ from trades.models import TradeOffer, TradeAcceptance from django.core.exceptions import PermissionDenied from trades.mixins import FriendCodeRequiredMixin from common.mixins import ReusablePaginationMixin - -class ListFriendCodesView(LoginRequiredMixin, ListView): - """ - Display the current user's friend codes. - """ - model = FriendCode - template_name = "friend_codes/list_friend_codes.html" - context_object_name = "friend_codes" - - def get_queryset(self): - # Get the default friend code's primary key if it exists. - default_pk = getattr(self.request.user.default_friend_code, "pk", None) - - # Annotate each friend code with is_default=True if its pk matches. - return self.request.user.friend_codes.all().annotate( - is_default=Case( - When(pk=default_pk, then=Value(True)), - default=Value(False), - output_field=BooleanField() - ) - ) +from django.urls import reverse +from django.utils.http import urlencode class AddFriendCodeView(LoginRequiredMixin, CreateView): """ @@ -40,7 +21,9 @@ class AddFriendCodeView(LoginRequiredMixin, CreateView): model = FriendCode form_class = FriendCodeForm template_name = "friend_codes/add_friend_code.html" - success_url = reverse_lazy("list_friend_codes") + def get_success_url(self): + base_url = reverse("dashboard") + return f"{base_url}?{urlencode({'tab': 'friend_codes'})}" def form_valid(self, form): form.instance.user = self.request.user @@ -57,7 +40,9 @@ class DeleteFriendCodeView(LoginRequiredMixin, DeleteView): model = FriendCode template_name = "friend_codes/confirm_delete_friend_code.html" context_object_name = "friend_code" - success_url = reverse_lazy("list_friend_codes") + def get_success_url(self): + base_url = reverse("dashboard") + return f"{base_url}?{urlencode({'tab': 'friend_codes'})}" def get_queryset(self): # Only allow deletion of friend codes owned by the current user. @@ -90,20 +75,16 @@ class DeleteFriendCodeView(LoginRequiredMixin, DeleteView): self.object = self.get_object() user = self.object.user - # Check if the friend code is the only one; prevent deletion. if user.friend_codes.count() == 1: messages.error(request, "Cannot remove your only friend code.") - return redirect(self.success_url) - - # Check if the friend code is set as default; prevent deletion. + return redirect(self.get_success_url()) if user.default_friend_code == self.object: messages.error( request, "Cannot delete your default friend code. Please set a different default first." ) - return redirect(self.success_url) + return redirect(self.get_success_url()) - # 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() @@ -112,12 +93,11 @@ class DeleteFriendCodeView(LoginRequiredMixin, DeleteView): request, "Cannot remove this friend code because there are existing trade offers associated with it." ) - return redirect(self.success_url) + return redirect(self.get_success_url()) - # Proceed to safe deletion. self.object.delete() messages.success(request, "Friend code removed successfully.") - return redirect(self.success_url) + return redirect(self.get_success_url()) class ChangeDefaultFriendCodeView(LoginRequiredMixin, View): """ @@ -128,7 +108,9 @@ class ChangeDefaultFriendCodeView(LoginRequiredMixin, View): friend_code = get_object_or_404(FriendCode, pk=friend_code_id, user=request.user) request.user.set_default_friend_code(friend_code) messages.success(request, "Default friend code updated successfully.") - return redirect("list_friend_codes") + base_url = reverse("dashboard") + query_string = urlencode({"tab": "friend_codes"}) + return redirect(f"{base_url}?{query_string}") class EditFriendCodeView(LoginRequiredMixin, UpdateView): """ @@ -141,7 +123,9 @@ class EditFriendCodeView(LoginRequiredMixin, UpdateView): fields = ['in_game_name'] template_name = "friend_codes/edit_friend_code.html" context_object_name = "friend_code" - success_url = reverse_lazy("list_friend_codes") + def get_success_url(self): + base_url = reverse("dashboard") + return f"{base_url}?{urlencode({'tab': 'friend_codes'})}" def get_queryset(self): # Ensure the user can only edit their own friend codes diff --git a/home/views.py b/home/views.py index db17386..b26e523 100644 --- a/home/views.py +++ b/home/views.py @@ -7,7 +7,6 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from trades.models import TradeOffer, TradeAcceptance, TradeOfferHaveCard, TradeOfferWantCard from cards.models import Card from django.utils.decorators import method_decorator -from django.views.decorators.cache import cache_page from django.template.response import TemplateResponse from django.http import HttpResponseRedirect import logging @@ -112,7 +111,6 @@ class HomePageView(TemplateView): return context - @method_decorator(cache_page(60 * 10)) # Cache for 10 minutes def get(self, request, *args, **kwargs): """Override get method to add caching""" return super().get(request, *args, **kwargs) \ No newline at end of file diff --git a/static/css/base.css b/static/css/base.css index ce81a47..2bec08b 100644 --- a/static/css/base.css +++ b/static/css/base.css @@ -1,5 +1,16 @@ [x-cloak] { display: none !important; } +/* Beta Badge */ +#navbar-logo::after { + content: 'BETA'; + font-size: 12px; + font-weight: bold; + color: var(--color-base-content); + background-color: var(--color-base-300); + padding: 4px 8px; + border-radius: 4px; +} + select.card-multiselect { height: calc(var(--spacing) * 35); /*background-image: linear-gradient(45deg, #0000 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, #0000 50%); */ diff --git a/theme/templates/account/dashboard.html b/theme/templates/account/dashboard.html index 63bc1ce..9dd5ad8 100644 --- a/theme/templates/account/dashboard.html +++ b/theme/templates/account/dashboard.html @@ -56,7 +56,7 @@

{{ _('Quick Actions') }}

-
+
{{ _('Create New Offer') }} {{ _('View All Offers') }} {{ _('Sign Out') }} @@ -121,17 +121,17 @@ {% endif %} {% endwith %}
-

What is Gravatar?

-

Gravatar (Globally Recognized Avatar) is a free service that links your email address to a profile picture and, optionally, a profile. Many websites, including this one, use Gravatar to display your avatar and profile automatically.

+

What is Gravatar?

+

Gravatar (Globally Recognized Avatar) is a free service that links your email address to a profile picture and, optionally, a profile. Many websites, including this one, use Gravatar to display your avatar and profile automatically.

-

How does it work?

-

If you've set up a Gravatar, your profile picture will appear here whenever you use your email on supported sites. When someone hovers over or clicks on your avatar, your Gravatar profile will also appear if you have one. If you don't have a Gravatar yet, you'll see a default image instead.

+

How does it work?

+

If you've set up a Gravatar, your profile picture will appear here whenever you use your email on supported sites. When someone hovers over or clicks on your avatar, your Gravatar profile will also appear if you have one. If you don't have a Gravatar yet, you'll see a default image instead.

-

Is it safe? What about privacy?

-

Gravatar is completely optional, opt-in, and prioritizes your security and privacy. Your email is never shared and only a hashed version is sent to Gravatar, protecting your identity while ensuring that your email address is not exposed to bots or scrapers. Your personal data remains secure, and you maintain full control over your public profile.

+

Is it safe? What about privacy?

+

Gravatar is completely optional, opt-in, and prioritizes your security and privacy. Your email is never shared and only a hashed version is sent to Gravatar, protecting your identity while ensuring that your email address is not exposed to bots or scrapers. Your personal data remains secure, and you maintain full control over your public profile.

-

Want to update or add a Gravatar?

-

Go to Gravatar.com to set up or change your avatar or profile. Your updates will appear here once saved!

+

Want to update or add a Gravatar?

+

Go to Gravatar.com to set up or change your avatar or profile. Your updates will appear here once saved!

diff --git a/theme/templates/base.html b/theme/templates/base.html index ce033f6..d175ea0 100644 --- a/theme/templates/base.html +++ b/theme/templates/base.html @@ -54,11 +54,11 @@ {% block javascript_head %}{% endblock %} - + {% endif %} - -
{% endblock content %} \ No newline at end of file diff --git a/theme/templates/trades/trade_offer_detail.html b/theme/templates/trades/trade_offer_detail.html index 6c132cd..e2a6900 100644 --- a/theme/templates/trades/trade_offer_detail.html +++ b/theme/templates/trades/trade_offer_detail.html @@ -47,11 +47,10 @@ {% endif %}
- Back to Trade Offers {% if is_initiator %} Delete/Close Trade Offer {% elif request.user.is_authenticated %} - + {% endif %}
diff --git a/theme/templates/trades/trade_offer_update.html b/theme/templates/trades/trade_offer_update.html index 2dba5d2..71eb196 100644 --- a/theme/templates/trades/trade_offer_update.html +++ b/theme/templates/trades/trade_offer_update.html @@ -80,7 +80,6 @@ {% endif %}
- Back to Trade Offers {% if can_delete %} Delete Trade Offer {% endif %} diff --git a/theme/templatetags/trade_acceptance.html b/theme/templatetags/trade_acceptance.html index 38c3808..1843b93 100644 --- a/theme/templatetags/trade_acceptance.html +++ b/theme/templatetags/trade_acceptance.html @@ -1,12 +1,11 @@ -{% load gravatar card_badge cache %} +{% load gravatar card_badge %} -{% cache 60 trade_acceptance acceptance.pk %} -
+
-
+
-
+
{{ acceptance.trade_offer.initiated_by.user.email|gravatar:40 }} @@ -15,7 +14,7 @@ Has
-
+
Wants
@@ -29,7 +28,7 @@
-
+
{% card_badge acceptance.requested_card %}
@@ -41,13 +40,15 @@
-
-
+
+
+ {{ acceptance.get_state_display }} +
+
-
-{% endcache %} \ No newline at end of file +
\ No newline at end of file diff --git a/theme/templatetags/trade_offer.html b/theme/templatetags/trade_offer.html index 84d0745..528ffcc 100644 --- a/theme/templatetags/trade_offer.html +++ b/theme/templatetags/trade_offer.html @@ -40,26 +40,33 @@
- -
- - + {% if have_cards_available|length > 1 or want_cards_available|length > 1 %}
+ {% else %} +
+ {% endif %} diff --git a/trades/urls.py b/trades/urls.py index 98b8f7d..ce4cf7a 100644 --- a/trades/urls.py +++ b/trades/urls.py @@ -1,5 +1,4 @@ from django.urls import path -from django.views.decorators.cache import cache_page from .views import ( TradeOfferCreateView, TradeOfferCreateConfirmView,