Permalink
Browse files

Update BBC TPEG provider to new scheme, also fix postcodes provider

  • Loading branch information...
cnorthwood committed May 27, 2011
1 parent b7d9f12 commit 4df21966367d8803a6722c994f22dcc174451d3d
Showing with 28 additions and 8 deletions.
  1. +25 −5 molly/apps/places/providers/bbc_tpeg.py
  2. +3 −3 molly/apps/places/providers/postcodes.py
@@ -3,10 +3,13 @@
from django.contrib.gis.geos import Point, LineString
from django.conf import settings
+from django.utils.translation import ugettext as _
+from django.utils.translation import ugettext_noop
from molly.apps.places.providers import BaseMapsProvider
from molly.apps.places.models import Source, Entity, EntityType, EntityTypeCategory
from molly.conf.settings import batch
+from molly.utils.i18n import override
class BBCTPEGResolver(etree.Resolver):
"""
@@ -119,14 +122,31 @@ def _get_source(self):
return source
def _get_entity_type(self):
- entity_type, created = EntityType.objects.get_or_create(slug='travel-alert')
- category, created2 = EntityTypeCategory.objects.get_or_create(name='Transport')
- entity_type.verbose_name = 'travel alert'
- entity_type.verbose_name_plural = 'travel alerts'
- entity_type.article = 'a'
+ try:
+ entity_type = EntityType.objects.get(slug='travel-alert')
+ created = False
+ except EntityType.DoesNotExist:
+ entity_type = EntityType(slug='travel-alert')
+ created = True
+ category, etc_created = EntityTypeCategory.objects.get_or_create(name=ugettext_noop('Transport'))
if created:
entity_type.show_in_nearby_list = False
entity_type.show_in_category_list = False
entity_type.category = category
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=_('travel alert'),
+ verbose_name_singular=_('a travel alert'),
+ verbose_name_plural=_('travel alerts'))
+ else:
+ name = name[0]
+ name.verbose_name = _('travel alert')
+ name.verbose_name_singular = _('a travel alert')
+ name.verbose_name_plural = _('travel alerts')
+ name.save()
return entity_type
@@ -10,12 +10,12 @@
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_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.utils.i18n import override
from molly.conf.settings import batch
@@ -98,7 +98,7 @@ def _load_from_csv(self, reader, entity_type, source):
entity.update_all_types_completion()
def _get_entity_type(self):
- category, created = EntityTypeCategory.objects.get_or_create(name=_noop('Uncategorised'))
+ category, created = EntityTypeCategory.objects.get_or_create(name=ugettext_noop('Uncategorised'))
entity_type, created = EntityType.objects.get_or_create(
slug='post-code', category=category)
entity_type.slug = 'post-code'

0 comments on commit 4df2196

Please sign in to comment.