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
def post(self): num = 0 for stop in settings.STOP_TYPES: counter = StopMeta.get(Key.from_path('StopMeta', 1)) q = db.Query(Stop, keys_only=True).filter("stop_type =", stop).fetch(100) logging.debug(q) counter.counter_delta(-len(q), stop, "NO") num += len(q) db.delete(q) q = db.Query(StopUpdate, keys_only=True).filter("stop_type =", stop).fetch(100) logging.debug(q) counter.counter_delta(-len(q), stop, "UPDATE") num += len(q) db.delete(q) q = db.Query(StopNew, keys_only=True).filter("stop_type =", stop).fetch(100) logging.debug(q) counter.counter_delta(-len(q), stop, "NEW") num += len(q) db.delete(q) counter.put() if num: taskqueue.add(url='/purge/delete', queue_name='import') memcache.set('import_status', "Deletion finished.", time=30)
def update_counter(cls): """Update meta counter fields in transaction""" counter = StopMeta.get(Key.from_path('StopMeta', 1)) for stop in cls._stop_data: if isinstance(stop, Stop): counter.counter_delta(1, stop.stop_type, "NO") elif isinstance(stop, StopUpdate): counter.counter_delta(1, stop.stop_type, "UPDATE") elif isinstance(stop, StopNew): counter.counter_delta(1, stop.stop_type, "NEW") else: assert False, "Unknown stop instance: %s" % (stop) if cls._timestamp > counter.last_update: counter.last_update = cls._timestamp counter.put()
def get(self, login_user=None, template_values={}): # Check for existing data. Import is only done with an empty database # Note: If an area is imported which has no intersection with the existing # data it is a differrent matter. This will be handled in proper # time. For the moment we concentrate on Chile. if StopMeta.get(Key.from_path('StopMeta', 1)): self.redirect('/update') # set counter fields to zero # counter_fields = StopMeta(Key.from_path('StopMeta', 1)) def store(): counter_fields = StopMeta(key=Key.from_path('StopMeta', 1)) counter_fields.zero_all() counter_fields.last_update = datetime.datetime(2011,1,1) counter_fields.put() db.run_in_transaction(store) template_values['upload_url'] = blobstore.create_upload_url('/import/upload') path = os.path.join(os.path.dirname(__file__), "pages/import_select.html") self.response.out.write(template.render(path, template_values)) return