def updatePercorsiInRideOffers(test=False): import route more, cursor = True, None while more: # for all ride offers, including expired ones records, cursor, more = RideOffer.query().fetch_page( 100, start_cursor=cursor) updating_records = [] for r in records: old_percorso = convertToUtfIfNeeded(r.percorso) new_percorso = getNewPercorso(old_percorso) if new_percorso is None: # triggering a warning in getNewPercorso print 'aborting' return if old_percorso != new_percorso: print 'updating percorso from {} to {}'.format( old_percorso, new_percorso) r.percorso = new_percorso updating_records.append(r) if Route.get_by_id(new_percorso) is None: rt = route.addRoute(new_percorso) rt.populateWithDetails(put=not test) print 'populating new route: {}'.format(new_percorso) if not test: create_futures = ndb.put_multi_async(updating_records) ndb.Future.wait_all(create_futures)
def getPropertyUtfMarkdown(self, property, escapeMarkdown=True): if property == None: return None result = convertToUtfIfNeeded(property) if escapeMarkdown: result = utility.escapeMarkdown(result) return result
def updatePercorsiPreferiti(test=False): more, cursor = True, None while more: records, cursor, more = Person.query( Person.percorsi_size > 0).fetch_page(100, start_cursor=cursor) updating_records = [] for r in records: new_percorsi = [] updated = False for old_percorso in r.percorsi: old_percorso = convertToUtfIfNeeded(old_percorso) new_percorso = getNewPercorso(old_percorso) if new_percorso is None: # triggering a warning in getNewPercorso print 'aborting' return if old_percorso != new_percorso: updated = True print 'updating percorso from {} to {}'.format( old_percorso, new_percorso) new_percorsi.append(new_percorso) else: new_percorsi.append(old_percorso) if updated: r.percorsi = new_percorsi updating_records.append(r) if not test: create_futures = ndb.put_multi_async(updating_records) ndb.Future.wait_all(create_futures)
def getTimeMode(self): return convertToUtfIfNeeded(self.time_mode)
def getPercorso(self): return convertToUtfIfNeeded(self.percorso)
def getDriverName(self): return convertToUtfIfNeeded(self.driver_name_lastname)
def removePercorsi(self, index): removed_percorso_key = convertToUtfIfNeeded(self.percorsi.pop(index)) return removed_percorso_key
def getPercorsi(self): return tuple([convertToUtfIfNeeded(prc) for prc in self.percorsi])
def getFermateIntermedie(self): return [convertToUtfIfNeeded(x) for x in self.fermate_intermedie]
def getPercorsiPasseggeriCompatibili(self): return [convertToUtfIfNeeded(x) for x in self.percorsi_passeggeri_compatibili]