def draft_list(request): try: content = dict() page = request.GET.get("page", None) # 页码 num = request.GET.get("num", None) # 每页数量 user = request.user bloger = User.objects.filter(id=user.id, deleted=0).first() drafts = ArticleDraft.objects.filter(author_id=user.id, deleted=0).order_by("-created") paginations, current_page = pagination(drafts, page, num) content['user'] = user content['bloger'] = bloger content['drafts'] = paginations content['page'] = current_page git = UserInfo.objects.values("github").filter(user_id=bloger.id, deleted=0).first() content['git'] = git return render(request, "draft/draft_list.html", content) except Exception as e: print(e)
def article_list(request): try: page = request.GET.get("page", None) # 页码 num = request.GET.get("num", None) # 每页数量 user = request.user bloger = User.objects.filter(id=user.id, deleted=0).first() articles = Article.objects.filter(author_id=user.id, deleted=0).order_by("-created") # 分页 paginations, current_page = pagination(articles, page, num) content = dict() content['user'] = user content['bloger'] = bloger content['articles'] = paginations content['page'] = current_page # 提取当前页的每篇文章的标签 if articles: article_and_tag = [] for article in paginations: tag = article.articletag_set.filter(deleted=0) article_and_tag.append({ 'article': article, 'article_tags': tag }) content['articles'] = article_and_tag else: content['articles'] = '' git = UserInfo.objects.values("github").filter(user_id=bloger.id, deleted=0).first() content['git'] = git return render(request, "article/article_list.html", content) except Exception as e: print(e)
def get_context_data(self, *args, **kwargs): # songs = Song.objects.filter(name=kwargs['q']) # for song in songs: # print(song.name) mySearchView = super(MySearchView, self) form_data = mySearchView.get_form_kwargs()['data'] # search_method = form_data['search-method'] self.ordering = '-updated' context = dict() page = form_data.get('page', None) articles = Article.objects.filter(Q(title__icontains=form_data['q']) | Q(body__icontains=form_data['q']), is_secret=0, deleted=0).order_by("-updated") # 分页 paginations, current_page = pagination(articles, page=page, num=None) # context['articles'] = paginations context['page'] = current_page context['articles'] = paginations context['search'] = form_data['q'] cache.set('host:' + self.request.get_host() + 'url', self.request.get_host() + self.request.get_full_path(), 60 * 10) context['query'] = True if context['articles'] else False return context
def get_tag_article(request, tag_id): if request.user.is_authenticated: user = request.user else: user = '' try: page = request.GET.get("page", None) num = request.GET.get("num", None) tag = Tags.objects.filter(id=tag_id, deleted=0).first() # article = Article.objects.filter(articletag__tag_id=tag_id, deleted=0, articletag__deleted=0) bloger = User.objects.filter(id=tag.user.id, deleted=0).first() if bloger == user: articles = Article.objects.filter(articletag__tag_id=tag_id, articletag__deleted=0, deleted=0).order_by("-created") else: articles = Article.objects.filter(articletag__tag_id=tag_id, articletag__deleted=0, is_secret=0, deleted=0).order_by("-created") # 分页 paginations, current_page = pagination(articles, page, num) content = dict() content['user'] = user content['bloger'] = bloger content['articles'] = paginations content['page'] = current_page if articles: article_and_tag = [] for article in paginations: tag = article.articletag_set.filter(deleted=0) article_and_tag.append({ 'article': article, 'article_tags': tag }) content['articles'] = article_and_tag else: content['articles'] = '' git = UserInfo.objects.values("github").filter(user_id=bloger.id, deleted=0).first() content['git'] = git return render(request, "article/article_list.html", content) except Exception as e: print(e)
def photo(request): user = request.user bloger = User.objects.filter(id=user.id, deleted=0).first() try: page = request.GET.get("page", None) # 页码 num = request.GET.get("num", None) # 每页数量 content = dict() photos = Photo.objects.filter(user_id=user.id, deleted=0).order_by("-created") paginations, current_page = pagination(photos, page, num) content['user'] = user content['bloger'] = bloger content['photos'] = paginations content['page'] = current_page return render(request, "photo/photo_list.html", content) except Exception as e: print(e)
def msg_list(request): try: page = request.GET.get("page", None) num = request.GET.get("num", None) user = request.user bloger = User.objects.filter(id=user.id, deleted=0).first() content = dict() content['user'] = user content['bloger'] = bloger messages = Message.objects.filter(user_id=user.id, deleted=0).order_by("-created") # 分页 paginations, current_page = pagination(messages, page, num) content['messages'] = paginations content['page'] = current_page return render(request, "user/message_list.html", content) except Exception as e: print(e)
def get_tags(request): try: page = request.GET.get("page", None) # 页码 num = request.GET.get("num", None) # 每页数量 user = request.user bloger = User.objects.filter(id=user.id, deleted=0).first() tags = Tags.objects.filter(user_id=user.id, deleted=0).order_by("-created") # 分页 paginations, current_page = pagination(tags, page, num) content = dict() content['user'] = user content['bloger'] = bloger content['tags'] = paginations content['page'] = current_page git = UserInfo.objects.values("github").filter(user_id=bloger.id, deleted=0).first() content['git'] = git return render(request, "article/tag_list.html", content) except Exception as e: print(e)
def get_photo_img(req, photo_id, category): user = req.user bloger = User.objects.filter(id=user.id, deleted=0).first() content = dict() if category == 'list': try: page = req.GET.get("page", None) # 页码 num = req.GET.get("num", None) # 每页数量 photo_imgs = PhotoImg.objects.filter( photo_id=photo_id, deleted=0).order_by("-created") paginations, current_page = pagination(photo_imgs, page, num) content['user'] = user content['bloger'] = bloger content['photo_imgs'] = paginations content['page'] = current_page content['photo_id'] = photo_id return content except Exception as e: print(e) if category == 'fall': try: nid = req.GET['nid'] # 每次加载15张图片 dif = int(nid) + 15 photo_imgs = PhotoImg.objects.values('id', 'title', 'img_url', 'description').filter( photo_id=photo_id, id__gt=nid, id__lt=dif, deleted=0) content['data'] = list(photo_imgs) content['code'] = True return content except Exception as e: print(e) if category == 'tile': try: checked_date = req.GET.get('checked_date', None) nid = req.GET['nid'] # 每次加载20张图片 dif = int(nid) + 20 if checked_date == None or checked_date == '': photo_imgs = PhotoImg.objects.values( 'id', 'title', 'img_url', 'description').filter(photo_id=photo_id, id__gt=nid, id__lt=dif, deleted=0).order_by("created") else: photo_imgs = PhotoImg.objects.values( 'id', 'title', 'img_url', 'description').filter(photo_id=photo_id, created__icontains=checked_date, deleted=0).order_by("created") content['data'] = list(photo_imgs) if photo_imgs: content['code'] = True else: content['code'] = False return content except Exception as e: print(e)