Commits

Ian George committed 3430cfc

Added countries list and country field back into order form

Comments (0)

Files changed (5)

quiet/common/countries.py

+# -*- coding: utf-8 -*-
+from django.utils.translation import ugettext as _
+from django.db import models
+
+#adapted from http://www.djangosnippets.org/snippets/494/
+#using UN country and 3 char code list from http://unstats.un.org/unsd/methods/m49/m49alpha.htm
+#correct as of 17th October 2008
+
+COUNTRIES = (
+    ('AFG', _('Afghanistan')), 
+    ('ALA', _('Aland Islands')),
+    ('ALB', _('Albania')),
+    ('DZA', _('Algeria')),
+    ('ASM', _('American Samoa')),
+    ('AND', _('Andorra')),
+    ('AGO', _('Angola')),
+    ('AIA', _('Anguilla')),
+    ('ATG', _('Antigua and Barbuda')),
+    ('ARG', _('Argentina')),
+    ('ARM', _('Armenia')),
+    ('ABW', _('Aruba')),
+    ('AUS', _('Australia')),
+    ('AUT', _('Austria')),
+    ('AZE', _('Azerbaijan')),
+    ('BHS', _('Bahamas')),
+    ('BHR', _('Bahrain')),
+    ('BGD', _('Bangladesh')),
+    ('BRB', _('Barbados')),
+    ('BLR', _('Belarus')),
+    ('BEL', _('Belgium')),
+    ('BLZ', _('Belize')),
+    ('BEN', _('Benin')),
+    ('BMU', _('Bermuda')),
+    ('BTN', _('Bhutan')),
+    ('BOL', _('Bolivia')),
+    ('BIH', _('Bosnia and Herzegovina')),
+    ('BWA', _('Botswana')),
+    ('BRA', _('Brazil')),
+    ('VGB', _('British Virgin Islands')),
+    ('BRN', _('Brunei Darussalam')),
+    ('BGR', _('Bulgaria')),
+    ('BFA', _('Burkina Faso')),
+    ('BDI', _('Burundi')),
+    ('KHM', _('Cambodia')),
+    ('CMR', _('Cameroon')),
+    ('CAN', _('Canada')),
+    ('CPV', _('Cape Verde')),
+    ('CYM', _('Cayman Islands')),
+    ('CAF', _('Central African Republic')),
+    ('TCD', _('Chad')),
+    ('CIL', _('Channel Islands')),
+    ('CHL', _('Chile')),
+    ('CHN', _('China')),
+    ('HKG', _('China - Hong Kong')),
+    ('MAC', _('China - Macao')),
+    ('COL', _('Colombia')),
+    ('COM', _('Comoros')),
+    ('COG', _('Congo')),
+    ('COK', _('Cook Islands')),
+    ('CRI', _('Costa Rica')),
+    ('CIV', _('Cote d\'Ivoire')),
+    ('HRV', _('Croatia')),
+    ('CUB', _('Cuba')),
+    ('CYP', _('Cyprus')),
+    ('CZE', _('Czech Republic')),
+    ('PRK', _('Democratic People\'s Republic of Korea')),
+    ('COD', _('Democratic Republic of the Congo')),
+    ('DNK', _('Denmark')),
+    ('DJI', _('Djibouti')),
+    ('DMA', _('Dominica')),
+    ('DOM', _('Dominican Republic')),
+    ('ECU', _('Ecuador')),
+    ('EGY', _('Egypt')),
+    ('SLV', _('El Salvador')),
+    ('GNQ', _('Equatorial Guinea')),
+    ('ERI', _('Eritrea')),
+    ('EST', _('Estonia')),
+    ('ETH', _('Ethiopia')),
+    ('FRO', _('Faeroe Islands')),
+    ('FLK', _('Falkland Islands (Malvinas)')),
+    ('FJI', _('Fiji')),
+    ('FIN', _('Finland')),
+    ('FRA', _('France')),
+    ('GUF', _('French Guiana')),
+    ('PYF', _('French Polynesia')),
+    ('GAB', _('Gabon')),
+    ('GMB', _('Gambia')),
+    ('GEO', _('Georgia')),
+    ('DEU', _('Germany')),
+    ('GHA', _('Ghana')),
+    ('GIB', _('Gibraltar')),
+    ('GRC', _('Greece')),
+    ('GRL', _('Greenland')),
+    ('GRD', _('Grenada')),
+    ('GLP', _('Guadeloupe')),
+    ('GUM', _('Guam')),
+    ('GTM', _('Guatemala')),
+    ('GGY', _('Guernsey')),
+    ('GIN', _('Guinea')),
+    ('GNB', _('Guinea-Bissau')),
+    ('GUY', _('Guyana')),
+    ('HTI', _('Haiti')),
+    ('VAT', _('Holy See (Vatican City)')),
+    ('HND', _('Honduras')),
+    ('HUN', _('Hungary')),
+    ('ISL', _('Iceland')),
+    ('IND', _('India')),
+    ('IDN', _('Indonesia')),
+    ('IRN', _('Iran')),
+    ('IRQ', _('Iraq')),
+    ('IRL', _('Ireland')),
+    ('IMN', _('Isle of Man')),
+    ('ISR', _('Israel')),
+    ('ITA', _('Italy')),
+    ('JAM', _('Jamaica')),
+    ('JPN', _('Japan')),
+    ('JEY', _('Jersey')),
+    ('JOR', _('Jordan')),
+    ('KAZ', _('Kazakhstan')),
+    ('KEN', _('Kenya')),
+    ('KIR', _('Kiribati')),
+    ('KWT', _('Kuwait')),
+    ('KGZ', _('Kyrgyzstan')),
+    ('LAO', _('Lao People\'s Democratic Republic')),
+    ('LVA', _('Latvia')),
+    ('LBN', _('Lebanon')),
+    ('LSO', _('Lesotho')),
+    ('LBR', _('Liberia')),
+    ('LBY', _('Libyan Arab Jamahiriya')),
+    ('LIE', _('Liechtenstein')),
+    ('LTU', _('Lithuania')),
+    ('LUX', _('Luxembourg')),
+    ('MKD', _('Macedonia')),
+    ('MDG', _('Madagascar')),
+    ('MWI', _('Malawi')),
+    ('MYS', _('Malaysia')),
+    ('MDV', _('Maldives')),
+    ('MLI', _('Mali')),
+    ('MLT', _('Malta')),
+    ('MHL', _('Marshall Islands')),
+    ('MTQ', _('Martinique')),
+    ('MRT', _('Mauritania')),
+    ('MUS', _('Mauritius')),
+    ('MYT', _('Mayotte')),
+    ('MEX', _('Mexico')),
+    ('FSM', _('Micronesia, Federated States of')),
+    ('MCO', _('Monaco')),
+    ('MNG', _('Mongolia')),
+    ('MNE', _('Montenegro')),
+    ('MSR', _('Montserrat')),
+    ('MAR', _('Morocco')),
+    ('MOZ', _('Mozambique')),
+    ('MMR', _('Myanmar')),
+    ('NAM', _('Namibia')),
+    ('NRU', _('Nauru')),
+    ('NPL', _('Nepal')),
+    ('NLD', _('Netherlands')),
+    ('ANT', _('Netherlands Antilles')),
+    ('NCL', _('New Caledonia')),
+    ('NZL', _('New Zealand')),
+    ('NIC', _('Nicaragua')),
+    ('NER', _('Niger')),
+    ('NGA', _('Nigeria')),
+    ('NIU', _('Niue')),
+    ('NFK', _('Norfolk Island')),
+    ('MNP', _('Northern Mariana Islands')),
+    ('NOR', _('Norway')),
+    ('PSE', _('Occupied Palestinian Territory')),
+    ('OMN', _('Oman')),
+    ('PAK', _('Pakistan')),
+    ('PLW', _('Palau')),
+    ('PAN', _('Panama')),
+    ('PNG', _('Papua New Guinea')),
+    ('PRY', _('Paraguay')),
+    ('PER', _('Peru')),
+    ('PHL', _('Philippines')),
+    ('PCN', _('Pitcairn')),
+    ('POL', _('Poland')),
+    ('PRT', _('Portugal')),
+    ('PRI', _('Puerto Rico')),
+    ('QAT', _('Qatar')),
+    ('KOR', _('Republic of Korea')),
+    ('MDA', _('Republic of Moldova')),
+    ('REU', _('Reunion')),
+    ('ROU', _('Romania')),
+    ('RUS', _('Russian Federation')),
+    ('RWA', _('Rwanda')),
+    ('BLM', _('Saint-Barthelemy')),
+    ('SHN', _('Saint Helena')),
+    ('KNA', _('Saint Kitts and Nevis')),
+    ('LCA', _('Saint Lucia')),
+    ('MAF', _('Saint-Martin (French part)')),
+    ('SPM', _('Saint Pierre and Miquelon')),
+    ('VCT', _('Saint Vincent and the Grenadines')),
+    ('WSM', _('Samoa')),
+    ('SMR', _('San Marino')),
+    ('STP', _('Sao Tome and Principe')),
+    ('SAU', _('Saudi Arabia')),
+    ('SEN', _('Senegal')),
+    ('SRB', _('Serbia')),
+    ('SYC', _('Seychelles')),
+    ('SLE', _('Sierra Leone')),
+    ('SGP', _('Singapore')),
+    ('SVK', _('Slovakia')),
+    ('SVN', _('Slovenia')),
+    ('SLB', _('Solomon Islands')),
+    ('SOM', _('Somalia')),
+    ('ZAF', _('South Africa')),
+    ('ESP', _('Spain')),
+    ('LKA', _('Sri Lanka')),
+    ('SDN', _('Sudan')),
+    ('SUR', _('Suriname')),
+    ('SJM', _('Svalbard and Jan Mayen Islands')),
+    ('SWZ', _('Swaziland')),
+    ('SWE', _('Sweden')),
+    ('CHE', _('Switzerland')),
+    ('SYR', _('Syrian Arab Republic')),
+    ('TJK', _('Tajikistan')),
+    ('THA', _('Thailand')),
+    ('TLS', _('Timor-Leste')),
+    ('TGO', _('Togo')),
+    ('TKL', _('Tokelau')),
+    ('TON', _('Tonga')),
+    ('TTO', _('Trinidad and Tobago')),
+    ('TUN', _('Tunisia')),
+    ('TUR', _('Turkey')),
+    ('TKM', _('Turkmenistan')),
+    ('TCA', _('Turks and Caicos Islands')),
+    ('TUV', _('Tuvalu')),
+    ('UGA', _('Uganda')),
+    ('UKR', _('Ukraine')),
+    ('ARE', _('United Arab Emirates')),
+    ('GBR', _('United Kingdom')),
+    ('TZA', _('United Republic of Tanzania')),
+    ('USA', _('United States of America')),
+    ('VIR', _('United States Virgin Islands')),
+    ('URY', _('Uruguay')),
+    ('UZB', _('Uzbekistan')),
+    ('VUT', _('Vanuatu')),
+    ('VEN', _('Venezuela (Bolivarian Republic of)')),
+    ('VNM', _('Viet Nam')),
+    ('WLF', _('Wallis and Futuna Islands')),
+    ('ESH', _('Western Sahara')),
+    ('YEM', _('Yemen')),
+    ('ZMB', _('Zambia')),
+    ('ZWE', _('Zimbabwe')),
+)
+
+class CountryField(models.CharField):
+    def __init__(self, *args, **kwargs):
+        kwargs.setdefault('max_length', 3)
+        kwargs.setdefault('choices', COUNTRIES)
+        
+        super(CountryField, self).__init__(*args, **kwargs)
+        
+    def get_internal_type(self):
+        return "CharField"

