Ejemplo n.º 1
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})