-# TODO: marked for publishing
-
-
-def published_wall(user, max_len):
- qs = BookPublishRecord.objects.select_related('book__title')
- if user:
- # TODO: published my book
- qs = qs.filter(Q(user=user))
- qs = qs[:max_len]
- for item in qs:
- w = WallItem('publish')
- w.title = item.book.title
- #w.summary =
- w.url = chunk.book.get_absolute_url()
- yield w
-
-
-def comments_wall(user, max_len):
- qs = Comment.objects.filter(is_public=True).select_related().order_by('-submit_date')
- if user:
- # TODO: comments concerning my books
- qs = qs.filter(Q(user=user))
- qs = qs[:max_len]
- for item in qs:
- w = WallItem('comment')
- w.title = item.content_object
- w.summary = item.comment
- w.url = item.content_object.get_absolute_url()
- w.timestamp = item.submit_date
- w.user = item.user
- w.email = item.user_email
- yield w
-
-
-def big_wall(max_len, *args):
- """
- Takes some WallItem iterators and zips them into one big wall.
- Input iterators must already be sorted by timestamp.
- """
- subwalls = []
- for w in args:
- try:
- subwalls.append([next(w), w])
- except StopIteration:
- pass
-
- while max_len and subwalls:
- i, next_item = max(enumerate(subwalls), key=lambda x: x[1][0].timestamp)
- yield next_item[0]
- max_len -= 1
- try:
- next_item[0] = next(next_item[1])
- except StopIteration:
- del subwalls[i]