quiet/shop/forms/order.py

 from django import forms
 from form_utils.forms import BetterForm
+from quiet.common.countries import COUNTRIES
 
 class OrderForm(BetterForm):
 #    def __init__(self, gift_certificate=False, *args, **kwargs):
     address3 = forms.CharField(required=False, label="Address 3")
     city = forms.CharField(label="City")
     county = forms.CharField(required=False, label="County")
+    country = forms.ChoiceField(label="Country", choices=COUNTRIES, initial="GBR")
     postcode = forms.RegexField(label="Postcode", regex=r'^(([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2}))$', max_length=10, error_message=("Please enter a valid UK postcode")) 
 
     delivery_telephone = forms.CharField(required=False, label="Telephone")
     delivery_address3 = forms.CharField(required=False, label="Address 3")
     delivery_city = forms.CharField(required=False, label="City")
     delivery_county = forms.CharField(required=False, label="County")
+    delivery_country = forms.ChoiceField(label="Country", choices=COUNTRIES, initial="GBR")
     delivery_postcode = forms.RegexField(required=False, label="Postcode", regex=r'^(([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2}))$', max_length=10, error_message=("Please enter a valid UK postcode")) 
 
     #def clean(self):
     class Meta:
         fieldsets = (
             ('billing', {
-                    'fields': ('first_name', 'last_name', 'email', 'telephone', 'address1', 'address2', 'address3', 'city', 'county', 'postcode'), 
+                    'fields': ('first_name', 'last_name', 'email', 'telephone', 'address1', 'address2', 'address3', 'city', 'county', 'postcode', 'country'), 
                     'legend':'Billing details', 'classes':('half', 'billing')}),
             ('delivery', {
-                    'fields': ('delivery_first_name', 'delivery_last_name', 'delivery_telephone', 'delivery_address1', 'delivery_address2', 'delivery_address3', 'delivery_city', 'delivery_county', 'delivery_postcode'), 
+                    'fields': ('delivery_first_name', 'delivery_last_name', 'delivery_telephone', 'delivery_address1', 'delivery_address2', 'delivery_address3', 'delivery_city', 'delivery_county', 'delivery_postcode', 'delivery_country'), 
                     'legend':'Delivery details <span>(if different from billing details)</span>', 'classes':('half', 'delivery')}),
             )

