@@ -316,13 +316,9 @@ def __init__(self, *args, **kwargs):
316
316
self .showLocal = False
317
317
except :
318
318
self .showLocal = False
319
- self .showOwnLots = (
320
- True # show lots from the request user. I don't think this is used anywhere
321
- )
319
+ self .showOwnLots = True # show lots from the request user. I don't think this is used anywhere
322
320
self .maxRange = 70 # only applies if self.showLocal = True
323
- self .showDeactivated = (
324
- False # show lots that users have deliberately deactivated
325
- )
321
+ self .showDeactivated = False # show lots that users have deliberately deactivated
326
322
if self .user .is_superuser :
327
323
self .showBanned = True
328
324
else :
@@ -338,9 +334,7 @@ def __init__(self, *args, **kwargs):
338
334
# "all", "open", "unsold", or "ended". If regarding an auction, should default to all
339
335
self .status = "open"
340
336
self .showShipping = True
341
- self .shippingLocation = (
342
- 52 # USA, later we might set this with a cookie like we do with lat and lng
343
- )
337
+ self .shippingLocation = 52 # USA, later we might set this with a cookie like we do with lat and lng
344
338
if self .user .is_authenticated :
345
339
# lots for local pickup
346
340
if self .user .userdata .local_distance :
@@ -355,37 +349,27 @@ def __init__(self, *args, **kwargs):
355
349
try :
356
350
self .regardingAuction = kwargs .pop ("regardingAuction" )
357
351
except :
358
- self .regardingAuction = (
359
- None # force only displaying lots from a particular auction
360
- )
352
+ self .regardingAuction = None # force only displaying lots from a particular auction
361
353
try :
362
354
self .regardingUser = kwargs .pop ("regardingUser" )
363
355
except :
364
356
# force only displaying lots for a particular user (not necessarily the request user)
365
357
self .regardingUser = None
366
358
try :
367
- self .order = kwargs .pop (
368
- "order"
369
- ) # default ordering is just the most recent on top
359
+ self .order = kwargs .pop ("order" ) # default ordering is just the most recent on top
370
360
except :
371
- self .order = (
372
- "-lot_number" # default ordering is just the most recent on top
373
- )
361
+ self .order = "-lot_number" # default ordering is just the most recent on top
374
362
forceAuction = None
375
363
try :
376
364
forceAuction = kwargs .pop ("auction" )
377
365
if self .listType == "auction" :
378
- self .regardingAuction = Auction .objects .get (
379
- slug = forceAuction , is_deleted = False
380
- )
366
+ self .regardingAuction = Auction .objects .get (slug = forceAuction , is_deleted = False )
381
367
except :
382
368
pass
383
369
try :
384
370
forceAuction = self .request .GET ["auction" ]
385
371
if forceAuction != "no_auction" :
386
- self .regardingAuction = Auction .objects .get (
387
- slug = forceAuction , is_deleted = False
388
- )
372
+ self .regardingAuction = Auction .objects .get (slug = forceAuction , is_deleted = False )
389
373
else :
390
374
self .regardingAuction = None
391
375
except :
@@ -411,9 +395,7 @@ def __init__(self, *args, **kwargs):
411
395
self .showShipping = False
412
396
# an extra filter
413
397
specialAuctions = Q (slug = regardingAuctionSlug )
414
- self .possibleAuctions = Auction .objects .exclude (is_deleted = True ).order_by (
415
- "title"
416
- )
398
+ self .possibleAuctions = Auction .objects .exclude (is_deleted = True ).order_by ("title" )
417
399
if self .user .is_authenticated :
418
400
self .possibleAuctions = self .possibleAuctions .filter (
419
401
Q (auctiontos__user = self .user ) | specialAuctions
@@ -484,11 +466,7 @@ def generate_attrs(placeholder="", tooltip=""):
484
466
queryset = Category .objects .all ().order_by ("name" ),
485
467
method = "filter_by_category" ,
486
468
empty_label = "Any category" ,
487
- widget = Select (
488
- attrs = generate_attrs (
489
- None , "Picking something here overrides your ignored categories"
490
- )
491
- ),
469
+ widget = Select (attrs = generate_attrs (None , "Picking something here overrides your ignored categories" )),
492
470
)
493
471
status = django_filters .ChoiceFilter (
494
472
label = "" ,
@@ -571,11 +549,7 @@ def qs(self):
571
549
if self .user .is_authenticated :
572
550
# watched lots
573
551
primary_queryset = primary_queryset .annotate (
574
- is_watched_by_req_user = Exists (
575
- Watch .objects .filter (
576
- lot_number = OuterRef ("lot_number" ), user = self .user
577
- )
578
- )
552
+ is_watched_by_req_user = Exists (Watch .objects .filter (lot_number = OuterRef ("lot_number" ), user = self .user ))
579
553
)
580
554
if self .user .is_authenticated :
581
555
# messages for owner of lot
@@ -616,9 +590,7 @@ def qs(self):
616
590
)
617
591
)
618
592
if self .order == "-recommended" :
619
- primary_queryset = primary_queryset .annotate (
620
- recommended = Sum (0 , output_field = IntegerField ())
621
- )
593
+ primary_queryset = primary_queryset .annotate (recommended = Sum (0 , output_field = IntegerField ()))
622
594
if self .keywords :
623
595
for word in self .keywords :
624
596
primary_queryset = primary_queryset .annotate (
@@ -631,13 +603,12 @@ def qs(self):
631
603
)
632
604
if self .user .is_authenticated :
633
605
interest = Subquery (
634
- UserInterestCategory .objects .filter (
635
- category = OuterRef ( "species_category" ), user = self . user
636
- ). values ( "interest" )
606
+ UserInterestCategory .objects .filter (category = OuterRef ( "species_category" ), user = self . user ). values (
607
+ "interest"
608
+ )
637
609
)
638
610
primary_queryset = primary_queryset .annotate (
639
- recommended = (((F ("promotion_weight" ) + 1 ) / 10 ) * interest / 5 )
640
- + F ("recommended" )
611
+ recommended = (((F ("promotion_weight" ) + 1 ) / 10 ) * interest / 5 ) + F ("recommended" )
641
612
)
642
613
else :
643
614
# if not signed in, recommended = most viewed
@@ -687,24 +658,14 @@ def qs(self):
687
658
# finally, filter by max range
688
659
if self .maxRange : # and not self.regardingAuction:
689
660
# if you specify both range and auction, range does nothing
690
- local_qs = Q (
691
- distance__lte = self .maxRange , auction__isnull = True , local_pickup = True
692
- )
661
+ local_qs = Q (distance__lte = self .maxRange , auction__isnull = True , local_pickup = True )
693
662
if self .ignore and self .user .is_authenticated :
694
- allowedCategories = Category .objects .exclude (
695
- userignorecategory__user = self .user
696
- )
697
- primary_queryset = primary_queryset .filter (
698
- species_category__in = allowedCategories
699
- )
663
+ allowedCategories = Category .objects .exclude (userignorecategory__user = self .user )
664
+ primary_queryset = primary_queryset .filter (species_category__in = allowedCategories )
700
665
if not self .showOwnLots and self .user .is_authenticated :
701
- primary_queryset = primary_queryset .exclude (
702
- user = self .user .pk
703
- ) # don't show your own lots
666
+ primary_queryset = primary_queryset .exclude (user = self .user .pk ) # don't show your own lots
704
667
if self .showShipping and self .shippingLocation :
705
- shipping_qs = Q (
706
- shipping_locations = self .shippingLocation , auction__isnull = True
707
- )
668
+ shipping_qs = Q (shipping_locations = self .shippingLocation , auction__isnull = True )
708
669
else :
709
670
shipping_qs = Q (pk__isnull = True )
710
671
if self .canShowAuction :
@@ -717,19 +678,13 @@ def qs(self):
717
678
# this shows any auction you've joined + any public auction. Perhaps this should be a preference?
718
679
# auction_qs = Q(auction__pk__in=self.possibleAuctions)|Q(auction__promote_this_auction=True)
719
680
# this shows any auction you've joined. See https://github.com/iragm/fishauctions/issues/66
720
- auction_qs = Q (auction__pk__in = self .possibleAuctions ) | Q (
721
- auction__isnull = True
722
- )
681
+ auction_qs = Q (auction__pk__in = self .possibleAuctions ) | Q (auction__isnull = True )
723
682
else :
724
683
# anonymous users can see lots from all promoted auctions
725
- auction_qs = Q (auction__promote_this_auction = True ) | Q (
726
- auction__isnull = True
727
- )
684
+ auction_qs = Q (auction__promote_this_auction = True ) | Q (auction__isnull = True )
728
685
# auction_qs = Q(auction__auctiontos__user=self.user, auction__promote_this_auction=False)|Q(auction__promote_this_auction=True)
729
686
# putting them all together:
730
- primary_queryset = primary_queryset .filter (
731
- Q (local_qs ) | Q (shipping_qs ) | Q (auction_qs )
732
- )
687
+ primary_queryset = primary_queryset .filter (Q (local_qs ) | Q (shipping_qs ) | Q (auction_qs ))
733
688
return primary_queryset .order_by (self .order )
734
689
735
690
def filter_by_order (self , queryset , name , value ):
@@ -833,9 +788,7 @@ class UserLotFilter(LotFilter):
833
788
@property
834
789
def qs (self ):
835
790
primary_queryset = super ().qs
836
- return primary_queryset .filter (
837
- Q (user = self .request .user ) | Q (auctiontos_seller__user = self .request .user )
838
- )
791
+ return primary_queryset .filter (Q (user = self .request .user ) | Q (auctiontos_seller__user = self .request .user ))
839
792
840
793
def __init__ (self , * args , ** kwargs ):
841
794
super ().__init__ (* args , ** kwargs )
@@ -878,9 +831,7 @@ class UserWonLotFilter(LotFilter):
878
831
@property
879
832
def qs (self ):
880
833
primary_queryset = super ().qs
881
- return primary_queryset .filter (
882
- Q (winner = self .user ) | Q (auctiontos_winner__user = self .user )
883
- )
834
+ return primary_queryset .filter (Q (winner = self .user ) | Q (auctiontos_winner__user = self .user ))
884
835
885
836
def __init__ (self , * args , ** kwargs ):
886
837
super ().__init__ (* args , ** kwargs )
0 commit comments