Skip to content

Commit

Permalink
Move postcode importer to work with new names API
Browse files Browse the repository at this point in the history
Conflicts:

	molly/apps/places/providers/postcodes.py
  • Loading branch information
cnorthwood committed May 27, 2011
1 parent bdb960f commit b7d9f12
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions molly/apps/places/providers/postcodes.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import os.path import os.path
import re import re


from django.conf import settings
from django.contrib.gis.geos import Point 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.providers import BaseMapsProvider
from molly.apps.places.models import Entity, EntityType, Source, EntityTypeCategory from molly.apps.places.models import Entity, EntityType, Source, EntityTypeCategory
from molly.utils.misc import override


from molly.conf.settings import batch from molly.conf.settings import batch


Expand Down Expand Up @@ -71,7 +75,6 @@ def _load_from_csv(self, reader, entity_type, source):
except Entity.DoesNotExist: except Entity.DoesNotExist:
entity = Entity(source=source) entity = Entity(source=source)


entity.title = postcode
entity.location = Point(easting, northing, srid=27700) entity.location = Point(easting, northing, srid=27700)
entity.geometry = entity.location entity.geometry = entity.location
entity.primary_type = entity_type entity.primary_type = entity_type
Expand All @@ -81,21 +84,43 @@ def _load_from_csv(self, reader, entity_type, source):
'postcode-canonical': postcode, 'postcode-canonical': postcode,
} }
entity.save(identifiers=identifiers) 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.all_types.add(entity_type)
entity.update_all_types_completion() entity.update_all_types_completion()


def _get_entity_type(self): 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( entity_type, created = EntityType.objects.get_or_create(
slug='post-code', category=category) slug='post-code', category=category)
entity_type.slug = 'post-code' entity_type.slug = 'post-code'
entity_type.article = 'a'
entity_type.verbose_name = 'postcode'
entity_type.verbose_name_plural = 'postcodes'
if created: if created:
entity_type.show_in_nearby_list = False entity_type.show_in_nearby_list = False
entity_type.show_in_category_list = False entity_type.show_in_category_list = False
entity_type.save() 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 return entity_type


def _get_source(self): def _get_source(self):
Expand Down

0 comments on commit b7d9f12

Please sign in to comment.