1
1
'''
2
2
This file contains utilities for competitions
3
3
'''
4
- import random
5
-
6
- from django .db .models import Count
4
+ # import random
5
+ # from django.db.models import Count
7
6
8
7
from competitions .models import Competition
9
8
@@ -16,14 +15,26 @@ def get_popular_competitions(limit=4):
16
15
:rtype: list
17
16
:return: Most popular competitions.
18
17
'''
19
- competitions = Competition .objects .filter (published = True ) \
20
- .annotate (participant_count = Count ('participants' )) \
21
- .order_by ('-participant_count' )
22
18
23
- if len (competitions ) <= limit :
24
- return competitions
19
+ # TODO: Fix the fetching of the popular competitions
20
+ # Uncomment and update the following code when a long term fix is implemented for participants count
21
+
22
+ # competitions = Competition.objects.filter(published=True) \
23
+ # .annotate(participant_count=Count('participants')) \
24
+ # .order_by('-participant_count')
25
+
26
+ # if len(competitions) <= limit:
27
+ # return competitions
25
28
26
- return competitions [:limit ]
29
+ # return competitions[:limit]
30
+
31
+ # Temporary solution to show specific popular competitions
32
+ try :
33
+ popular_competiion_ids = [1752 , 1772 , 2338 , 3863 ]
34
+ competitions = Competition .objects .filter (id__in = popular_competiion_ids )
35
+ return competitions
36
+ except Exception :
37
+ return []
27
38
28
39
29
40
def get_featured_competitions (limit = 4 , excluded_competitions = None ):
@@ -36,13 +47,24 @@ def get_featured_competitions(limit=4, excluded_competitions=None):
36
47
:return: list of featured competitions
37
48
'''
38
49
39
- competitions = Competition .objects .filter (published = True ) \
40
- .annotate (participant_count = Count ('participants' ))
50
+ # TODO: Fix the fetching of the featured competitions
51
+ # Uncomment and update the following code when a long term fix is implemented for participants count
52
+
53
+ # competitions = Competition.objects.filter(published=True) \
54
+ # .annotate(participant_count=Count('participants'))
55
+
56
+ # if excluded_competitions:
57
+ # competitions = competitions.exclude(pk__in=[c.pk for c in excluded_competitions])
41
58
42
- if excluded_competitions :
43
- competitions = competitions .exclude (pk__in = [c .pk for c in excluded_competitions ])
59
+ # if len(competitions) <= limit:
60
+ # return competitions
61
+ # else:
62
+ # return random.sample(list(competitions), limit)
44
63
45
- if len (competitions ) <= limit :
64
+ # Temporary solution to show specific featured competitions
65
+ try :
66
+ featured_competiion_ids = [3523 , 2745 , 3160 , 1567 ]
67
+ competitions = Competition .objects .filter (id__in = featured_competiion_ids )
46
68
return competitions
47
- else :
48
- return random . sample ( list ( competitions ), limit )
69
+ except Exception :
70
+ return []
0 commit comments