def refill_redis(profile_id): support_key = get_support_key(profile_id) promise_key = get_promise_key(profile_id) promise_ids = list(Promise.objects.filter(creator=profile_id).active().values_list('id', flat=True)) connection.delete(promise_key) for prom_id in promise_ids: connection.lpush(promise_key, prom_id) promises_supported_ids = list(Promise.objects.filter(supporter__id=profile_id).values_list('id', flat=True)) connection.delete(support_key) for prom_id in promises_supported_ids: connection.lpush(support_key, prom_id)
def user_promise_state(user, promise): """Returns the status between the promise and the currently logged in (or anonymous) user. Just a helper to avoid ifs/elifs to proliferate in our codebase. """ # We got an anonymous user here, he obviously can't support # anything. Let's give him a chance to show the "support this" # button. if user.is_anonymous(): return PromiseUserState.NOTHING # For owners promise_key = get_promise_key(user.profile.id) if promise.id in get_ids_from_redis(promise_key): return PromiseUserState.OWNER # For supporters support_key = get_support_key(user.profile.id) if promise.id in get_ids_from_redis(support_key): return PromiseUserState.SUPPORTER return PromiseUserState.NOTHING
def update_redis(self, promise_id): """ In Redis, adds this promise to the list of promises that this user supports. """ key = get_support_key(self.request.user.profile.id) redis_connection.lpush(key, promise_id)