def notify_friends_async(self, choosie_post_key):
    try:
      choosie_post = CacheController.get_model(str(choosie_post_key))

      logging.info("choosie post key = %s", str(choosie_post.key()))
      for user in User.all():
        logging.info("%s: device %s, uid: %s", user.name(), user.device_id, user.fb_uid)

      users = User.all()
      top_list = self.top_users()
      recipients = [u for u in User.all()
                   if ((ChoosieConfiguration.get_send_to_rest_setting() == False) and (u.fb_uid in top_list) or (ChoosieConfiguration.get_send_to_rest_setting() == True))]

      logging.info("First selection: %s", ", ".join([user.name() for user in recipients]))

      recipients = [u for u in recipients
                    if u.device_id is not None and user.fb_uid != choosie_post.user_fb_id]

      result = NotifyHandler.send_notifiction(NotifyHandler.notify_type["new_post"],
                                              self.get_user().display_name(), 
                                              str(choosie_post_key),
                                              recipients)

      ChoosieConfiguration.set_sent_to_rest_setting(not ChoosieConfiguration.get_send_to_rest_setting())

      logging.info("result of notifying friends= " + result)
    except Exception, e:
      logging.error("Faled to notify friends on new post: %s" % e)
    def notify_friends_async(self, choosie_post_key):
        try:
            choosie_post = CacheController.get_model(str(choosie_post_key))

            logging.info("choosie post key = %s", str(choosie_post.key()))
            for user in User.all():
                logging.info("%s: device %s, uid: %s", user.name(),
                             user.device_id, user.fb_uid)

            users = User.all()
            top_list = self.top_users()
            recipients = [
                u for u in User.all()
                if ((ChoosieConfiguration.get_send_to_rest_setting() == False)
                    and (u.fb_uid in top_list) or
                    (ChoosieConfiguration.get_send_to_rest_setting() == True))
            ]

            logging.info("First selection: %s",
                         ", ".join([user.name() for user in recipients]))

            recipients = [
                u for u in recipients if u.device_id is not None
                and user.fb_uid != choosie_post.user_fb_id
            ]

            result = NotifyHandler.send_notifiction(
                NotifyHandler.notify_type["new_post"],
                self.get_user().display_name(), str(choosie_post_key),
                recipients)

            ChoosieConfiguration.set_sent_to_rest_setting(
                not ChoosieConfiguration.get_send_to_rest_setting())

            logging.info("result of notifying friends= " + result)
        except Exception, e:
            logging.error("Faled to notify friends on new post: %s" % e)
    def get(self):
        message = "i love soja milk"
        # users = db.GqlQuery("SELECT * FROM User WHERE device_id > :1",None)
        users = User.all()
        user_array = []
        # devices = ["APA91bHlkage-d5iZhdRAZtKS1gUy8q1LcEyGXmmhBzaGXxMTp6S5QIxQGkp8HxiTExI6cim4KngJXzamvbjzOKLrRUPKQpQqKaevHAEertE_PKKT8UjkLabSDTw8ljXYVt59k_xqIWK"]
        for user in users.run():
            # devices.append(user.device_id)
            if user.device_id is not None:
                user_array.append(user)

        result = NotifyHandler.send_notifiction(
            NotifyHandler.notify_type["new_post"], "ron", "1", user_array)

        self.response.write("result is " + result)
  def get(self):
    message = "i love soja milk"
    # users = db.GqlQuery("SELECT * FROM User WHERE device_id > :1",None)
    users = User.all()
    user_array = []
    # devices = ["APA91bHlkage-d5iZhdRAZtKS1gUy8q1LcEyGXmmhBzaGXxMTp6S5QIxQGkp8HxiTExI6cim4KngJXzamvbjzOKLrRUPKQpQqKaevHAEertE_PKKT8UjkLabSDTw8ljXYVt59k_xqIWK"]
    for user in users.run():
      # devices.append(user.device_id)
      if user.device_id is not None:
        user_array.append(user)


    result = NotifyHandler.send_notifiction(NotifyHandler.notify_type["new_post"],
                                            "ron",
                                            "1",
                                            user_array)


    self.response.write("result is " + result)