def contents(self, with_content=False, authenticated=False): from sefaria.sheets import sheet_topics_counts contents = super(Collection, self).contents() if with_content: contents["sheets"] = self.sheet_contents(authenticated=authenticated) contents["topics"] = sheet_topics_counts({"id": {"$in": self.sheets}}) contents["admins"] = [public_user_data(uid) for uid in contents["admins"]] contents["members"] = [public_user_data(uid) for uid in contents["members"]] contents["lastModified"] = str(self.lastModified) contents["invitations"] = getattr(self, "invitations", []) if authenticated else [] contents["pinnedSheets"] = getattr(self, "pinned_sheets", []) contents["pinnedTags"] = getattr(self, "pinnedTags", []) return contents
def contents(self, with_content=False, authenticated=False): from sefaria.sheets import group_sheets, sheet_topics_counts contents = super(Group, self).contents() if with_content: contents["sheets"] = group_sheets(self, authenticated)["sheets"] contents["topics"] = sheet_topics_counts({"group": self.name}) contents["admins"] = [ public_user_data(uid) for uid in contents["admins"] ] contents["publishers"] = [ public_user_data(uid) for uid in contents["publishers"] ] contents["members"] = [ public_user_data(uid) for uid in contents["members"] ] contents["invitations"] = getattr(self, "invitations", []) if authenticated else [] contents["pinnedSheets"] = getattr(self, "pinned_sheets", []) contents["pinnedTags"] = getattr(self, "pinnedTags", []) return contents
def run(self, query=None, test=0): """ Builds and sorts counts across all sheets. If `test` is not 0, only sample 1 in every `test` sheets to count. """ print("Loading sheets...") proj = { "sources.ref": 1, "tags": 1, "options": 1, "status": 1, "id": 1 } if query: sheets = db.sheets.find(query, proj) self.total = sheets.count() print("%d matching query" % sheets.count()) else: sheets = db.sheets.find() self.total = sheets.count() print("%d Total" % self.total) self.public_total = db.sheets.find({ "status": "public" }, proj).count() print("%d Public" % self.public_total) print("Processing tags...") self.top_tags = sheet_topics_counts({}) print("Processing sheets...") for sheet in sheets: if test == 0 or randrange(test) == 1: self.count_sheet(sheet) print("Sorting...") self.sort() print("Done.")