Permalink
Browse files

Move postcode importer to work with new names API

Conflicts:

	molly/apps/places/providers/postcodes.py
  • Loading branch information...
1 parent bdb960f commit b7d9f1215ab35e1ee08be39c9f70fa5ba927626f @cnorthwood cnorthwood committed May 25, 2011
Showing with 30 additions and 5 deletions.
  1. +30 −5 molly/apps/places/providers/postcodes.py
@@ -8,10 +8,14 @@
import os.path
import re
+from django.conf import settings
from django.contrib.gis.geos import Point
+from django.utils.translation import ugettext_noop as _noop
+from django.utils.translation import ugettext as _
from molly.apps.places.providers import BaseMapsProvider
from molly.apps.places.models import Entity, EntityType, Source, EntityTypeCategory
+from molly.utils.misc import override
from molly.conf.settings import batch
@@ -71,7 +75,6 @@ def _load_from_csv(self, reader, entity_type, source):
except Entity.DoesNotExist:
entity = Entity(source=source)
- entity.title = postcode
entity.location = Point(easting, northing, srid=27700)
entity.geometry = entity.location
entity.primary_type = entity_type
@@ -81,21 +84,43 @@ def _load_from_csv(self, reader, entity_type, source):
'postcode-canonical': postcode,
}
entity.save(identifiers=identifiers)
+ titles = entity.names.all()
+ if titles.count() == 0:
+ entity.names.create(
+ language_code=settings.LANGUAGE_CODE,
+ title=postcode
+ )
+ else:
+ for title in titles:
+ title.title = postcode
+ title.save()
entity.all_types.add(entity_type)
entity.update_all_types_completion()
def _get_entity_type(self):
- category, created = EntityTypeCategory.objects.get_or_create(name='Uncategorised')
+ category, created = EntityTypeCategory.objects.get_or_create(name=_noop('Uncategorised'))
entity_type, created = EntityType.objects.get_or_create(
slug='post-code', category=category)
entity_type.slug = 'post-code'
- entity_type.article = 'a'
- entity_type.verbose_name = 'postcode'
- entity_type.verbose_name_plural = 'postcodes'
if created:
entity_type.show_in_nearby_list = False
entity_type.show_in_category_list = False
entity_type.save()
+ for lang_code, lang_name in settings.LANGUAGES:
+ with override(lang_code):
+ name = entity_type.names.filter(language_code=lang_code)
+ if name.count() == 0:
+ entity_type.names.create(
+ language_code=lang_code,
+ verbose_name=_('postcode'),
+ verbose_name_singular=_('a postcode'),
+ verbose_name_plural=_('postcodes'))
+ else:
+ name = name[0]
+ name.verbose_name = _('postcode')
+ name.verbose_name_singular = _('a postcode')
+ name.verbose_name_plural = _('postcodes')
+ name.save()
return entity_type
def _get_source(self):

0 comments on commit b7d9f12

Please sign in to comment.