Skip to content

Commit

Permalink
fix: fix problem with declare winner endpoint being unable to create …
Browse files Browse the repository at this point in the history
…winner
  • Loading branch information
sandronadiradze committed Nov 5, 2024
1 parent 5f9300b commit 375f633
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
15 changes: 0 additions & 15 deletions auction/permissions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from rest_framework.permissions import BasePermission

from auction.models.auction import AuctionStatistics


class IsOwner(BasePermission):
"""
Expand Down Expand Up @@ -73,16 +71,3 @@ def has_permission(self, request, view):

def has_object_permission(self, request, view, obj):
return str(obj.auction.author) == str(request.user.id)


class AlreadyHasAWinner(BasePermission):
def has_permission(self, request, view):
return True

def has_object_permission(self, request, view, obj):
auction_statistics = AuctionStatistics.objects.filter(auction=obj).first()

if auction_statistics:
return auction_statistics.winner_bid_object is not None

return False
6 changes: 3 additions & 3 deletions auction/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
seller_dashboard_list_openapi_examples,
)
from auction.permissions import (
AlreadyHasAWinner,
HasCountryInProfile,
IsAuctionOwner,
IsBookmarkOwner,
Expand Down Expand Up @@ -1101,7 +1100,6 @@ class DeclareWinnerView(generics.GenericAPIView):
IsBuyer,
IsAuctionOwner,
HasCountryInProfile,
AlreadyHasAWinner,
]

def get_bid(self, auction_id, bid_id):
Expand All @@ -1117,7 +1115,6 @@ def validate_bid_and_auction(self, bid):
if bid.status in [
BidStatusChoices.REJECTED,
BidStatusChoices.DELETED,
BidStatusChoices.APPROVED,
BidStatusChoices.REVOKED,
]:
raise ValidationError(
Expand All @@ -1141,6 +1138,9 @@ def validate_bid_and_auction(self, bid):
_("You can only declare a winner after the auction has been completed.")
)

if auction.statistics.winner_bid_object is not None:
raise ValidationError(_("You can have only one winner on an auction."))

def update_auction_winner(self, bid):
with transaction.atomic():
statistics, created = AuctionStatistics.objects.get_or_create(
Expand Down
36 changes: 20 additions & 16 deletions locale/ka/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-05 08:56+0000\n"
"POT-Creation-Date: 2024-11-05 11:21+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -74,74 +74,78 @@ msgstr "თქვენ არ შეგიძლიათ შეცვალო
msgid "There was an error during the update of the auction. Please try again."
msgstr "აუქციონის შექმნისას პრობლემამ იჩინა თავი. გთხოვთ სცადოთ თავიდან."

#: auction/views.py:613
#: auction/views.py:628
msgid "Auction deleted successfully."
msgstr "აუქციონი წარმატებით წაიშალა."

#: auction/views.py:723
#: auction/views.py:738
#, python-brace-format
msgid "Auction with UUID {id} does not exist."
msgstr "აუქციონი მოცემული იდენტიფიკატორით {id} არ არსებობს."

#: auction/views.py:732
#: auction/views.py:747
#, python-brace-format
msgid ""
"{deleted} auctions deleted and {marked_deleted} auctions marked as deleted."
msgstr ""
"წაიშალა {deleted} აუქციონი და {marked_deleted} აუქციონი მონიშნულია, როგორც "
"წაშლილი."

#: auction/views.py:1103
#: auction/views.py:1122
msgid ""
"Only the bids with a status of either Pending or Approved can be declared as "
"winner bids."
msgstr ""
"მხოლოდ დაეფრუვებული ან მომლოდინე რეჟიმის მქონე ბიდები შეიძლება გამოცხადნენ "
"გამარჯვებულებად."

#: auction/views.py:1119
#: auction/views.py:1138
msgid "You can only declare a winner after the auction has been completed."
msgstr ""
"გამარჯვებულის გამოცხადება მხოლოდ აუქციონის დასრულების შემდეგ შეგიძლიათ."

#: auction/views.py:1164
#: auction/views.py:1143
msgid "You can have only one winner on an auction."
msgstr "აუქციონს შეიძლება ყავდეს მხოლოდ ერთი გამარჯვებული."

#: auction/views.py:1188
msgid "Winner of this auction has successfully been declared"
msgstr "აუქციონის გამარჯვებული წარმატებით გამოვლინდა."

#: auction/views.py:1290
#: auction/views.py:1314
msgid "You can not cancel draft auctions."
msgstr "თქვენ არ შეგიძლიათ დრაფტ სტატუსის მქონე აუქციონის გაუქმება."

#: auction/views.py:1291
#: auction/views.py:1315
msgid "This auction is already canceled."
msgstr "ეს აუქციონი უკვე გაუქმებულია."

#: auction/views.py:1292
#: auction/views.py:1316
msgid "You can not cancel deleted auctions."
msgstr "თქვენ არ შეგიძლიათ წაშლილი აუქციონის გაუქმება."

#: auction/views.py:1294
#: auction/views.py:1318
msgid "You can not cancel auctions that have already been completed."
msgstr "თქვენ არ შეგიძლიათ გააუქომთ აუქციონი, რომელიც უკვე დასრულებულია."

#: auction/views.py:1316
#: auction/views.py:1340
msgid "Auction was successfully canceled."
msgstr "აუქციონის გაუქმება წარმატებით განხორციელდა."

#: auction/views.py:1408
#: auction/views.py:1432
msgid "You can not leave an auction that has already been completed."
msgstr "თქვენ არ შეგიძლიათ დატოვოთ აუქციონი რომელიც უკვე დასრულდა."

#: auction/views.py:1412
#: auction/views.py:1436
msgid "You can not leave an auction that has not started yet."
msgstr "თქვენ არ შეგიძლიათ დატოვოთ აუქციონი, რომელიც ჯერ არ დაწყებულა."

#: auction/views.py:1416
#: auction/views.py:1440
msgid "You can not leave an auction that has been cancelled, drafted."
msgstr ""
"თქვენ არ შეგიძლიათ გაუქმებული ან drafter სტატუსის მქონე აუქციონის დატოვება."

#: auction/views.py:1421
#: auction/views.py:1445
msgid "As a winner of an auction, you can not leave it."
msgstr "როგორც გამარჯვებული, თქვენ ვერ დატოვებთ აუქციონს."

Expand Down

0 comments on commit 375f633

Please sign in to comment.