Skip to content

Commit

Permalink
feature - add flags to leaderboard (#6509)
Browse files Browse the repository at this point in the history
* add flags to leaderboard

* remove conversion to list

* switch csv to python file and clean up flag logic

Co-authored-by: Dan Lipert <[email protected]>
Co-authored-by: Aditya Anand M C <[email protected]>
  • Loading branch information
3 people authored May 13, 2020
1 parent 037aeab commit 144365c
Show file tree
Hide file tree
Showing 3 changed files with 291 additions and 1 deletion.
272 changes: 272 additions & 0 deletions app/marketing/country_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
COUNTRY_DATA =[
"us","United States",
"ad","Andorra",
"ae","United Arab Emirates",
"af","Afghanistan",
"ag","Antigua and Barbuda",
"ai","Anguilla",
"ah","Artsakh",
"ak","Abkhazia",
"al","Albania",
"am","Armenia",
"an","Netherlands Antilles",
"ao","Angola",
"aq","Antarctica",
"ar","Argentina",
"as","American Samoa",
"at","Austria",
"au","Australia",
"aw","Aruba",
"ax","Åland Islands",
"az","Azerbaijan",
"ba","Bosnia and Herzegovina",
"bb","Barbados",
"bd","Bangladesh",
"be","Belgium",
"bf","Burkina Faso",
"bg","Bulgaria",
"bh","Bahrain",
"bi","Burundi",
"bj","Benin",
"bl","Saint Barthélemy",
"bm","Bermuda",
"bn","Brunei Darussalam",
"bo","Bolivia",
"bq","Bonaire, Sint Eustatius and Saba",
"br","Brazil",
"bs","Bahamas",
"bt","Bhutan",
"bv","Bouvet Island",
"bw","Botswana",
"by","Belarus",
"bz","Belize",
"ca","Canada",
"cc","Cocos (Keeling) Islands",
"cd","Congo, The Democratic Republic Of The",
"cf","Central African Republic",
"cg","Congo",
"ch","Switzerland",
"ci","Côte D'Ivoire",
"ck","Cook Islands",
"cl","Chile",
"cm","Cameroon",
"cn","China",
"co","Colombia",
"cr","Costa Rica",
"cu","Cuba",
"cv","Cape Verde",
"cw","Curaçao",
"cx","Christmas Island",
"cy","Cyprus",
"cz","Czech Republic",
"de","Germany",
"dj","Djibouti",
"dk","Denmark",
"dm","Dominica",
"do","Dominican Republic",
"dz","Algeria",
"ec","Ecuador",
"ee","Estonia",
"eg","Egypt",
"eh","Western Sahara",
"er","Eritrea",
"es","Spain",
"et","Ethiopia",
"eu","Europe",
"fi","Finland",
"fj","Fiji",
"fk","Falkland Islands (Malvinas)",
"fm","Micronesia, Federated States Of",
"fo","Faroe Islands",
"fr","France",
"ga","Gabon",
"gb","United Kingdom",
"gd","Grenada",
"ge","Georgia",
"gf","French Guiana",
"gg","Guernsey",
"gh","Ghana",
"gi","Gibraltar",
"gl","Greenland",
"gm","Gambia",
"gn","Guinea",
"gp","Guadeloupe",
"gq","Equatorial Guinea",
"gr","Greece",
"gs","South Georgia and the South Sandwich Islands",
"gt","Guatemala",
"gu","Guam",
"gw","Guinea-Bissau",
"gy","Guyana",
"hk","Hong Kong",
"hm","Heard and McDonald Islands",
"hn","Honduras",
"hr","Croatia",
"ht","Haiti",
"hu","Hungary",
"ic","Canary Islands",
"id","Indonesia",
"ie","Ireland",
"il","Israel",
"im","Isle of Man",
"in","India",
"io","British Indian Ocean Territory",
"iq","Iraq",
"ir","Iran, Islamic Republic Of",
"is","Iceland",
"it","Italy",
"je","Jersey",
"jm","Jamaica",
"jo","Jordan",
"jp","Japan",
"ke","Kenya",
"kg","Kyrgyzstan",
"kh","Cambodia",
"ki","Kiribati",
"km","Comoros",
"kn","Saint Kitts And Nevis",
"kp","Korea, Democratic People's Republic Of",
"kr","Korea, Republic of",
"kw","Kuwait",
"ky","Cayman Islands",
"kz","Kazakhstan",
"la","Lao People's Democratic Republic",
"lb","Lebanon",
"lc","Saint Lucia",
"li","Liechtenstein",
"lk","Sri Lanka",
"lr","Liberia",
"ls","Lesotho",
"lt","Lithuania",
"lu","Luxembourg",
"lv","Latvia",
"ly","Libya",
"ma","Morocco",
"mc","Monaco",
"md","Moldova, Republic of",
"me","Montenegro",
"mf","Saint Martin",
"mg","Madagascar",
"mh","Marshall Islands",
"mk","Macedonia, the Former Yugoslav Republic Of",
"ml","Mali",
"mm","Myanmar",
"mn","Mongolia",
"mo","Macao",
"mp","Northern Mariana Islands",
"mq","Martinique",
"mr","Mauritania",
"ms","Montserrat",
"mt","Malta",
"mu","Mauritius",
"mv","Maldives",
"mw","Malawi",
"mx","Mexico",
"my","Malaysia",
"mz","Mozambique",
"na","Namibia",
"nc","New Caledonia",
"ne","Niger",
"nf","Norfolk Island",
"ng","Nigeria",
"ni","Nicaragua",
"nl","Netherlands",
"no","Norway",
"np","Nepal",
"nr","Nauru",
"nu","Niue",
"ny","Northern Cyprus",
"nz","New Zealand",
"om","Oman",
"pa","Panama",
"pe","Peru",
"pf","French Polynesia",
"pg","Papua New Guinea",
"ph","Philippines",
"pk","Pakistan",
"pl","Poland",
"pm","Saint Pierre And Miquelon",
"pn","Pitcairn",
"pr","Puerto Rico",
"ps","Palestine, State of",
"pt","Portugal",
"pw","Palau",
"py","Paraguay",
"qa","Qatar",
"re","Réunion",
"ro","Romania",
"rs","Serbia",
"ru","Russian Federation",
"rw","Rwanda",
"sa","Saudi Arabia",
"sb","Solomon Islands",
"sc","Seychelles",
"sd","Sudan",
"se","Sweden",
"sg","Singapore",
"sh","Saint Helena",
"si","Slovenia",
"sj","Svalbard And Jan Mayen",
"sk","Slovakia",
"sl","Sierra Leone",
"sm","San Marino",
"sn","Senegal",
"so","Somalia",
"sr","Suriname",
"ss","South Sudan",
"st","Sao Tome and Principe",
"sv","El Salvador",
"sx","Sint Maarten",
"sy","Syrian Arab Republic",
"sz","Swaziland",
"tc","Turks and Caicos Islands",
"td","Chad",
"tf","French Southern Territories",
"tg","Togo",
"th","Thailand",
"tj","Tajikistan",
"tk","Tokelau",
"tl","Timor-Leste",
"tm","Turkmenistan",
"tn","Tunisia",
"to","Tonga",
"tr","Turkey",
"tt","Trinidad and Tobago",
"tv","Tuvalu",
"tw","Taiwan, Republic Of China",
"tz","Tanzania, United Republic of",
"ua","Ukraine",
"ug","Uganda",
"um","United States Minor Outlying Islands",
"us","United States",
"uy","Uruguay",
"uz","Uzbekistan",
"va","Holy See (Vatican City State)",
"vc","Saint Vincent And The Grenadines",
"ve","Venezuela, Bolivarian Republic of",
"vg","Virgin Islands, British",
"vi","Virgin Islands, U.S.",
"vn","Vietnam",
"vu","Vanuatu",
"wf","Wallis and Futuna",
"ws","Samoa",
"xk","Kosovo",
"ye","Yemen",
"yt","Mayotte",
"za","South Africa",
"zm","Zambia",
"zw","Zimbabwe",
]


FLAG_API_LINK = 'https://countryflags.io'

FLAG_ERR_MSG = f'Failed to map country name, \
See {FLAG_API_LINK}/#countries \
for list of supported countries.'

FLAG_SIZE = 32 # (32 | 64)
FLAG_STYLE = 'flat' # (flat | shiny)

COUNTRY_NAMES = COUNTRY_DATA[1::2]
COUNTRY_CODES = COUNTRY_DATA[0::2]
16 changes: 16 additions & 0 deletions app/marketing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
from marketing.management.commands.new_bounties_email import get_bounties_for_keywords
from marketing.models import AccountDeletionRequest, EmailSubscriber, Keyword, LeaderboardRank
from marketing.utils import delete_user_from_mailchimp, get_or_save_email_subscriber, validate_slack_integration
from marketing.country_codes import COUNTRY_NAMES, COUNTRY_CODES, \
FLAG_API_LINK, FLAG_ERR_MSG, FLAG_STYLE, FLAG_SIZE
from quests.models import Quest
from retail.emails import ALL_EMAILS, render_new_bounty, render_nth_day_email_campaign
from retail.helpers import get_ip
Expand Down Expand Up @@ -790,6 +792,18 @@ def leaderboard(request, key=''):
for tech in techs:
technologies.add(tech)

flags = []
if key == 'countries':
for item in items[0:limit]:
country = item.at_ify_username
code = 'us'
try:
country_index = COUNTRY_NAMES.index(country)
code = COUNTRY_CODES[country_index]
except:
print(f'Error: {FLAG_ERR_MSG}')
flags.append(f'{FLAG_API_LINK}/{code}/{FLAG_STYLE}/{FLAG_SIZE}.png')

if amount:
amount_max = amount[0][0]
top_earners = ranks.order_by('-amount')[0:5].values_list('github_username', flat=True)
Expand Down Expand Up @@ -852,7 +866,9 @@ def leaderboard(request, key=''):
next_update = timezone.now() + timezone.timedelta(days=1)

context = {
'key': key,
'items': items[0:limit],
'dual_list': zip(items[0:limit], flags),
'nav': 'home',
'cht': cht,
'titles': titles,
Expand Down
4 changes: 3 additions & 1 deletion app/retail/templates/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ <h1 class="font-title-lg font-weight-semibold mt-2">{% trans "None found" %}</h1
</thead>

<tbody>
{% for item in items %}
{% for item, flag in dual_list %}
<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 %} >
<td class="col-2 d-flex align-items-center item-position"># {{forloop.counter}}</td>
<td class="col-6 d-flex align-items-center" >
{% if not is_linked_to_profile %}
<img class="img-fluid" data-src="{{item.avatar_url}}">
{% elif key == "countries" %}
<img class="img-fluid" data-src="{{flag}}">
{% endif %}
<div class="ml-3 item-count-bounties" style="white-space: nowrap">
{% if not is_linked_to_profile %}
Expand Down

1 comment on commit 144365c

@owocki
Copy link
Contributor

@owocki owocki commented on 144365c May 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this tested? it broke https://gitcoin.co/leaderboard on everything BUT the countries list

https://bits.owocki.com/NQuDn1l6

putting in fix for 9aad3f0, but itll not display the flags now

Please sign in to comment.