def _get_countries_by_prefix(self, prefix): for country in Country.find_prefix('name', prefix): yield {"name": country.name, "slug": country.slug, "label": self._get_html_label(country.name, country.code), "capital_city": country.relation_set.capital_city.name, "ranking": None}
def migrate_country(entry): """ Migration of a JSON-represented country. """ try: corresp_map = { 'code': entry['fields']['code'], 'wikiname': entry['fields']['wikiname'], 'currency': entry['fields']['currency'], 'slug': entry['fields']['slug'], 'name': entry['fields']['name'], } additional_corresp_map = { 'old_pk': entry['pk'], 'old_capitalcity_pk': entry['fields']['capital_city'], } except KeyError: raise RuntimeError(u"Invalid JSON configuration: %s" % str(entry)) country = Country.find_one({'code': entry['fields']['code']}) if not country: country = Country() country.set_lang("en") for k, v in corresp_map.iteritems(): setattr(country, k, v) for k, v in additional_corresp_map.iteritems(): country[k] = v country.save() return country
def _get_countries_by_prefix(self, prefix): for country in Country.find_prefix('name', prefix): yield { "name": country.name, "slug": country.slug, "label": self._get_html_label(country.name, country.code), "capital_city": country.relation_set.capital_city.name, "ranking": None }
def post_migrate(): """ Post-migration phase: index generations, cross-document relationships. """ for country in Country.find(): country['capital_city'] = City.find_one({ 'old_pk': country['old_capitalcity_pk']})._id del country['old_capitalcity_pk'] country.save() for cls in (City, Country, Region): cls.generate_index(cls.collection)
def post_migrate(): """ Post-migration phase: index generations, cross-document relationships. """ for country in Country.find(): country['capital_city'] = City.find_one({ 'old_pk': country['old_capitalcity_pk'] })._id del country['old_capitalcity_pk'] country.save() for cls in (City, Country, Region): cls.generate_index(cls.collection)
def migrate_city(entry): """ Migration of a JSON-represented city. """ corresp_map = { 'wikiname': entry['fields']['wikiname'], 'slug': entry['fields']['slug'], 'name': entry['fields']['name'], 'rankings': [ float(entry['fields']['rating_factor_%d' % idx]) for idx in xrange(1, 4) ], 'timezone': u'UTC%s%d' % (u'' if entry['fields']['timezone'] < 0 else u'+', entry['fields']['timezone']), 'total_ranking': float(entry['fields']['total_rating']), 'coordinates': [ float(entry['fields']['latitude']), float(entry['fields']['longitude']) ], 'country': Country.find_one({ 'old_pk': entry['fields']['country'] })._id, } additional_corresp_map = { 'old_pk': entry['pk'], } city = City.find_one({'old_pk': entry['pk']}) if not city: city = City() city.set_lang("en") for k, v in corresp_map.iteritems(): setattr(city, k, v) for k, v in additional_corresp_map.iteritems(): city[k] = v city.save() return city
def migrate_city(entry): """ Migration of a JSON-represented city. """ corresp_map = { 'wikiname': entry['fields']['wikiname'], 'slug': entry['fields']['slug'], 'name': entry['fields']['name'], 'rankings': [float(entry['fields']['rating_factor_%d' % idx]) for idx in xrange(1, 4)], 'timezone': u'UTC%s%d' % ( u'' if entry['fields']['timezone'] < 0 else u'+', entry['fields']['timezone']), 'total_ranking': float(entry['fields']['total_rating']), 'coordinates': [float(entry['fields']['latitude']), float(entry['fields']['longitude'])], 'country': Country.find_one({ 'old_pk': entry['fields']['country']})._id, } additional_corresp_map = { 'old_pk': entry['pk'], } city = City.find_one({'old_pk': entry['pk']}) if not city: city = City() city.set_lang("en") for k, v in corresp_map.iteritems(): setattr(city, k, v) for k, v in additional_corresp_map.iteritems(): city[k] = v city.save() return city