Пример #1
0
 def add_several(wineries,ip,update_votes=True):
   if not wineries:
     return
   for winery in wineries:
     # assuming winery is a tuple (name,city,state)
     hash_id = make_hash_id(winery)
     wr = WineryRequest(ip=ip,hash_id=hash_id)
     wr.put()
   if update_votes:
     # get latest timestamp
     timestamp = wr.timestamp.strftime(TIME_FORMAT)
     Votings.update_several(wineries,ip,timestamp)
Пример #2
0
 def init(self):
   if WineriesSearcher.db:
     pass 
     #return WineriesSearcher.__single 
   else:
     # first time init
     # test if there is db already stored in memcache
     self.db = memcache.get(self.mc_key)
     if not self.db:
       # reload from disk
       reader = csv.reader(open(DB_FILE_PATH, 'rb'), delimiter=';', quotechar='|')
       name_db = {}
       state_db = {}
       city_db = {}
       hash_db = {}
       # skipping first row
       reader.next()
       for row in reader:
         name, city, state = row
         if name:
           name_db[name] = city,state
           state_db.setdefault(state,[]).append((name,city))
           city_db.setdefault(city,[]).append((name,state))
           hash_db[make_hash_id(row)] = name
       
       log(hash_db)
       #log(state_db["CA"])
       #log(len(state_db["CA"]))
       #log(city_db)
       #log(sorted(state_db.keys()))
       
       # fill db
       self.db = {
         "city" : city_db,
         "state" : state_db,
         "name" : name_db,
         "hash" : hash_db,
                  }
       # store it in memcache
       memcache.set(self.mc_key,self.db)
     else:
       # got from memcache
       #log(self.db["state"].keys())
       #log(self.db["state"][""])
       pass
Пример #3
0
 def get(self):
   link = ""
   ids_param = self.getval("ids", False)
   prepared_bookmarks = []
   if ids_param:
     #log("HWA");
     # someone shared bookmarks with current user
     # we must extract them and save in cookie
     ids = ids_param.split("|")
     if ids:
       # that will be very long calculation
       # TODO: mb we should optimise it with memcache key 
       # for getting already prepared bookmarks by some key provided in url
       # and not to recalc (filter) them all again
       # for every user
       bookmarks = WS.get_by_ids(ids) # will be dict in fmt: dict[name]=(city,state)
       self.set_bookmarks(bookmarks)
       for name, citystate in bookmarks.items():
         prepared_bookmarks.append((name,)+citystate)
       link = "?ids="+ids_param        
   else:
     prepared_bookmarks =[]
     ids = []
     for name, citystate in self.get_bookmarks().items():
       obj = (name,)+citystate
       prepared_bookmarks.append(obj)
       ids.append(make_hash_id(obj))
     if ids:
       # making link-to-this-page
       # that allow user to quick-share their bookmarks
       link = "?ids=%s" % urllib.quote("|".join(ids))
     else:
       link = False
   
   self.render("bookmarks.html", {"bookmarks" : prepared_bookmarks,
                                  "link" : link})