def delete(handler, obj_id): obj_key = models.get_key(obj_id) if obj_key.kind() == "Topic": topic = models.db.get(obj_key) topics = models._get_topics(topic) for t in topics: t.delete() memecache.set("data", None) return {"deleted":obj_id} elif obj_key.kind() == "Resource": resource = models.Resource.get(obj_key) resource.delete() return {"deleted":obj_id} else: return {"deleted":""}
def get_topic_tree(handler, topic_id=None): data = memcache.get("data2") if data: output = data["root"] location = data["location"] if not topic_id: return output elif location: locs = location[models.get_key(topic_id).name()] return _topic_lookup(output, locs) location = {} output = { "name" : "ROOT", "description" : "", "subtopics" : [] } topics = models._get_topics() for topic in topics: topic_dict = topic.to_dict() locstr = topic.key().name() if (locstr == "Bookmark"): continue loc_nodes = locstr.split(".") parent_locstr = ".".join(loc_nodes[0:len(loc_nodes)-1]) if parent_locstr: parent = _topic_lookup(output, location[parent_locstr]) location[locstr] = location[parent_locstr] + [len(parent["subtopics"])] parent["subtopics"].append(topic_dict) else: location[locstr] = [ len(output["subtopics"]) ] output["subtopics"].append(topic_dict) if not topic_id: data = {"root" : output, "location" : location } memcache.set("data", data) return output else: locs = location[models.get_key(topic_id).name()] return _topic_lookup(output, locs)