Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

add schema and Python for countries #3999

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions gratipay/models/country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import absolute_import, division, print_function, unicode_literals

from postgres.orm import Model


class Country(Model):
"""Represent country records from our database (read-only).

:var int id: the record's primary key in our ``countries`` table
:var unicode name: the name of the country
:var unicode code2: the country's `ISO 3166-1 alpha-2`_ code
:var unicode code3: the country's `ISO 3166-1 alpha-3`_ code

.. _ISO 3166-1 alpha-2 : https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
.. _ISO 3166-1 alpha-3 : https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3

"""
typname = 'countries'
2 changes: 1 addition & 1 deletion gratipay/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Harness(unittest.TestCase):
db = client.website.db
platforms = client.website.platforms
tablenames = db.all("SELECT tablename FROM pg_tables "
"WHERE schemaname='public'")
"WHERE schemaname='public' AND tablename != 'countries'")
seq = itertools.count(0)


Expand Down
3 changes: 2 additions & 1 deletion gratipay/wireup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from gratipay.elsewhere.venmo import Venmo
from gratipay.models.account_elsewhere import AccountElsewhere
from gratipay.models.community import Community
from gratipay.models.country import Country
from gratipay.models.exchange_route import ExchangeRoute
from gratipay.models.participant import Participant
from gratipay.models.team import Team
Expand All @@ -54,7 +55,7 @@ def db(env):
maxconn = env.database_maxconn
db = GratipayDB(dburl, maxconn=maxconn)

for model in (AccountElsewhere, Community, ExchangeRoute, Participant, Team):
for model in (AccountElsewhere, Community, Country, ExchangeRoute, Participant, Team):
db.register_model(model)
gratipay.billing.payday.Payday.db = db

Expand Down
6 changes: 6 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE countries -- http://www.iso.org/iso/country_codes
( id bigserial primary key
, code text NOT NULL UNIQUE
);

\i sql/countries.sql
28 changes: 28 additions & 0 deletions sql/countries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- scraped from https://www.iso.org/obp/ui/#search
INSERT INTO countries (code)
VALUES ('AD') , ('AE') , ('AF') , ('AG') , ('AI') , ('AL') , ('AM') , ('AO') , ('AQ') , ('AR')
, ('AS') , ('AT') , ('AU') , ('AW') , ('AX') , ('AZ') , ('BA') , ('BB') , ('BD') , ('BE')
, ('BF') , ('BG') , ('BH') , ('BI') , ('BJ') , ('BL') , ('BM') , ('BN') , ('BO') , ('BQ')
, ('BR') , ('BS') , ('BT') , ('BV') , ('BW') , ('BY') , ('BZ') , ('CA') , ('CC') , ('CD')
, ('CF') , ('CG') , ('CH') , ('CI') , ('CK') , ('CL') , ('CM') , ('CN') , ('CO') , ('CR')
, ('CU') , ('CV') , ('CW') , ('CX') , ('CY') , ('CZ') , ('DE') , ('DJ') , ('DK') , ('DM')
, ('DO') , ('DZ') , ('EC') , ('EE') , ('EG') , ('EH') , ('ER') , ('ES') , ('ET') , ('FI')
, ('FJ') , ('FK') , ('FM') , ('FO') , ('FR') , ('GA') , ('GB') , ('GD') , ('GE') , ('GF')
, ('GG') , ('GH') , ('GI') , ('GL') , ('GM') , ('GN') , ('GP') , ('GQ') , ('GR') , ('GS')
, ('GT') , ('GU') , ('GW') , ('GY') , ('HK') , ('HM') , ('HN') , ('HR') , ('HT') , ('HU')
, ('ID') , ('IE') , ('IL') , ('IM') , ('IN') , ('IO') , ('IQ') , ('IR') , ('IS') , ('IT')
, ('JE') , ('JM') , ('JO') , ('JP') , ('KE') , ('KG') , ('KH') , ('KI') , ('KM') , ('KN')
, ('KP') , ('KR') , ('KW') , ('KY') , ('KZ') , ('LA') , ('LB') , ('LC') , ('LI') , ('LK')
, ('LR') , ('LS') , ('LT') , ('LU') , ('LV') , ('LY') , ('MA') , ('MC') , ('MD') , ('ME')
, ('MF') , ('MG') , ('MH') , ('MK') , ('ML') , ('MM') , ('MN') , ('MO') , ('MP') , ('MQ')
, ('MR') , ('MS') , ('MT') , ('MU') , ('MV') , ('MW') , ('MX') , ('MY') , ('MZ') , ('NA')
, ('NC') , ('NE') , ('NF') , ('NG') , ('NI') , ('NL') , ('NO') , ('NP') , ('NR') , ('NU')
, ('NZ') , ('OM') , ('PA') , ('PE') , ('PF') , ('PG') , ('PH') , ('PK') , ('PL') , ('PM')
, ('PN') , ('PR') , ('PS') , ('PT') , ('PW') , ('PY') , ('QA') , ('RE') , ('RO') , ('RS')
, ('RU') , ('RW') , ('SA') , ('SB') , ('SC') , ('SD') , ('SE') , ('SG') , ('SH') , ('SI')
, ('SJ') , ('SK') , ('SL') , ('SM') , ('SN') , ('SO') , ('SR') , ('SS') , ('ST') , ('SV')
, ('SX') , ('SY') , ('SZ') , ('TC') , ('TD') , ('TF') , ('TG') , ('TH') , ('TJ') , ('TK')
, ('TL') , ('TM') , ('TN') , ('TO') , ('TR') , ('TT') , ('TV') , ('TW') , ('TZ') , ('UA')
, ('UG') , ('UM') , ('US') , ('UY') , ('UZ') , ('VA') , ('VC') , ('VE') , ('VG') , ('VI')
, ('VN') , ('VU') , ('WF') , ('WS') , ('YE') , ('YT') , ('ZA') , ('ZM') , ('ZW')
;