quiet/shop/models/order.py

 from quiet.shop.utils import debug
 from quiet.shop.session import SessionBasket
 from quiet.common.emails import internal_mail, external_mail
+from quiet.common.countries import CountryField
     
 STATUS_CHOICES = (
     ('new', 'New order'),
     address3 = models.CharField(max_length=255, blank=True)
     city = models.CharField(max_length=255)
     county = models.CharField(max_length=255, blank=True)
-    country = models.CharField(max_length=100, null=True, blank=True)
+    country = CountryField(max_length=100, null=True, blank=True)
     postcode = models.CharField(max_length=50, blank=True) 
     telephone = models.CharField(max_length=40, blank=True)
     email = models.CharField(max_length=255, blank=True)

quiet/shop/session.py

             item.save() 
         signal_basket_update_post.send(sender=self.__class__, basket_id=self.basket_id, content_type=c_type.id, content_id=object_to_update.id, quantity=quantity)
 
-
     def clear(self):
         signal_basket_clear_pre.send(sender=self.__class__, basket_id=self.basket_id)
         for item in self.basket.items.all():
 
     def clear_shipping(self):
         for item in self.basket.shipping_items.all():
-            item.delete()
+            print "DELETED %s" % item
+            item.delete()            
 
     def kill(self, request):
         signal_basket_kill_pre.send(sender=self.__class__, basket_id=self.basket_id)

quiet/shop/views/order.py

             a_billing.city = form.cleaned_data['city']
             a_billing.county = form.cleaned_data['county']
             a_billing.postcode = form.cleaned_data['postcode']
+            a_billing.country = form.cleaned_data['country']
             a_billing.telephone = form.cleaned_data['telephone']
             a_billing.email = form.cleaned_data['email']
             a_billing.save()
                 a_delivery.city = form.cleaned_data['delivery_city']
                 a_delivery.county = form.cleaned_data['delivery_county']
                 a_delivery.postcode = form.cleaned_data['delivery_postcode']
+                a_delivery.country = form.cleaned_data['delivery_country']
+
                 a_delivery.save()
 
             request.session['order_id'] = o.id