Exemple #1
0
    def get(self, login_user=None, template_values={}):

        # is import or update going on?
        template_values['update_status'] = memcache.get('update_status')
        template_values['import_status'] = memcache.get('import_status')

        # Check for existing data.
        try:
            counter = StopMeta.get(Key.from_path('StopMeta', 1))
            template_values['production_num_stops'] = counter.counter_stop_no_confirm
            template_values['production_num_stations'] = counter.counter_station_no_confirm
            template_values['production_num_places'] = counter.counter_place_no_confirm
            # confirmation outstanding
            template_values['update_num_stops'] = counter.counter_stop_update_confirm
            template_values['update_num_stations'] = counter.counter_station_update_confirm
            template_values['update_num_places'] = counter.counter_place_update_confirm
            template_values['new_num_stops'] = counter.counter_stop_new_confirm
            template_values['new_num_stations'] = counter.counter_station_new_confirm
            template_values['new_num_places'] = counter.counter_place_new_confirm
            # Administrative hierarchy
            template_values['gov_num'] = Comuna.all().count()+Region.all().count()+Country.all().count()
        except AttributeError:
            # no data in database. Redirect to import page
            self.redirect('/import')

        template_values['upload_url'] = blobstore.create_upload_url('/update/upload')
        path = os.path.join(os.path.dirname(__file__), "pages/update.html")
        self.response.out.write(template.render(path, template_values))
        return
Exemple #2
0
 def fill_stop(self, stop, node, kind):
     """Returns stop in the correct entity group"""
     stop.stop_type = kind
     stop.location = db.GeoPt(lat=node.lat, lon=node.lon)
     stop.update_location()
     stop.names = [node.name]
     gov = []
     for k,v in node.attr.items():
         if k in ['alt_name', 'nat_name', 'old_name', 'reg_name', 'loc_name', 'official_name']:
             stop.names.append(v)
         if k.startswith('name:'):
             # language specific
             stop.names.append(v)
         # adminstrative regions
         if k.startswith('is_in:country'):
             country = Country.get_or_insert(v, name=v, ascii_names=Normalize.normalize(v))
             stop.country = country
         if k.startswith('is_in:region') or k.startswith('is_in:state'):
             # find the region with the best match (but must have some similarity to tag)
             region_match = (0.6, "<no match>", "-")
             for short_name,long_name in settings.REGIONS:
                 ndiff = difflib.SequenceMatcher(None,long_name,v)
                 if ndiff.ratio() > region_match[0]:
                     region_match = (ndiff.ratio(), unicode(long_name), unicode(short_name))
             if region_match[1] != "<no match>":
                 logging.debug("Match %f for %s and %s" % region_match)
                 region = Region.get_or_insert(region_match[2],
                                               name=region_match[1],
                                               short_name=region_match[2],
                                               ascii_names = Normalize.normalize("%s %s" % (long_name, short_name)))
                 region.put()
                 stop.region = region
             else:
                 logging.warning("Unknown region, state or Bundesland: %s" % v)
         if k.startswith('is_in:city') or k.startswith('is_in:municipality'):
             comuna = Comuna.get_or_insert(v, name=v, ascii_names=Normalize.normalize(v))
             stop.comuna = comuna
     stop.ascii_names = []
     for name in stop.names:
         if name != "<no name>":
             stop.ascii_names.extend(Normalize.normalize(name))
     return stop