Ejemplo n.º 1
0
 def get(self):
   pub_id = int(self.request.get('pub'))
   pub = Pub.get_by_id(pub_id)
   visits = Visit.all().filter('pub =', pub).run()
   for v in visits:
     v.delete()
   pub.delete()
Ejemplo n.º 2
0
  def get(self):
    visits = Visit.all().run()
    for v in visits:
      try:
        p = v.pub
      except:
        v.delete()

    self.response.out.write('success')
Ejemplo n.º 3
0
def get_user_counts():
  users = memcache.get('user-counts')
  if users:
    return users
  users = User.all().run()
  user_counts = []
  for u in users:
    count = Visit.all().ancestor(u).filter('visited =', True).count()
    user_counts.append({'name':u.name,'id':u.key().id(),'count':count})
  user_counts = sorted(user_counts, key=lambda c: -c['count'])
  memcache.set('user-counts', user_counts)
  return user_counts
Ejemplo n.º 4
0
  def post(self):
    user = get_current_user()
    if not user and False:
      return self.redirect('/')
    pub_id = self.request.get('pub_id')
    pub = Pub.get_by_id(int(pub_id))

    visit = Visit.all().ancestor(user).filter('pub =', pub).get()

    visited = bool(self.request.get('visited'))
    visit.visited = visited
    visit.put()
    memcache.delete('visited-' + str(user.key().id()))
    memcache.delete('not-visited-' + str(user.key().id()))
    memcache.delete('user-counts')
Ejemplo n.º 5
0
  def get(self):
    user = get_current_user()
    lat=float(self.request.get('lat'))
    long=float(self.request.get('long'))
    if self.request.get('show-colleges'):
      if not user.show_colleges:
        memcache.delete('not-visited-' + str(user.key().id()))
        user.show_colleges = True
        user.put()
    elif user and user.show_colleges:
      memcache.delete('not-visited-' + str(user.key().id()))
      user.show_colleges = False
      user.put()
    if self.request.get('hide-visited'):
      if not user.hide_visited:
        user.hide_visited = True
        user.put()
    elif user and user.hide_visited:
      user.hide_visited = False
      user.put()

    if user and user.hide_visited:
      visits = memcache.get('not-visited-' + str(user.key().id()))
      if not visits:
        visits = Visit.all().ancestor(user).filter('visited =', False).fetch(500)
        visits = sorted(visits, key = lambda v: v.pub.name.lower())
        memcache.set('not-visited-' + str(user.key().id()), visits)
      if user.show_colleges:
        pubs = [v.pub for v in visits]
      else:
        pubs = [v.pub for v in visits if not v.pub.is_college]
      pubs = [p for p in pubs if not p.closed]
      pubs = sorted(pubs, key=lambda p: p.distance(lat, long))[0:20]
      pubs = [pub.toDictionary() for pub in pubs]
    else:
      pubs = memcache.get('all-pubs-list')
      if not pubs:
        pubs = Pub.all().filter('closed =', False).fetch(500)
        pubs = sorted(pubs, key = lambda p: p.name.lower())
        memcache.set('all-pubs-list', pubs)
      if user and not user.show_colleges:
        pubs = [p for p in pubs if not p.is_college]
      pubs = sorted(pubs, key=lambda p: p.distance(lat, long))[0:20]
      pubs = [p.toDictionary() for p in pubs]

    self.response.out.write(json.dumps(pubs))