def blacklistuser(): try: user_key = request.headers.get("X-SecondLife-Owner-Key") user = get_user(user_key) toggle_user_name = request.args.get("username") query = User.all() query.filter("name =", toggle_user_name) toggle_user = query.get() if toggle_user is None: return Response("\nThere is no user `%s` in the navigator." % toggle_user_name, status=404) query = BlacklistUser.all() query.ancestor(user) query.filter("user ="******"\nUser `%s` was added to your blacklist." % toggle_user_name) else: wl_user.delete() return Response("\nUser `%s` was removed from your blacklist." % toggle_user_name) except db.Timeout: msg = "\nUser was not blacklisted. The database timed out." logging.error(msg) return Response(msg, status=500) except CapabilityDisabledError: msg = "\nUser was not blacklisted. Database could not be written to." logging.error(msg) return Response(msg, status=500) except TransactionFailedError: msg = "\nUser was not blacklisted. Transaction failed." logging.error(msg) return Response(msg, status=500) except Exception, e: if DEBUG: print_exc() logging.error(str(e)) return Response("\nUser was not blacklisted. %s." % e, status=500)
def getblacklistedusers(): user_key = request.headers.get("X-SecondLife-Owner-Key") user = get_user(user_key) query = BlacklistUser.all() query.ancestor(user) result = sorted([User.get(n.user.key()).name for n in query]) if result: return Response("\nBlacklisted users:\n" + "\n".join(result)) else: return Response("\nYour user blacklist is empty.")
def regioncourses(): region_name, _, _ = get_region(request.headers.get("X-SecondLife-Region")) user_key = request.headers.get("X-SecondLife-Owner-Key") user = get_user(user_key) region = Region.get_by_key_name(region_name) if not region is None: query = BlacklistUser.all(keys_only=True) query.ancestor(user) bl_users = [n for n in query] query = BlacklistCourse.all(keys_only=True) query.ancestor(user) bl_courses = [n for n in query] all_courses = [] query = Course.all() query.ancestor(region.key()) query.filter("saved =", True) query.filter("deactivated =", False) query.filter("public =", False) query.filter("user ="******"name") for course in query: all_courses.append( "%s (%s by %s, private);%s" % (course.name, course.type.lower(), course.user.name, str(course.key())) ) courses = deserialize_entities(memcache.get("regioncourses-%s" % region_name)) if courses is None: query = Course.all() query.ancestor(region.key()) query.filter("saved =", True) query.filter("deactivated =", False) query.filter("public =", True) query.order("name") courses = [course for course in query] memcache.set(key="regioncourses-%s" % region_name, value=serialize_entities(courses), time=CACHE_TIME * 6) for course in courses: if course.user.key() not in bl_users and course.key() not in bl_courses: all_courses.append( "%s (%s by %s);%s" % (course.name, course.type.lower(), course.user.name, str(course.key())) ) if all_courses: return Response(";".join(all_courses)) msg = "\nThere are no courses for region %s." % region_name regions = Region.all().filter("course_count >", 0).order("-course_count").fetch(10) msg += "\nTry one of these regions instead:\n" + "\n".join(["http://" + quote(sl_url % r.name) for r in regions]) return Response(msg, status=406)