def tag(self, request, tag_id, *args, **kwargs): user = request.user context = getContext(request=request) tag = TagRepo(user=user).get(tag_id=tag_id) context['search_for'] = tag.title context['pages'] = ManagerPageRepo(user=request.user).list_by_tag( tag_id=tag_id) return render(request, TEMPLATE_ROOT + 'search.html', context)
def add_tag(self, request, *args, **kwargs): if request.method == 'POST': add_tag_form = AddTagForm(request.POST, request.FILES) if add_tag_form.is_valid(): tag_title = add_tag_form.cleaned_data['tag_title'] page_id = add_tag_form.cleaned_data['page_id'] tag = TagRepo(user=request.user).add(tag_title=tag_title, page_id=page_id) if tag is not None: return JsonResponse({ 'result': SUCCEED, 'tag': TagSerializer(tag).data }) return JsonResponse({'result': FAILED})
def blog(self, request, blog_id, *args, **kwargs): context = getContext(request=request) page = BlogRepo(user=request.user).blog(blog_id=blog_id) context['page'] = page page_id = blog_id if page is None: raise Http404 tags = TagRepo(user=request.user).list_top() context['tags'] = tags context['add_like_form'] = AddLikeForm() context['get_edit_url'] = page.get_edit_url() context['add_comment_form'] = AddCommentForm() context['delete_comment_form'] = DeleteCommentForm() comments_s = json.dumps( CommentSerializer(page.comments, many=True).data) context['comments_s'] = comments_s context['my_like'] = LikeRepo( user=request.user, object_type='Page').my_like(object_id=page_id) return render(request, TEMPLATE_ROOT + 'page.html', context)
def tag(self, request, tag_id, *args, **kwargs): user = request.user main_pic_repo = MainPicRepo(user=user) context = getContext(request=request) context['blog_header_image'] = main_pic_repo.get( name=MainPicEnum.BLOG_HEADER) context['pages_pre_title'] = f'برچسب ' tag = TagRepo(user=user).get(tag_id=tag_id) context['pages_title'] = tag.title if tag.image_header: context['pages_header_image'] = tag else: context['pages_header_image'] = main_pic_repo.get( name=MainPicEnum.TAG_HEADER) context['pages'] = PageRepo(user=request.user).list_by_tag( tag_id=tag_id) return render(request, TEMPLATE_ROOT + 'pages.html', context)
def list_by_tag(self, tag_id): tag = TagRepo(user=self.user).tag(tag_id=tag_id) if tag is not None: return tag.managerpage_set.all()