def set_other_perms(self, perms): perms = coerce_to_list(perms) perms = unique_items(perms) self.check_perm(perms) self.__other_perms = [] self.__other_perms.extend(perms) self._p_changed = 1
def check_perm(self, perm): """Raise KeyError if perm is not a valid perm""" perm = coerce_to_list(perm) for p in perm: if p not in HasOwnership._valid_perms: raise KeyError, "%s is not a valid permission" % p
def add_owning_group(self, group): """Add group as an group owner of this resource""" group = coerce_to_list(group) typecheck_seq(group, HasUserID) self.groups.extend(group) self._p_changed = 1
def set_owner(self, owner): """Set owner as sole owner of this resource. Can use add_owner to add additional owners. """ owner = coerce_to_list(owner) typecheck_seq(owner, HasUserID) self.owners = [] self.add_owner(owner)
def highest_score_items(wikis, count=10): """Return list of highest scoring items across multiple wikis. The order in which tied items are returned is not defined. """ wikis = coerce_to_list(wikis) items = [] for wiki in wikis: items.extend(wiki.highest_score_items(count)) bykarma = sort_list(items, lambda x: x.get_karma_score(), count=count) return bykarma
def highest_score_items(blogs, count=10): """Return list of highest scoring items across multiple blogs. The order in which tied items are returned is not defined. """ blogs = coerce_to_list(blogs) items = [] for blog in blogs: items.extend(blog.highest_score_items(count)) items = sort_list(items, lambda x: x.get_karma_score()) return items
def recent_items(wikis, count=10): """Return list of recent items across multiple wikis, most recent first, with wikis intermingled. """ wikis = coerce_to_list(wikis) items = [] for wiki in wikis: items.extend(wiki.recent_changes_with_date()) items.sort() items = [i for date, i in items[-count:]] items.reverse() return items
def add_owner(self, owner): """Add owner as an owner of this resource""" owner = coerce_to_list(owner)[:] typecheck_seq(owner, HasUserID) to_remove = [] for user in owner: if user in self.owners: to_remove.append(user) for user in to_remove: owner.remove(user) self.owners.extend(owner) self._p_changed = 1
def recent_items_by_author(blogs, author, count=10, not_by=0): """Return list of recent items by author(s) across multiple blogs. If not_by is not zero, returns the complement (i.e., items not by the given author(s). author may be given as a single User instance or a list of Users. """ blogs = coerce_to_list(blogs) items = [] for blog in blogs: items.extend(blog.recent_items_by_author(author, count, not_by)) items = sort_list(items, lambda x: x.last_modified(), count=count) return items
def recent_comments_by_author(blogs, author, count=10): """Return most recent comments in blogs by author. Returns list of tuples: (comment, parent item) """ blogs = coerce_to_list(blogs) items = [] for blog in blogs: items.extend(blog.recent_comments_by_author(author, count)) bydate = [(i.last_modified(consider_comments=False), i, parent) for i, parent in items] bydate.sort() items = [(i, parent) for date, i, parent in bydate[-count:]] items.reverse() return items
def recent_items_by_author(self, author, count=10, not_by=0): """Return most recent items by author from newest to oldest.""" author = coerce_to_list(author) items = [] recent_items = self.get_items() recent_items.reverse() bydate = [(i.last_modified(), i) for i in self.get_items() \ if (not not_by and (i.author in author)) or \ (not_by and (i.author not in author))] bydate.sort() items = [i for date, i in bydate[-count:]] items.reverse() return items
def recent_items(blogs, count=10, consider_comments=True): """Return list of recent items across multiple blogs, most recent first, with blogs intermingled. If consider_comments is True, item's last-modified date takes comment postings into account. """ blogs = coerce_to_list(blogs) items = [] for blog in blogs: items.extend(blog.recent_items_with_date(count, consider_comments=consider_comments)) items.sort() items = [i for date, i in items[-count:]] items.reverse() return items
def add_to_group(self, item): item = coerce_to_list(item) typecheck_seq(item, HasUserID) self.__items.extend(item) self.__items = unique_items(self.__items) self._p_changed = 1