#-- encoding: utf-8 --
#
# This file is part of I4P.
#
# I4P is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# I4P is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with I4P. If not, see <http://www.gnu.org/licenses/>.
#
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_countries import CountryField
I4P_COUNTRIES = (
('AF', _(u'Afghanistan')),
('AX', _(u'\xc5land Islands')),
('AL', _(u'Albania')),
('DZ', _(u'Algeria')),
('AS', _(u'American Samoa')),
('AD', _(u'Andorra')),
('AO', _(u'Angola')),
('AI', _(u'Anguilla')),
('AQ', _(u'Antarctica')),
('AG', _(u'Antigua and Barbuda')),
('AR', _(u'Argentina')),
('AM', _(u'Armenia')),
('AW', _(u'Aruba')),
('AU', _(u'Australia')),
('AT', _(u'Austria')),
('AZ', _(u'Azerbaijan')),
('BS', _(u'Bahamas')),
('BH', _(u'Bahrain')),
('BD', _(u'Bangladesh')),
('BB', _(u'Barbados')),
('BY', _(u'Belarus')),
('BE', _(u'Belgium')),
('BZ', _(u'Belize')),
('BJ', _(u'Benin')),
('BM', _(u'Bermuda')),
('BT', _(u'Bhutan')),
('BO', _(u'Bolivia')),
('BA', _(u'Bosnia and Herzegovina')),
('BW', _(u'Botswana')),
('BV', _(u'Bouvet Island')),
('BR', _(u'Brazil')),
# ('IO', _(u'British Indian Ocean Territory')),
('BN', _(u'Brunei Darussalam')),
('BG', _(u'Bulgaria')),
('BF', _(u'Burkina Faso')),
('BI', _(u'Burundi')),
('KH', _(u'Cambodia')),
('CM', _(u'Cameroon')),
('CA', _(u'Canada')),
('CV', _(u'Cape Verde')),
('KY', _(u'Cayman Islands')),
('CF', _(u'Central African Republic')),
('TD', _(u'Chad')),
('CL', _(u'Chile')),
('CN', _(u'China')),
('CX', _(u'Christmas Island')),
('CC', _(u'Cocos (Keeling) Islands')),
('CO', _(u'Colombia')),
('KM', _(u'Comoros')),
('CG', _(u'Congo')),
('CD', _(u'Congo, The Democratic Republic of the')),
('CK', _(u'Cook Islands')),
('CR', _(u'Costa Rica')),
('CI', _(u"C\xf4te D'ivoire")),
('HR', _(u'Croatia')),
('CU', _(u'Cuba')),
('CY', _(u'Cyprus')),
('CZ', _(u'Czech Republic')),
('DK', _(u'Denmark')),
('DJ', _(u'Djibouti')),
('DM', _(u'Dominica')),
('DO', _(u'Dominican Republic')),
('EC', _(u'Ecuador')),
('EG', _(u'Egypt')),
('SV', _(u'El Salvador')),
('GQ', _(u'Equatorial Guinea')),
('ER', _(u'Eritrea')),
('EE', _(u'Estonia')),
('ET', _(u'Ethiopia')),
('FK', _(u'Falkland Islands (Malvinas)')),
('FO', _(u'Faroe Islands')),
('FJ', _(u'Fiji')),
('FI', _(u'Finland')),
('FR', _(u'France')),
('GF', _(u'French Guiana')),
('PF', _(u'French Polynesia')),
('TF', _(u'French Southern Territories')),
('GA', _(u'Gabon')),
('GM', _(u'Gambia')),
('GE', _(u'Georgia')),
('DE', _(u'Germany')),
('GH', _(u'Ghana')),
('GI', _(u'Gibraltar')),
('GR', _(u'Greece')),
('GL', _(u'Greenland')),
('GD', _(u'Grenada')),
('GP', _(u'Guadeloupe')),
('GU', _(u'Guam')),
('GT', _(u'Guatemala')),
('GG', _(u'Guernsey')),
('GN', _(u'Guinea')),
('GW', _(u'Guinea-bissau')),
('GY', _(u'Guyana')),
('HT', _(u'Haiti')),
# ('HM', _(u'Heard Island and McDonald Islands')),
# ('VA', _(u'Holy See (Vatican City State)')),
('HN', _(u'Honduras')),
('HK', _(u'Hong Kong')),
('HU', _(u'Hungary')),
('IS', _(u'Iceland')),
('IN', _(u'India')),
('ID', _(u'Indonesia')),
('IR', _(u'Iran')),
('IQ', _(u'Iraq')),
('IE', _(u'Ireland')),
('IM', _(u'Isle of Man')),
('IL', _(u'Israel')),
('IT', _(u'Italy')),
('JM', _(u'Jamaica')),
('JP', _(u'Japan')),
('JE', _(u'Jersey')),
('JO', _(u'Jordan')),
('KZ', _(u'Kazakhstan')),
('KE', _(u'Kenya')),
('KI', _(u'Kiribati')),
('KP', _(u"North Korea")),
('KR', _(u'South Korea')),
('KW', _(u'Kuwait')),
('KG', _(u'Kyrgyzstan')),
('LA', _(u"Lao People's Democratic Republic")),
('LV', _(u'Latvia')),
('LB', _(u'Lebanon')),
('LS', _(u'Lesotho')),
('LR', _(u'Liberia')),
('LY', _(u'Libyan Arab Jamahiriya')),
('LI', _(u'Liechtenstein')),
('LT', _(u'Lithuania')),
('LU', _(u'Luxembourg')),
('MO', _(u'Macao')),
('MK', _(u'Macedonia')),
('MG', _(u'Madagascar')),
('MW', _(u'Malawi')),
('MY', _(u'Malaysia')),
('MV', _(u'Maldives')),
('ML', _(u'Mali')),
('MT', _(u'Malta')),
('MH', _(u'Marshall Islands')),
('MQ', _(u'Martinique')),
('MR', _(u'Mauritania')),
('MU', _(u'Mauritius')),
('YT', _(u'Mayotte')),
('MX', _(u'Mexico')),
# ('FM', _(u'Micronesia, Federated States of')),
('MD', _(u'Moldova, Republic of')),
('MC', _(u'Monaco')),
('MN', _(u'Mongolia')),
('ME', _(u'Montenegro')),
('MS', _(u'Montserrat')),
('MA', _(u'Morocco')),
('MZ', _(u'Mozambique')),
('MM', _(u'Myanmar')),
('NA', _(u'Namibia')),
('NR', _(u'Nauru')),
('NP', _(u'Nepal')),
('NL', _(u'Netherlands')),
('AN', _(u'Netherlands Antilles')),
('NC', _(u'New Caledonia')),
('NZ', _(u'New Zealand')),
('NI', _(u'Nicaragua')),
('NE', _(u'Niger')),
('NG', _(u'Nigeria')),
('NU', _(u'Niue')),
('NF', _(u'Norfolk Island')),
('MP', _(u'Northern Mariana Islands')),
('NO', _(u'Norway')),
('OM', _(u'Oman')),
('PK', _(u'Pakistan')),
('PW', _(u'Palau')),
('PS', _(u'Palestinian Territory, Occupied')),
('PA', _(u'Panama')),
('PG', _(u'Papua New Guinea')),
('PY', _(u'Paraguay')),
('PE', _(u'Peru')),
('PH', _(u'Philippines')),
('PN', _(u'Pitcairn')),
('PL', _(u'Poland')),
('PT', _(u'Portugal')),
('PR', _(u'Puerto Rico')),
('QA', _(u'Qatar')),
('RE', _(u'R\xe9union')),
('RO', _(u'Romania')),
('RU', _(u'Russian Federation')),
('RW', _(u'Rwanda')),
('BL', _(u'Saint Barth\xe9lemy')),
# ('SH', _(u'Saint Helena, Ascension and Tristan Da Cunha')),
('KN', _(u'Saint Kitts and Nevis')),
('LC', _(u'Saint Lucia')),
('MF', _(u'Saint Martin')),
('PM', _(u'Saint Pierre and Miquelon')),
('VC', _(u'Saint Vincent and the Grenadines')),
('WS', _(u'Samoa')),
('SM', _(u'San Marino')),
('ST', _(u'Sao Tome and Principe')),
('SA', _(u'Saudi Arabia')),
('SN', _(u'Senegal')),
('RS', _(u'Serbia')),
('SC', _(u'Seychelles')),
('SL', _(u'Sierra Leone')),
('SG', _(u'Singapore')),
('SK', _(u'Slovakia')),
('SI', _(u'Slovenia')),
('SB', _(u'Solomon Islands')),
('SO', _(u'Somalia')),
('ZA', _(u'South Africa')),
# ('GS', _(u'South Georgia and the South Sandwich Islands')),
('ES', _(u'Spain')),
('LK', _(u'Sri Lanka')),
('SD', _(u'Sudan')),
('SR', _(u'Suriname')),
('SJ', _(u'Svalbard and Jan Mayen')),
('SZ', _(u'Swaziland')),
('SE', _(u'Sweden')),
('CH', _(u'Switzerland')),
('SY', _(u'Syrian Arab Republic')),
('TW', _(u'Taiwan')),
('TJ', _(u'Tajikistan')),
('TZ', _(u'Tanzania')),
('TH', _(u'Thailand')),
('TL', _(u'Timor-leste')),
('TG', _(u'Togo')),
('TK', _(u'Tokelau')),
('TO', _(u'Tonga')),
('TT', _(u'Trinidad and Tobago')),
('TN', _(u'Tunisia')),
('TR', _(u'Turkey')),
('TM', _(u'Turkmenistan')),
('TC', _(u'Turks and Caicos Islands')),
('TV', _(u'Tuvalu')),
('UG', _(u'Uganda')),
('UA', _(u'Ukraine')),
('AE', _(u'United Arab Emirates')),
('GB', _(u'United Kingdom')),
('US', _(u'United States')),
# ('UM', _(u'United States Minor Outlying Islands')),
('UY', _(u'Uruguay')),
('UZ', _(u'Uzbekistan')),
('VU', _(u'Vanuatu')),
('VE', _(u'Venezuela')),
('VN', _(u'Viet Nam')),
('VG', _(u'Virgin Islands, British')),
('VI', _(u'Virgin Islands, U.S.')),
('WF', _(u'Wallis and Futuna')),
('EH', _(u'Western Sahara')),
('YE', _(u'Yemen')),
('ZM', _(u'Zambia')),
('ZW', _(u'Zimbabwe')),
)
[docs]class Location(models.Model):
"""
A generic location model designed to be used to localize any object
"""
lat = models.FloatField(verbose_name=_('latitude'),
null=True, blank=True)
lon = models.FloatField(verbose_name=_('longitude'),
null=True, blank=True)
country = CountryField(verbose_name=_('country'), choices=I4P_COUNTRIES,
null=True, blank=True)
address = models.TextField(verbose_name=_('address'),
null=True, blank=True)
def __unicode__(self):
return u"%s %s (%s, %s)" % (self.address,
self.get_country_display(),
self.lon,
self.lat)