Beispiel #1
0
 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
Beispiel #2
0
    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
Beispiel #3
0
 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
Beispiel #4
0
 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)
Beispiel #5
0
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
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
0
    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
Beispiel #9
0
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
Beispiel #10
0
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
Beispiel #11
0
 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
Beispiel #12
0
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
Beispiel #13
0
 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