def set_dnd(self, state): from map import flask_redis uun = self.get_username() if state: flask_redis.sadd("dnd-users", uun) else: flask_redis.srem("dnd-users", uun)
def cascade(self, enabled, tagline): from map import flask_redis uun = self.get_username() if enabled: flask_redis.sadd("cascaders.users", uun) else: flask_redis.srem("cascaders.users", uun) if not tagline: flask_redis.hdel("cascaders.taglines", uun) else: flask_redis.hset("cascaders.taglines", uun, tagline)
def friends(): if request.method == "POST": formtype = request.form.get('type') if formtype == "del": remove_friends = request.form.getlist('delfriends') flask_redis.srem(current_user.get_id() + "-friends", *remove_friends) elif formtype == "add": add_friend = request.form.get('newfriend') if(re.match("^[A-Za-z]+\ [A-Za-z]+$", add_friend) == None): raise APIError("Friend name expected in [A-z]+\ [A-z]+ form.", status_code=400) flask_redis.sadd(current_user.get_id() + "-friends", add_friend) friends = flask_redis.smembers(current_user.get_id() + "-friends") friends = list(friends) friends = sorted(friends, key=lambda s: s.lower()) return jsonify(friendList=friends) #Set up for ajax responses
def friends(): if request.method == "POST": formtype = request.form.get('type') if formtype == "del": remove_friends = request.form.getlist('delfriends[]') flask_redis.srem(current_user.get_username() + "-friends", *remove_friends) elif formtype == "add": add_friend = request.form.get('uun') #if(re.match("^[A-Za-z]+\ [A-Za-z]+$", add_friend) == None): # raise APIError("Friend name expected in [A-z]+\ [A-z]+ form.", status_code=400) flask_redis.sadd(current_user.get_username() + "-friends", add_friend) friends = get_friends() friends = map(lambda p: ("%s (%s)" % (p[0], p[1]), p[1]), friends) friends = sorted(friends, key=lambda s: s[0].lower()) return jsonify(friendList=friends) #Set up for ajax responses