Skip to content

Commit 144365c

Browse files
dzuqedanlipertthelostone-mc
authored
feature - add flags to leaderboard (#6509)
* add flags to leaderboard * remove conversion to list * switch csv to python file and clean up flag logic Co-authored-by: Dan Lipert <danlipert@gmail.com> Co-authored-by: Aditya Anand M C <aditya.anandmc@gmail.com>
1 parent 037aeab commit 144365c

3 files changed

Lines changed: 291 additions & 1 deletion

File tree

app/marketing/country_codes.py

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
COUNTRY_DATA =[
2+
"us","United States",
3+
"ad","Andorra",
4+
"ae","United Arab Emirates",
5+
"af","Afghanistan",
6+
"ag","Antigua and Barbuda",
7+
"ai","Anguilla",
8+
"ah","Artsakh",
9+
"ak","Abkhazia",
10+
"al","Albania",
11+
"am","Armenia",
12+
"an","Netherlands Antilles",
13+
"ao","Angola",
14+
"aq","Antarctica",
15+
"ar","Argentina",
16+
"as","American Samoa",
17+
"at","Austria",
18+
"au","Australia",
19+
"aw","Aruba",
20+
"ax","Åland Islands",
21+
"az","Azerbaijan",
22+
"ba","Bosnia and Herzegovina",
23+
"bb","Barbados",
24+
"bd","Bangladesh",
25+
"be","Belgium",
26+
"bf","Burkina Faso",
27+
"bg","Bulgaria",
28+
"bh","Bahrain",
29+
"bi","Burundi",
30+
"bj","Benin",
31+
"bl","Saint Barthélemy",
32+
"bm","Bermuda",
33+
"bn","Brunei Darussalam",
34+
"bo","Bolivia",
35+
"bq","Bonaire, Sint Eustatius and Saba",
36+
"br","Brazil",
37+
"bs","Bahamas",
38+
"bt","Bhutan",
39+
"bv","Bouvet Island",
40+
"bw","Botswana",
41+
"by","Belarus",
42+
"bz","Belize",
43+
"ca","Canada",
44+
"cc","Cocos (Keeling) Islands",
45+
"cd","Congo, The Democratic Republic Of The",
46+
"cf","Central African Republic",
47+
"cg","Congo",
48+
"ch","Switzerland",
49+
"ci","Côte D'Ivoire",
50+
"ck","Cook Islands",
51+
"cl","Chile",
52+
"cm","Cameroon",
53+
"cn","China",
54+
"co","Colombia",
55+
"cr","Costa Rica",
56+
"cu","Cuba",
57+
"cv","Cape Verde",
58+
"cw","Curaçao",
59+
"cx","Christmas Island",
60+
"cy","Cyprus",
61+
"cz","Czech Republic",
62+
"de","Germany",
63+
"dj","Djibouti",
64+
"dk","Denmark",
65+
"dm","Dominica",
66+
"do","Dominican Republic",
67+
"dz","Algeria",
68+
"ec","Ecuador",
69+
"ee","Estonia",
70+
"eg","Egypt",
71+
"eh","Western Sahara",
72+
"er","Eritrea",
73+
"es","Spain",
74+
"et","Ethiopia",
75+
"eu","Europe",
76+
"fi","Finland",
77+
"fj","Fiji",
78+
"fk","Falkland Islands (Malvinas)",
79+
"fm","Micronesia, Federated States Of",
80+
"fo","Faroe Islands",
81+
"fr","France",
82+
"ga","Gabon",
83+
"gb","United Kingdom",
84+
"gd","Grenada",
85+
"ge","Georgia",
86+
"gf","French Guiana",
87+
"gg","Guernsey",
88+
"gh","Ghana",
89+
"gi","Gibraltar",
90+
"gl","Greenland",
91+
"gm","Gambia",
92+
"gn","Guinea",
93+
"gp","Guadeloupe",
94+
"gq","Equatorial Guinea",
95+
"gr","Greece",
96+
"gs","South Georgia and the South Sandwich Islands",
97+
"gt","Guatemala",
98+
"gu","Guam",
99+
"gw","Guinea-Bissau",
100+
"gy","Guyana",
101+
"hk","Hong Kong",
102+
"hm","Heard and McDonald Islands",
103+
"hn","Honduras",
104+
"hr","Croatia",
105+
"ht","Haiti",
106+
"hu","Hungary",
107+
"ic","Canary Islands",
108+
"id","Indonesia",
109+
"ie","Ireland",
110+
"il","Israel",
111+
"im","Isle of Man",
112+
"in","India",
113+
"io","British Indian Ocean Territory",
114+
"iq","Iraq",
115+
"ir","Iran, Islamic Republic Of",
116+
"is","Iceland",
117+
"it","Italy",
118+
"je","Jersey",
119+
"jm","Jamaica",
120+
"jo","Jordan",
121+
"jp","Japan",
122+
"ke","Kenya",
123+
"kg","Kyrgyzstan",
124+
"kh","Cambodia",
125+
"ki","Kiribati",
126+
"km","Comoros",
127+
"kn","Saint Kitts And Nevis",
128+
"kp","Korea, Democratic People's Republic Of",
129+
"kr","Korea, Republic of",
130+
"kw","Kuwait",
131+
"ky","Cayman Islands",
132+
"kz","Kazakhstan",
133+
"la","Lao People's Democratic Republic",
134+
"lb","Lebanon",
135+
"lc","Saint Lucia",
136+
"li","Liechtenstein",
137+
"lk","Sri Lanka",
138+
"lr","Liberia",
139+
"ls","Lesotho",
140+
"lt","Lithuania",
141+
"lu","Luxembourg",
142+
"lv","Latvia",
143+
"ly","Libya",
144+
"ma","Morocco",
145+
"mc","Monaco",
146+
"md","Moldova, Republic of",
147+
"me","Montenegro",
148+
"mf","Saint Martin",
149+
"mg","Madagascar",
150+
"mh","Marshall Islands",
151+
"mk","Macedonia, the Former Yugoslav Republic Of",
152+
"ml","Mali",
153+
"mm","Myanmar",
154+
"mn","Mongolia",
155+
"mo","Macao",
156+
"mp","Northern Mariana Islands",
157+
"mq","Martinique",
158+
"mr","Mauritania",
159+
"ms","Montserrat",
160+
"mt","Malta",
161+
"mu","Mauritius",
162+
"mv","Maldives",
163+
"mw","Malawi",
164+
"mx","Mexico",
165+
"my","Malaysia",
166+
"mz","Mozambique",
167+
"na","Namibia",
168+
"nc","New Caledonia",
169+
"ne","Niger",
170+
"nf","Norfolk Island",
171+
"ng","Nigeria",
172+
"ni","Nicaragua",
173+
"nl","Netherlands",
174+
"no","Norway",
175+
"np","Nepal",
176+
"nr","Nauru",
177+
"nu","Niue",
178+
"ny","Northern Cyprus",
179+
"nz","New Zealand",
180+
"om","Oman",
181+
"pa","Panama",
182+
"pe","Peru",
183+
"pf","French Polynesia",
184+
"pg","Papua New Guinea",
185+
"ph","Philippines",
186+
"pk","Pakistan",
187+
"pl","Poland",
188+
"pm","Saint Pierre And Miquelon",
189+
"pn","Pitcairn",
190+
"pr","Puerto Rico",
191+
"ps","Palestine, State of",
192+
"pt","Portugal",
193+
"pw","Palau",
194+
"py","Paraguay",
195+
"qa","Qatar",
196+
"re","Réunion",
197+
"ro","Romania",
198+
"rs","Serbia",
199+
"ru","Russian Federation",
200+
"rw","Rwanda",
201+
"sa","Saudi Arabia",
202+
"sb","Solomon Islands",
203+
"sc","Seychelles",
204+
"sd","Sudan",
205+
"se","Sweden",
206+
"sg","Singapore",
207+
"sh","Saint Helena",
208+
"si","Slovenia",
209+
"sj","Svalbard And Jan Mayen",
210+
"sk","Slovakia",
211+
"sl","Sierra Leone",
212+
"sm","San Marino",
213+
"sn","Senegal",
214+
"so","Somalia",
215+
"sr","Suriname",
216+
"ss","South Sudan",
217+
"st","Sao Tome and Principe",
218+
"sv","El Salvador",
219+
"sx","Sint Maarten",
220+
"sy","Syrian Arab Republic",
221+
"sz","Swaziland",
222+
"tc","Turks and Caicos Islands",
223+
"td","Chad",
224+
"tf","French Southern Territories",
225+
"tg","Togo",
226+
"th","Thailand",
227+
"tj","Tajikistan",
228+
"tk","Tokelau",
229+
"tl","Timor-Leste",
230+
"tm","Turkmenistan",
231+
"tn","Tunisia",
232+
"to","Tonga",
233+
"tr","Turkey",
234+
"tt","Trinidad and Tobago",
235+
"tv","Tuvalu",
236+
"tw","Taiwan, Republic Of China",
237+
"tz","Tanzania, United Republic of",
238+
"ua","Ukraine",
239+
"ug","Uganda",
240+
"um","United States Minor Outlying Islands",
241+
"us","United States",
242+
"uy","Uruguay",
243+
"uz","Uzbekistan",
244+
"va","Holy See (Vatican City State)",
245+
"vc","Saint Vincent And The Grenadines",
246+
"ve","Venezuela, Bolivarian Republic of",
247+
"vg","Virgin Islands, British",
248+
"vi","Virgin Islands, U.S.",
249+
"vn","Vietnam",
250+
"vu","Vanuatu",
251+
"wf","Wallis and Futuna",
252+
"ws","Samoa",
253+
"xk","Kosovo",
254+
"ye","Yemen",
255+
"yt","Mayotte",
256+
"za","South Africa",
257+
"zm","Zambia",
258+
"zw","Zimbabwe",
259+
]
260+
261+
262+
FLAG_API_LINK = 'https://countryflags.io'
263+
264+
FLAG_ERR_MSG = f'Failed to map country name, \
265+
See {FLAG_API_LINK}/#countries \
266+
for list of supported countries.'
267+
268+
FLAG_SIZE = 32 # (32 | 64)
269+
FLAG_STYLE = 'flat' # (flat | shiny)
270+
271+
COUNTRY_NAMES = COUNTRY_DATA[1::2]
272+
COUNTRY_CODES = COUNTRY_DATA[0::2]

app/marketing/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
from marketing.management.commands.new_bounties_email import get_bounties_for_keywords
5151
from marketing.models import AccountDeletionRequest, EmailSubscriber, Keyword, LeaderboardRank
5252
from marketing.utils import delete_user_from_mailchimp, get_or_save_email_subscriber, validate_slack_integration
53+
from marketing.country_codes import COUNTRY_NAMES, COUNTRY_CODES, \
54+
FLAG_API_LINK, FLAG_ERR_MSG, FLAG_STYLE, FLAG_SIZE
5355
from quests.models import Quest
5456
from retail.emails import ALL_EMAILS, render_new_bounty, render_nth_day_email_campaign
5557
from retail.helpers import get_ip
@@ -790,6 +792,18 @@ def leaderboard(request, key=''):
790792
for tech in techs:
791793
technologies.add(tech)
792794

795+
flags = []
796+
if key == 'countries':
797+
for item in items[0:limit]:
798+
country = item.at_ify_username
799+
code = 'us'
800+
try:
801+
country_index = COUNTRY_NAMES.index(country)
802+
code = COUNTRY_CODES[country_index]
803+
except:
804+
print(f'Error: {FLAG_ERR_MSG}')
805+
flags.append(f'{FLAG_API_LINK}/{code}/{FLAG_STYLE}/{FLAG_SIZE}.png')
806+
793807
if amount:
794808
amount_max = amount[0][0]
795809
top_earners = ranks.order_by('-amount')[0:5].values_list('github_username', flat=True)
@@ -852,7 +866,9 @@ def leaderboard(request, key=''):
852866
next_update = timezone.now() + timezone.timedelta(days=1)
853867

854868
context = {
869+
'key': key,
855870
'items': items[0:limit],
871+
'dual_list': zip(items[0:limit], flags),
856872
'nav': 'home',
857873
'cht': cht,
858874
'titles': titles,

app/retail/templates/leaderboard.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,14 @@ <h1 class="font-title-lg font-weight-semibold mt-2">{% trans "None found" %}</h1
153153
</thead>
154154

155155
<tbody>
156-
{% for item in items %}
156+
{% for item, flag in dual_list %}
157157
<tr class='{% if not is_linked_to_profile %} clickable-row {% endif %} d-flex align-items-stretch' {% if not is_linked_to_profile %} data-href="{{item.url}}" {% endif %} >
158158
<td class="col-2 d-flex align-items-center item-position"># {{forloop.counter}}</td>
159159
<td class="col-6 d-flex align-items-center" >
160160
{% if not is_linked_to_profile %}
161161
<img class="img-fluid" data-src="{{item.avatar_url}}">
162+
{% elif key == "countries" %}
163+
<img class="img-fluid" data-src="{{flag}}">
162164
{% endif %}
163165
<div class="ml-3 item-count-bounties" style="white-space: nowrap">
164166
{% if not is_linked_to_profile %}

0 commit comments

Comments
 (0)