def get(self, request, book_id): book = get_object_or_404(Book, pk=book_id) user_booklog = None if request.user.is_authenticated: user_booklog = BookLog.objects.filter(booklog_owner=request.user, booklog_book=book).first() # the booklog_comment is the related_query_name of BookLog and used as a reverse lookup from Comment book_comments = Comment.objects.filter( booklog_comment__booklog_book=book, parent_comment=None).order_by('-comment_date_time') page_book_comments = page_list(request, book_comments, 5, 'c-page') book_posts = Post.objects.filter( booklog_post__booklog_book=book).order_by('-create_date_time') page_book_posts = page_list(request, book_posts, 5, 'p-page') context = { 'booklog': user_booklog, 'book': book, 'book_comments': page_book_comments, 'book_posts': page_book_posts, 'comment_form': CommentForm(), } return render(request, 'book/book_page/detail.html', context)
def index_own(request, user_id): user = get_object_or_404(get_user_model(), pk=user_id) post_list = Post.objects.filter(blog_author=user).order_by('-update_date_time') # use '-' to order items in reversed order qs = request.GET.get('qs') if qs: post_list = post_list.filter( Q(blog_title__icontains=qs) | Q(blog_content__icontains=qs) | Q(blog_author__username__icontains=qs) | Q(blog_author__email__icontains=qs) | Q(blog_tag__name__icontains=qs) ).distinct() page_post_list = page_list(request, post_list, 5) tag_list = PostTag.objects.all() title = format_html("""<i>{0}</i>'s Post""".format(user.username)) if request.user == user: title = 'My Posts' context = { 'title': title, 'post_list': page_post_list, #post_list 'tag_list': tag_list, } return render(request, 'blog/index.html', context)
def index(request): post_list = Post.objects.order_by('-update_date_time') # use '-' to order items in reversed order owner_id = request.GET.get('owner_id') if owner_id: user = get_object_or_404(get_user_model(), pk=owner_id) post_list = post_list.filter(blog_author=user) qs = request.GET.get('qs') if qs: post_list = post_list.filter( Q(blog_title__icontains=qs) | Q(blog_content__icontains=qs) | Q(blog_author__username__icontains=qs) | Q(blog_author__email__icontains=qs) | Q(blog_tag__name__icontains=qs) ).distinct() page_post_list = page_list(request, post_list, 5) tag_list = PostTag.objects.all() context = { 'title': 'Posts', 'post_list': page_post_list, #post_list 'tag_list': tag_list, } return render(request, 'blog/index.html', context)
def detail(request, blog_id): post = get_object_or_404(Post, pk=blog_id) if request.method == 'POST' and request.user.is_authenticated: comment_form = CommentForm(request.POST, request.FILES) if comment_form.is_valid(): comment_instance = comment_form.save(commit=False) comment_instance.comment_user = request.user comment_instance.content_type = ContentType.objects.get_for_model(Post) comment_instance.content_object = post comment_instance.object_id = post.id parent_id = request.POST.get('parent_id') if parent_id is not None: comment_instance.parent_comment = Comment.objects.get(pk=int(parent_id)) comment_form.save() comment_form.save_m2m() return HttpResponseRedirect(post.get_absolute_url()) post_comments = post.blog_comment.filter(parent_comment=None).order_by('-comment_date_time') page_post_comments = page_list(request, post_comments, 10) context = { 'booklog': post.content_object, 'post': post, 'post_comments': page_post_comments, 'comment_form': CommentForm(), } return render(request, 'blog/detail.html', context)
def get(self, request): book_list = Book.objects.order_by('book_title') qs = request.GET.get('qs') if qs: book_list = book_list.filter( Q(book_title__icontains=qs) | Q(sub_title__icontains=qs) | Q(book_author__author_name__icontains=qs) | Q(book_press__press_name__icontains=qs) | Q(book_tag__name__icontains=qs)).distinct() user_book_list = None if request.user.is_authenticated: user_shelf = get_object_or_404(BookShelf, shelf_owner=request.user) user_book_list = [ booklog.booklog_book for booklog in user_shelf.shelf_books.select_related('booklog_book') ] tag_list = BookTag.objects.all() context = { 'book_list': page_list(request, book_list, 10), #book_list 'tag_list': tag_list, 'user_book_list': user_book_list, } return render(request, 'book/book_page/index.html', context)
def get(self, request, user_id): user = get_object_or_404(get_user_model(), pk=user_id) book_sharelist = BookShareList.objects.filter(share_user=user).order_by('-share_update_date_time') qs = request.GET.get('qs') if qs: book_sharelist = book_sharelist.filter( Q(share_title__icontains=qs) | Q(share_intro__icontains=qs) | Q(share_tag__name__icontains=qs) ).distinct() page_book_sharelist = page_list(request, book_sharelist, 20) tag_list = ShareTag.objects.all() title = format_html("""<i>{0}</i>'s Share Lists""".format(user.username)) if request.user == user: title = 'My Share Lists' context = { 'title': title, 'book_sharelist': page_book_sharelist, 'tag_list': tag_list, } return render(request, 'sharelist/index.html', context)
def get(self, request, user_id=None): if user_id: user = get_object_or_404(get_user_model(), pk=user_id) book_shelf = get_list_or_404(BookShelf, shelf_public=True, shelf_owner=user)[0] else: book_shelf = get_list_or_404(BookShelf, shelf_public=False)[0] booklogs_list = book_shelf.shelf_books.all() qs = request.GET.get('qs') if qs: booklogs_list = booklogs_list.filter( Q(booklog_book__book_title__icontains=qs) | Q(booklog_book__sub_title__icontains=qs) | Q(booklog_book__book_author__author_name__icontains=qs) | Q(booklog_book__book_press__press_name__icontains=qs) | Q(booklog_book__book_tag__name__icontains=qs) | Q(booklog_intro__icontains=qs) ).distinct() page_booklogs_list = page_list(request, booklogs_list, 20) context = { 'title': book_shelf.shelf_name, 'booklog_list': page_booklogs_list, } return render(request, 'shelf/shelf.html', context)
def get(self, request, share_id): bookshare = get_object_or_404(BookShareList, pk=share_id) bookshare_books = bookshare.share_books.all() page_bookshare_books = page_list(request, bookshare_books, 20) context = { 'bookshare': bookshare, 'bookshare_books': page_bookshare_books, 'bookshare_comments': bookshare.share_comment.filter(parent_comment=None).order_by('-comment_date_time'), 'comment_form': CommentForm(), } return render(request, 'sharelist/detail.html', context)
def get(self, request, booklog_id): booklog = get_object_or_404(BookLog, pk=booklog_id) booklog_posts = booklog.booklog_post.all().order_by('-update_date_time') page_booklog_posts_list = page_list(request, booklog_posts, 5) context = { 'booklog': booklog, 'booklog_comments': booklog.booklog_comment.filter(parent_comment=None).order_by('-comment_date_time'), 'booklog_posts': page_booklog_posts_list, 'comment_form': CommentForm(), } return render(request, 'shelf/detail.html', context)
def get(self, request): press_list = Press.objects.order_by('press_name') qs = request.GET.get('qs') if qs: press_list = press_list.filter( Q(press_name__icontains=qs) ).distinct() page_press_list = page_list(request, press_list, 5) context = { 'press_list': page_press_list, } return render(request, 'book/press_page/index.html', context)
def get(self, request): author_list = Author.objects.order_by('author_name') qs = request.GET.get('qs') if qs: author_list = author_list.filter( Q(author_name__icontains=qs) | Q(author_intro__icontains=qs) ).distinct() page_author_list = page_list(request, author_list, 5) context = { 'author_list': page_author_list, } return render(request, 'book/author_page/index.html', context)
def get(self, request): book_sharelist = BookShareList.objects.order_by('-share_update_date_time') qs = request.GET.get('qs') if qs: book_sharelist = book_sharelist.filter( Q(share_title__icontains=qs) | Q(share_intro__icontains=qs) | Q(share_tag__name__icontains=qs) ).distinct() page_book_sharelist = page_list(request, book_sharelist, 20) tag_list = ShareTag.objects.all() context = { 'title': 'Shares', 'book_sharelist': page_book_sharelist, 'tag_list': tag_list, } return render(request, 'sharelist/index.html', context)