Ejemplo n.º 1
0
def article(request, *args, **kwargs):
    """
    博主个人文章管理
    :param request:
    :return:
    """
    condition = {}  # 筛选条件
    for k, v in kwargs.items():
        kwargs[k] = int(v)  # 将字符串改为数字
        if v != "0":
            condition[k] = v
    username = request.session.get("username", None)  # 获取session中的用户名
    user_obj = models.UserInfo.objects.filter(
        username=username).select_related("blog").first()  # 获取用户对象
    category_list = models.Category.objects.filter(
        blog_id=user_obj.blog.nid).all()  # 获取用户博客的所有分类
    article_type_list = models.ArticleType.objects.all()  # 获取文章类型
    article_list = models.Article.objects.filter(
        blog_id=user_obj.blog.nid).filter(**condition).all()  # 获取用户的文章
    if request.method == "GET":
        current_page = int(request.GET.get("p", 1))  # 获取用户选择的页码,默认为第一页
        page_obj = Page(current_page, len(article_list))  # 获取分页对象
        page_str = page_obj.page_str("/backend/article.html")  # 获取分页HTML
        article_list = article_list[page_obj.start:page_obj.end]  # 获取当前页数据
        return render(
            request,
            'backend_article.html',
            {
                "user_obj": user_obj,  # 用户对象
                "category_list": category_list,  # 博客分类列表
                "article_type_list": article_type_list,  # 文章分类
                "article_list": article_list,  # 文章列表
                "page_str": page_str,  # 分页对象
                "kwargs": kwargs,  # 用户文章分类和博客分类
            })
Ejemplo n.º 2
0
def index(request, **kwargs):
    if request.method == 'GET':
        article_type_list = models.Article.type_choices

        c = {}
        for k, v in kwargs.items():
            kwargs[k] = int(v)
            if v != '0':
                c[k] = v
        all_articles = models.Article.objects.filter(
            **c).order_by('-create_time')
        hot_articles = models.Article.objects.filter().order_by(
            '-up_count')[:5]
        read_articles = models.Article.objects.filter().order_by(
            '-read_count')[:5]

        # 分页
        current_page = request.GET.get('p',
                                       1)  # 获取对应get数据p: href="/user_list/?p=%s
        current_page = int(current_page)
        page_num = 10
        page = Page(current_page, len(all_articles), page_num)
        data = all_articles[page.start:page.end]  # 列表切片
        page_str = page.page_str(request.path_info)
        return render(
            request, 'index.html', {
                'all_articles': data,
                'page_str': page_str,
                'hot': hot_articles,
                'read': read_articles,
                'article_type_list': article_type_list,
                'arg_dict': kwargs,
            })
Ejemplo n.º 3
0
def index(request):
    """
    博客首页,展示全部博文
    :param request:  请求信息
    :param article_type: 文章类型
    :return:
    """
    if request.method == "GET":
        username = request.session.get("username", None)  # 获取session中的用户名
        user_obj = models.UserInfo.objects.filter(
            username=username).select_related("blog").first()  # 获取用户对象
        article_type_list = models.ArticleType.objects.all()  # 获取所有的文章类型
        current_page = int(request.GET.get("p", "1"))  # 当前页码,默认是第一页
        article_type = request.GET.get(
            "at",
            request.session.get("article_type"))  # 获取用户类型,获取不到则从session中获取
        request.session["article_type"] = article_type  # 将本次查询的文章类型存入session
        if article_type and article_type != "0":  # 有类型查询条件
            article_type = int(article_type)  # 先变成整数
            article_list = models.Article.objects.filter(
                article_type=article_type).all().select_related(
                    "blog", "blog__user")  # 依据类型获取所有的文章
        else:
            article_list = models.Article.objects.all().select_related(
                "blog", "blog__user")  # 没有类型查询条件则获取所有文章
        data_count = len(article_list)  # 文章总个数
        page_obj = Page(current_page, data_count)  # 生成分页对象
        article_list = article_list[page_obj.start:page_obj.end]  # 获取当前页的所有文章
        page_str = page_obj.page_str("/")  # 获取分页html

        # 回复最多的文章
        hot_recommend = models.Comment.objects.exclude(
            reply_id__isnull=True).values('article_id').annotate(
                c=Count('reply_id'))
        hot_recommend = sorted(list(hot_recommend),
                               key=lambda i: i['c'],
                               reverse=True)[:8]
        hot_recommend = models.Article.objects.filter(
            nid__in=[item["article_id"] for item in hot_recommend]).all()

        # 评论最多的文章
        hot_comment = models.Comment.objects.values('article_id').annotate(
            c=Count('article_id'))
        hot_comment = sorted(list(hot_comment),
                             key=lambda i: i['c'],
                             reverse=True)[:8]
        hot_comment = models.Article.objects.filter(
            nid__in=[item["article_id"] for item in hot_comment]).all()
        return render(
            request,
            'index.html',
            {
                "article_type_list": article_type_list,  # 文章类型
                'article_list': article_list,  # 文章列表
                "page_str": page_str,  # 分页HTML
                "article_type": article_type,  # 文章类型ID
                "user_obj": user_obj,  # 用户对象
                "hot_recommend": hot_recommend,  # 吐血推荐文章
                "hot_comment": hot_comment,  # 评论最多文章
            })
Ejemplo n.º 4
0
def tag(request):
    """

    博主个人标签管理
    :param request:
    :return:
    """
    username = request.session.get("username", None)  # 获取session中的用户名
    user_obj = models.UserInfo.objects.filter(
        username=username).select_related("blog").first()  # 获取用户对象
    tag_list = models.Tag.objects.filter(
        blog_id=user_obj.blog.nid).all()  # 获取用户所有标签
    if request.method == "GET":
        current_page = int(request.GET.get("p", 1))  # 获取用户选择的页码,默认为第一页
        page_obj = Page(current_page, len(tag_list))  # 获取分页对象
        page_str = page_obj.page_str("/backend/tag.html")  # 获取分页HTML
        tag_list = tag_list[page_obj.start:page_obj.end]  # 获取当前页数据
        tag_obj = TagForm()  # 生成标签form对象
        return render(
            request, 'backend_tag.html', {
                "user_obj": user_obj,
                "tag_list": tag_list,
                "tag_obj": tag_obj,
                "page_str": page_str
            })
    elif request.method == "POST":
        tag_obj = TagForm(request.POST)
        if tag_obj.is_valid():  # tagform验证通过
            tagname = tag_obj.cleaned_data.get("tagname")  # 获取新加的tagname
            if models.Tag.objects.filter(
                    blog_id=user_obj.blog.nid,
                    title=tagname).count():  # 检测tagname是否存在
                tag_obj.add_error("tagname", "该标签名已经存在!")
            else:  # 不存在则创建
                models.Tag.objects.create(title=tagname,
                                          blog_id=user_obj.blog.nid)
        page_obj = Page(1, len(tag_list))  # 获取分页对象
        page_str = page_obj.page_str("/backend/tag.html")  # 获取分页HTML
        tag_list = tag_list[page_obj.start:page_obj.end]  # 获取当前页数据
        return render(
            request, 'backend_tag.html', {
                "user_obj": user_obj,
                "tag_list": tag_list,
                "tag_obj": tag_obj,
                "page_str": page_str
            })
Ejemplo n.º 5
0
def category(request):
    """
    博主个人分类管理
    :param request:
    :return:
    """
    username = request.session.get("username", None)  # 获取session中的用户名
    user_obj = models.UserInfo.objects.filter(
        username=username).select_related("blog").first()  # 获取用户对象
    category_list = models.Category.objects.filter(
        blog_id=user_obj.blog.nid).all()  # 获取用户的文章分类
    if request.method == "GET":
        current_page = int(request.GET.get("p", 1))  # 获取用户选择的页码,默认为第一页
        page_obj = Page(current_page, len(category_list))  # 获取分页对象
        page_str = page_obj.page_str("/backend/category.html")  # 获取分页HTML
        category_list = category_list[page_obj.start:page_obj.end]  # 获取当前页数据
        category_obj = CategoryForm()
        return render(
            request, 'backend_category.html', {
                "user_obj": user_obj,
                "category_list": category_list,
                "category_obj": category_obj,
                "page_str": page_str,
            })
    elif request.method == "POST":
        category_obj = CategoryForm(request.POST)
        if category_obj.is_valid():  # categoryform验证通过
            category = category_obj.cleaned_data.get("category")  # category
            if models.Category.objects.filter(
                    blog_id=user_obj.blog.nid,
                    title=category).count():  # 检测category是否存在
                category_obj.add_error("category", "该分类名称已经存在!")
            else:  # 不存在则创建
                models.Category.objects.create(title=category,
                                               blog_id=user_obj.blog.nid)
        page_obj = Page(1, len(category_list))  # 获取分页对象
        page_str = page_obj.page_str("/backend/category.html")  # 获取分页HTML
        category_list = category_list[page_obj.start:page_obj.end]  # 获取当前页数据
        return render(
            request, 'backend_category.html', {
                "user_obj": user_obj,
                "category_list": category_list,
                "category_obj": category_obj,
                "page_str": page_str,
            })
Ejemplo n.º 6
0
def wdty_jk(request):
    """网贷天眼接口"""
    username = request.session.get("username")  # 获取用户名
    userobj = models.User.objects.using("default").filter(
        username=username).first()  # 获取用户对象
    time_from = ""  # 定义起始日期
    time_to = ""  # 定义终止日期
    num_show = 10  # 定义每页显示行数
    current_page = 1  # 定义当前页
    if request.method == "GET":
        today = datetime.strftime(datetime.now() + timedelta(-1),
                                  "%Y-%m-%d")  # 获取昨天日期
        default_wdty_jk_dict = {
            "time_from": today,
            "time_to": today
        }  # 默认日期为昨天
        time_from = request.session.get("wdty_jk_dict",
                                        default_wdty_jk_dict).get("time_from")
        time_to = request.session.get("wdty_jk_dict",
                                      default_wdty_jk_dict).get("time_to")
        current_page = int(request.GET.get("p", "1"))  # 获取当前页
    elif request.method == "POST":
        time_from = request.POST.get("time_from")  # 获取起始日期
        time_to = request.POST.get("time_to")  # 获取终止日期
        request.session["wdty_jk_dict"] = {
            "time_from": time_from,
            "time_to": time_to,
        }  # 将用户此次输入日期存入session
        current_page = 1  # POST请求则为第一页
    url = "https://last.51rz.com/api/ip2peye.php/Ip2peye/blist?token=acb1415727bc2b1375d8f3a221816c1b&time_from={time_from}&time_to={time_to}%2023:59:59&status=1&page_size={num_show}&page_index={current_page}".format(
        time_from=time_from,
        time_to=time_to,
        num_show=num_show,
        current_page=current_page,
    )
    response = requests.get(
        url, headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64)"})
    data = response.json() if response.status_code == 200 else {
        "page_count": 0,
        "loans": []
    }  # 获取接口返回的数据
    data_count = int(data.get("page_count", 0)) * num_show  # 获取总个数
    info_list = data.get("loans")  # 获取当前页内容
    page_obj = Page(current_page, data_count,
                    per_page_count=num_show)  # 生成分页对象
    page_str = page_obj.page_str("/backend/wdty_jk/")  # 获取分页html
    return render(
        request, "backend_wdty_jk.html", {
            "username": username,
            "userobj": userobj,
            "info_list": info_list,
            "page_str": page_str,
            "time_from": time_from,
            "time_to": time_to
        })
Ejemplo n.º 7
0
 def get(self):
     title = self.get_argument('title', None)
     current_page = self.get_argument("p", 1)
     per_page_count = self.get_argument("pre", 10)
     try:
         current_page = int(current_page)
         per_page_count = int(per_page_count)
     except ValueError as e:
         Logger().log(e, True)
         self.redirect('/index')
     if title:
         try:
             data_count = Article.select().where(
                 Article.title.contains(title)).count()
             if data_count <= 0:
                 return self.redirect('/404')
             page_obj = Page(current_page=current_page,
                             data_count=data_count,
                             per_page_count=per_page_count)
             page_html = page_obj.page_str(
                 base_url="search?title={_kw}".format(_kw=title))
             search_list = []
             if current_page == 1:
                 search_objs = Article.select().where(
                     Article.title.contains(title))[-page_obj.end:]
             else:
                 search_objs = Article.select().where(
                     Article.title.contains(
                         title))[-page_obj.end:-page_obj.start]
             for search_obj in search_objs:
                 search_list.append({
                     'id':
                     search_obj.id,
                     'title':
                     search_obj.title,
                     'summary':
                     search_obj.summary,
                     'read_count':
                     search_obj.read_count,
                     'created_date':
                     search_obj.created_date,
                     'article_type':
                     search_obj.article_type.article_type
                 })
             search_list.reverse()
             if current_page == 1 and len(search_list) < per_page_count:
                 page_html = ""
             self.render('index/search.html',
                         search_list=search_list,
                         page_html=page_html)
         except Exception as e:
             Logger().log(e, True)
             return self.render('index/500.html')
     self.redirect('/index')
Ejemplo n.º 8
0
 def get(self, tag_id=None):
     current_page = self.get_argument("p", 1)
     per_page_count = self.get_argument("pre", 10)
     try:
         current_page = int(current_page)
         per_page_count = int(per_page_count)
     except ValueError as e:
         Logger().log(e, True)
         return self.redirect('/index')
     if tag_id:
         try:
             data_count = Article.select().where(
                 Article.article_type_id == tag_id).count()
             if data_count <= 0:
                 return self.redirect('/404')
             page_obj = Page(current_page=current_page,
                             data_count=data_count,
                             per_page_count=per_page_count)
             page_html = page_obj.page_str(
                 base_url="/tag/{_tid}?".format(_tid=tag_id, ))
             tag_list = []
             if current_page == 1:
                 tag_objs = Article.select().where(
                     Article.article_type_id == tag_id)[-page_obj.end:]
             else:
                 tag_objs = Article.select().where(
                     Article.article_type_id ==
                     tag_id)[-page_obj.end:-page_obj.start]
             for search_obj in tag_objs:
                 tag_list.append({
                     'id':
                     search_obj.id,
                     'title':
                     search_obj.title,
                     'summary':
                     search_obj.summary,
                     'read_count':
                     search_obj.read_count,
                     'created_date':
                     search_obj.created_date,
                     'article_type':
                     search_obj.article_type.article_type
                 })
             tag_list.reverse()
             if current_page == 1 and len(tag_list) < per_page_count:
                 page_html = ""
             return self.render('index/tag.html',
                                tag_list=tag_list,
                                page_html=page_html)
         except Exception as e:
             Logger().log(e, True)
             return self.render('index/500.html')
     self.redirect('/index')
Ejemplo n.º 9
0
def blog(request, site, **kwargs):

    blog = models.Blog.objects.filter(site=site).select_related('user').first()
    UserInfo = models.UserInfo.objects.filter(blog=blog).first()
    articles_count = models.Article.objects.filter(
        blog=blog).order_by('-create_time').count()
    read_articles = models.Article.objects.filter(
        blog=blog).order_by('-read_count')[:5]
    hot_articles = models.Article.objects.filter(
        blog=blog).order_by('-up_count')[:5]

    #组合搜索
    article_type_list = models.Article.type_choices
    category_list = models.Category.objects.filter(blog=blog)
    blog = models.Blog.objects.filter(site=site).select_related('user').first()
    c = {}
    for k, v in kwargs.items():
        kwargs[k] = int(v)
        if v != '0':
            c[k] = v
    # 指定查找所有属于该博主的博文
    c['blog'] = blog
    data_count = models.Article.objects.filter(**c).count()
    articles = models.Article.objects.filter(
        **c).order_by('-create_time').select_related('blog')

    # 分页
    current_page = request.GET.get('p',
                                   1)  # 获取对应get数据p: href="/user_list/?p=%s
    current_page = int(current_page)
    page_num = 10
    page = Page(current_page, len(articles), page_num)
    data = articles[page.start:page.end]  # 列表切片
    page_str = page.page_str(request.path_info)
    page_start = page.start

    return render(
        request, 'blog.html', {
            'userinfo': UserInfo,
            'blog': blog,
            'articles': data,
            'articles_count': articles_count,
            'page_str': page_str,
            'read': read_articles,
            'hot': hot_articles,
            'article_type_list': article_type_list,
            'category_list': category_list,
            'arg_dic': kwargs,
            'data_count': data_count,
            'page_start': page_start,
        })
Ejemplo n.º 10
0
def articles(request, *args, **kwargs):
    # print(kwargs)
    #获取当前url
    # print(request.path_info)
    # from django.urls import reverse
    # url = reverse('articles',kwargs=kwargs)
    # print(url)

    # article_type_list = models.ArticleType.objects.all()
    # 组合搜索
    article_type_list = models.Article.type_choices
    category_list = models.Category.objects.filter(
        blog_id=request.session['user_info']['blog__nid'])
    blog = models.Blog.objects.filter(
        site=request.session['user_info']['blog__site']).select_related(
            'user').first()

    #组合搜索
    c = {}
    for k, v in kwargs.items():
        kwargs[k] = int(v)
        if v != '0':
            c[k] = v
    # 指定查找所有属于该博主的博文
    c['blog'] = blog
    data_count = models.Article.objects.filter(**c).count()
    articles = models.Article.objects.filter(
        **c).order_by('-create_time').select_related('blog')

    #分页
    current_page = request.GET.get('p',
                                   1)  # 获取对应get数据p: href="/user_list/?p=%s
    current_page = int(current_page)
    page = Page(current_page, len(articles), 7)
    data = articles[page.start:page.end]  # 列表切片
    page_str = page.page_str(reverse('articles', kwargs=kwargs))

    #显示序号
    page_start = page.start

    return render(
        request, 'BM_articles.html', {
            'arts': data,
            'page_str': page_str,
            'article_type_list': article_type_list,
            'category_list': category_list,
            'arg_dic': kwargs,
            'data_count': data_count,
            'page_start': page_start
        })
Ejemplo n.º 11
0
def filter(request, site, condition, val):
    """
    分类显示
    :param request:
    :param site: 博客站点
    :param condition: 筛选条件
    :param val: 值
    :return:
    """
    blog_obj = models.Blog.objects.filter(
        site=site).select_related('user').first()
    if not blog_obj:
        return redirect('/')
    tag_list = models.Tag.objects.filter(blog=blog_obj)  # 获取博主所有的标签
    category_list = models.Category.objects.filter(blog=blog_obj)  # 获取博主所有的分类
    # date_format(create_time,"%Y-%m")
    date_list_sql = """select nid, count(nid) as num,strftime("%%Y-%%m",create_time) as ctime 
            from repository_article where blog_id = %s
            group by strftime("%%Y-%%m",create_time)
            """ % blog_obj.nid
    date_list = models.Article.objects.raw(date_list_sql)  # 获取博主文章所揽阔的月份
    template_name = "home_summary_list.html"
    if condition == 'tag':
        template_name = "home_title_list.html"
        article_list = models.Article.objects.filter(tags__title=val,
                                                     blog=blog_obj).all()
    elif condition == 'category':
        article_list = models.Article.objects.filter(category__title=val,
                                                     blog=blog_obj).all()
    elif condition == 'date':
        article_list = models.Article.objects.filter(blog=blog_obj).extra(
            where=['strftime("%%Y-%%m",create_time)=%s'], params=[
                val,
            ]).all()
    else:
        article_list = []
    current_page = int(request.GET.get("p", 1))  # 获取用户选择的页码,默认为第一页
    page_obj = Page(current_page, len(article_list))  # 获取分页对象
    page_str = page_obj.page_str("/%s/%s/%s.html" %
                                 (site, condition, val))  # 获取分页HTML
    article_list = article_list[page_obj.start:page_obj.end]  # 获取当前页数据
    return render(
        request, template_name, {
            'blog_obj': blog_obj,
            'tag_list': tag_list,
            'category_list': category_list,
            'date_list': date_list,
            'article_list': article_list,
            'page_str': page_str,
        })
Ejemplo n.º 12
0
def wdzj_jk(request):
    """网贷之家接口"""
    username = request.session.get("username")  # 获取用户名
    userobj = models.User.objects.using("default").filter(
        username=username).first()  # 获取用户对象
    qdate = ""  # 定义日期
    num_show = 10  # 定义每页显示行数
    current_page = 1  # 定义当前页
    if request.method == "GET":
        today = datetime.strftime(datetime.now() + timedelta(-1),
                                  "%Y-%m-%d")  # 获取昨天日期
        default_wdzj_jk_dict = {"qdate": today}  # 默认日期为昨天
        qdate = request.session.get("wdzj_jk_dict",
                                    default_wdzj_jk_dict).get("qdate")
        current_page = int(request.GET.get("p", "1"))  # 获取当前页
    elif request.method == "POST":
        qdate = request.POST.get("qdate")  # 获取起始日期
        request.session["wdzj_jk_dict"] = {
            "qdate": qdate
        }  # 将用户此次输入日期存入session
        current_page = 1  # POST请求则为第一页
    url = "https://last.51rz.com/api/iwdzj.php/IwdzjnewV2/GetNowProjects?token=2e7c3ff493e716d0680d175513b0dff4&date={qdate}&page={current_page}&pageSize={num_show}".format(
        qdate=qdate,
        num_show=num_show,
        current_page=current_page,
    )
    response = requests.get(
        url, headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64)"})
    data = response.json() if response.status_code == 200 else {
        "totalCount": 0,
        "borrowList": []
    }  # 获取接口返回的数据
    data_count = int(data.get("totalCount", 0))  # 获取总个数
    info_list = data.get("borrowList")  # 获取当前页内容
    page_obj = Page(current_page, data_count,
                    per_page_count=num_show)  # 生成分页对象
    page_str = page_obj.page_str("/backend/wdzj_jk/")  # 获取分页html
    return render(
        request, "backend_wdzj_jk.html", {
            "username": username,
            "userobj": userobj,
            "info_list": info_list,
            "page_str": page_str,
            "qdate": qdate
        })
Ejemplo n.º 13
0
    def get(self, request, *agrs, **kwargs):
        LIST = []
        msg = Show.objects.order_by("-create_time")
        for i in msg:
            LIST.append(i)
        current_page = request.GET.get('p', 1)
        current_page = int(current_page)
        page_obj = Page(current_page, len(LIST))
        comments = 1
        data = LIST[page_obj.start():page_obj.end()]
        context = {
            'msg': msg,
            'content_all': data,
            'page_str': page_obj.page_str(reverse('file:inform')),
            'comments': comments
        }

        return render(request, 'inform.html', context)
Ejemplo n.º 14
0
def myblog(request, site, nid):
    blog = models.Blog.objects.filter(site=site).select_related('user').first()
    UserInfo = models.UserInfo.objects.filter(blog=blog).first()
    articles_count = models.Article.objects.filter(
        blog=blog).order_by('-create_time').count()
    new_articles = models.Article.objects.filter(
        blog=blog).order_by('-create_time')[:5]
    obj = models.Article.objects.filter(blog=blog, nid=nid).first()
    obj_content = models.ArticleDetail.objects.filter(article=obj).first()
    hot_articles = models.Article.objects.filter(
        blog=blog).order_by('-up_count')[:5]
    comment = models.Comment.objects.filter(
        article_id=nid).order_by('-create_time')

    #每次请求,阅读数加一
    # print(obj.read_count)
    n = obj.read_count
    n += 1
    models.Article.objects.filter(blog=blog, nid=nid).update(read_count=n)

    # 分页
    current_page = request.GET.get('p',
                                   1)  # 获取对应get数据p: href="/user_list/?p=%s
    current_page = int(current_page)
    page = Page(current_page, len(comment), 10)
    data = comment[page.start:page.end]  # 列表切片
    k = 'content_comment'
    page_str = page.page_str(request.path_info, k)
    comment_count = len(comment)
    page_start = page.start
    return render(
        request, 'myblog.html', {
            'userinfo': UserInfo,
            'blog': blog,
            'articles_count': articles_count,
            'new': new_articles,
            'hot': hot_articles,
            'obj': obj,
            'obj_content': obj_content,
            'comment': data,
            'page_str': page_str,
            'page_start': page_start,
            'comment_count': comment_count,
        })
Ejemplo n.º 15
0
    def get(self):
        current_page = self.get_argument("p", 1)
        per_page_count = self.get_argument("pre", 10)
        try:
            current_page = int(current_page)
            per_page_count = int(per_page_count)
        except ValueError as e:
            Logger().log(e, True)
            self.redirect('/index')
        try:
            data_count = Article.select().count()
            page_obj = Page(current_page=current_page,
                            data_count=data_count,
                            per_page_count=per_page_count)
            page_html = page_obj.page_str(base_url="index?")
            at_list = []
            if current_page == 1:
                article_objs = Article.select()[-page_obj.end:]
            else:
                article_objs = Article.select()[-page_obj.end:-page_obj.start]

            for article_obj in article_objs:
                at_list.append({
                    'id':
                    article_obj.id,
                    'title':
                    article_obj.title,
                    'summary':
                    article_obj.summary,
                    'read_count':
                    article_obj.read_count,
                    'created_date':
                    article_obj.created_date,
                    'article_type':
                    article_obj.article_type.article_type
                })
            at_list.reverse()
        except Exception as e:
            Logger().log(e, True)
            return self.render('index/500.html')
        if current_page == 1 and len(at_list) < per_page_count:
            page_html = ""
        self.render('index/index.html', at_list=at_list, page_html=page_html)
Ejemplo n.º 16
0
def detail(request, site, nid):
    """
    博文详细页
    :param request:
    :param site:
    :param nid:
    :return:
    """
    blog_obj = models.Blog.objects.filter(
        site=site).select_related('user').first()
    if not blog_obj:
        return redirect('/')
    tag_list = models.Tag.objects.filter(blog=blog_obj)  # 获取博主所有的标签
    category_list = models.Category.objects.filter(blog=blog_obj)  # 获取博主所有的分类
    # date_format(create_time,"%Y-%m")
    date_list_sql = """select nid, count(nid) as num,strftime("%%Y-%%m",create_time) as ctime 
        from repository_article where blog_id = %s
        group by strftime("%%Y-%%m",create_time)
        """ % blog_obj.nid
    date_list = models.Article.objects.raw(date_list_sql)  # 获取博主文章所揽阔的月份
    # 获取文章对象
    article = models.Article.objects.filter(blog=blog_obj,
                                            nid=nid).select_related(
                                                'category',
                                                'article_detail').first()
    article.read_count += 1  # 文章阅读数加一
    article.save()  # 保存文章对象
    comment_list = models.Comment.objects.filter(
        article=article).select_related('reply')  # 获取评论列表
    current_page = int(request.GET.get("p", 1))  # 获取用户选择的页码,默认为第一页
    page_obj = Page(current_page, len(comment_list))  # 获取分页对象
    page_str = page_obj.page_str("/%s/%s.html" % (site, nid))  # 获取分页HTML
    comment_list = comment_list[page_obj.start:page_obj.end]  # 获取当前页数据
    return render(
        request, 'home_detail.html', {
            'blog_obj': blog_obj,
            'tag_list': tag_list,
            'category_list': category_list,
            'date_list': date_list,
            'article': article,
            'comment_list': comment_list,
            'page_str': page_str,
        })
Ejemplo n.º 17
0
def home(request, site):
    """
    博主个人首页
    :param request:
    :param site: 博主的网站后缀如:http://xxx.com/wupeiqi.html
    :return:
    """
    blog_obj = models.Blog.objects.filter(
        site=site).select_related('user').first()
    if not blog_obj:
        return redirect('/')
    tag_list = models.Tag.objects.filter(blog=blog_obj)  # 获取博主所有的标签
    category_list = models.Category.objects.filter(blog=blog_obj)  # 获取博主所有的分类
    # date_format(create_time,"%Y-%m")
    date_list_sql = """select nid, count(nid) as num,strftime("%%Y-%%m",create_time) as ctime 
        from repository_article where blog_id = %s
        group by strftime("%%Y-%%m",create_time)
        """ % blog_obj.nid
    date_list = models.Article.objects.raw(date_list_sql)  # 获取博主文章所揽阔的月份
    article_list = models.Article.objects.filter(
        blog=blog_obj).order_by('-nid').all()  # 获取博主所有文章
    top_article_list = models.Article.objects.filter(blog=blog_obj,
                                                     top=1).all()  # 获取博主置顶文章
    current_page = int(request.GET.get("p", 1))  # 获取用户选择的页码,默认为第一页
    page_obj = Page(current_page, len(article_list))  # 获取分页对象
    page_str = page_obj.page_str("/%s.html" % site)  # 获取分页HTML
    article_list = article_list[page_obj.start:page_obj.end]  # 获取当前页数据
    return render(
        request, 'home.html', {
            'blog_obj': blog_obj,
            'tag_list': tag_list,
            'category_list': category_list,
            'date_list': date_list,
            'article_list': article_list,
            'page_str': page_str,
            'top_article_list': top_article_list,
        })
Ejemplo n.º 18
0
def category(request):
    '''
    博主个人文章分类管理
    '''

    blog_id = request.session['user_info']['blog__nid']
    obj = models.Article.objects.filter(blog_id=blog_id)
    category = models.Category.objects.filter(blog_id=blog_id)
    category_list = []
    if obj.exists():
        for i in category:
            m = 0
            for n in obj:
                if i.nid == n.category_id:
                    m += 1
            category_list.append([i.title, m, i])
    else:
        for i in category:
            category_list.append([i.title, 0, i])
    # print(category_list)

    #分页
    current_page = request.GET.get('p',
                                   1)  # 获取对应get数据p: href="/user_list/?p=%s
    current_page = int(current_page)
    page_num = 8
    page = Page(current_page, len(category_list), page_num)
    data = category_list[page.start:page.end]  # 列表切片
    page_str = page.page_str('/bm/category/')
    page_start = page.start

    return render(request, 'BM_category.html', {
        'category': data,
        'page_str': page_str,
        'page_start': page_start,
    })
Ejemplo n.º 19
0
def sales_achievement(request):
    """
    展示电销业绩
    :param request:
    :return:
    """
    if request.method == "GET":
        current_page = request.GET.get("p")  # 获取用户想看的页数,默认是第一页
        # 获取客服ID
        kefu_id = request.session.get(
            "sales_achievement_kefu_id",
            "1285094,1285095,1285099,1285100,1296124,1455368,1455369,1455375"
        )
        if current_page:
            current_page = int(current_page)
            # 获取起始日期,默认为本月第一天
            start_time = request.session.get(
                "sales_achievement_start_time",
                datetime.date(datetime.now()).replace(day=1)
            )
            # 获取终止日期,默认为昨天
            end_time = request.session.get(
                "sales_achievement_end_time", datetime.date(datetime.now()) - timedelta(1)
            )
        else:  # 相当于用户第一次访问
            current_page = 1
            start_time = datetime.date(datetime.now()).replace(day=1)
            end_time = datetime.date(datetime.now()) - timedelta(1)
        sales_achievement_obj = SalesAchievementForm(initial={
            "kefu_id": kefu_id,
            "start_time": start_time,
            "end_time": end_time
        })  # 获取电销业绩展示form
        # 获取电销业绩展示SQL
        sales_achievement_sql = db_connect.get_sql("crm", "RzSql", "exhibition", "sales_achievement.sql")
        # 获取电销业绩详情列表
        sales_achievement_info_list = db_connect.get_info_list("rz", sales_achievement_sql.format(
            kefu_id=kefu_id,
            start_time=start_time,
            end_time=end_time,
        ))
        sales_achievement_chart_display_info_list = sales_achievement_info_list[:-1]  # 剔除总计
        chart_display_dict = {
            "kefu_list": [],  # 客服列表
            "tz_j_list": [],  # 投资金额列表
            "nianhua_list": [],  # 年化金额列表
            "recover_account_list": [],  # 待收金额列表
        }
        for item in sales_achievement_chart_display_info_list:
            chart_display_dict["kefu_list"].append(item["kefu"])
            chart_display_dict["tz_j_list"].append(float(item["tz_j"]))
            chart_display_dict["nianhua_list"].append(float(item["nianhua"]))
            chart_display_dict["recover_account_list"].append(float(item["recover_account"]))
        page_obj = Page(current_page, len(sales_achievement_info_list))  # 获取分页对象
        sales_achievement_info_list = sales_achievement_info_list[page_obj.start:page_obj.end]  # 对详情列表进行拆分
        page_str = page_obj.page_str("/crm/sales_achievement/")  # 获取分页HTML
        return render(request, "sales_achievement.html", {
            "sales_achievement_obj": sales_achievement_obj,
            "sales_achievement_info_list": sales_achievement_info_list,
            "page_str": page_str,
            "chart_display_dict": chart_display_dict
        })
    elif request.method == "POST":
        sales_achievement_obj = SalesAchievementForm(request.POST)  # 获取form对象
        if sales_achievement_obj.is_valid():
            kefu_id = sales_achievement_obj.cleaned_data.pop("kefu_id")
            # 格式化用户输入起始日期
            start_time = datetime.strftime(sales_achievement_obj.cleaned_data.pop("start_time"), "%Y-%m-%d")
            # 格式化用户输入终止日期
            end_time = datetime.strftime(sales_achievement_obj.cleaned_data.pop("end_time"), "%Y-%m-%d")
            request.session["sales_achievement_kefu_id"] = kefu_id  # 存储用户本次查询的客服ID
            request.session["sales_achievement_start_time"] = start_time  # 存储用户本次查询的起始日期
            request.session["sales_achievement_end_time"] = end_time  # 存储用户本次查询的终止日期
            # 获取电销业绩展示SQL
            sales_achievement_sql = db_connect.get_sql("crm", "RzSql", "exhibition", "sales_achievement.sql")
            # 获取电销业绩详情列表
            sales_achievement_info_list = db_connect.get_info_list("rz", sales_achievement_sql.format(
                kefu_id=kefu_id,
                start_time=start_time,
                end_time=end_time,
            ))
            sales_achievement_chart_display_info_list = sales_achievement_info_list[:-1]  # 剔除总计
            chart_display_dict = {
                "kefu_list": [],  # 客服列表
                "tz_j_list": [],  # 投资金额列表
                "nianhua_list": [],  # 年化金额列表
                "recover_account_list": [],  # 待收金额列表
            }
            for item in sales_achievement_chart_display_info_list:
                chart_display_dict["kefu_list"].append(item["kefu"])
                chart_display_dict["tz_j_list"].append(float(item["tz_j"]))
                chart_display_dict["nianhua_list"].append(float(item["nianhua"]))
                chart_display_dict["recover_account_list"].append(float(item["recover_account"]))
            page_obj = Page(1, len(sales_achievement_info_list))  # 获取分页对象
            sales_achievement_info_list = sales_achievement_info_list[page_obj.start:page_obj.end]  # 对详情列表进行拆分
            page_str = page_obj.page_str("/crm/sales_achievement/")  # 获取分页HTML
            return render(request, "sales_achievement.html", {
                "sales_achievement_obj": sales_achievement_obj,
                "sales_achievement_info_list": sales_achievement_info_list,
                "page_str": page_str,
                "chart_display_dict": chart_display_dict
            })
        else:
            return render(request, "sales_achievement.html", {
                "sales_achievement_obj": sales_achievement_obj
            })
Ejemplo n.º 20
0
def tg_info(request):
    """后台推广数据信息"""
    username = request.session.get("username")  # 获取用户名
    userobj = models.User.objects.using("default").filter(
        username=username).first()  # 获取用户对象
    if request.method == "GET":
        start_time = request.session.get("smst_start_time", "")  # 获取上次查询的起始日期
        end_time = request.session.get("smst_end_time", "")  # 获取上次查询的终止日期
        qudao_name = request.session.get("smst_qudao_name_id",
                                         "APP 苹果")  # 获取上次查询的渠道名称
        data_type = request.session.get("smst_data_type_id",
                                        "1")  # 获取上次查询的是实名还是首投
        info_list = request.session.get("tg_info_list", [])  # 获取上次查询的信息,没有则置空
        smst_obj = SmStForm({
            "start_time": start_time,
            "end_time": end_time,
            "qudao_name": qudao_name,
            "data_type": data_type
        })  # 获取实名首投form对象
        current_page = int(request.GET.get("p", "1"))  # 获取当前页,没有则默认第一页
        page_obj = Page(current_page, len(info_list))  # 生成分页对象
        info_list = info_list[page_obj.start:page_obj.end]  # 获取当前页的所有文章
        page_str = page_obj.page_str("/backend/tg_info/")  # 获取分页html
        return render(
            request, "backend_tg_info.html", {
                "username": username,
                "userobj": userobj,
                "info_list": info_list,
                "page_str": page_str,
                "smst_obj": smst_obj
            })
    elif request.method == "POST":
        data_type_dict = {"1": "sm.sql", "2": "st.sql"}  # 实名首投对应sql语句
        smst_obj = SmStForm(request.POST)  # 获取实名首投form对象
        if smst_obj.is_valid():  # 验证是否通过form认证
            start_time = datetime.strftime(
                smst_obj.cleaned_data.get("start_time"),
                "%Y-%m-%d")  # 格式化用户输入起始日期
            end_time = datetime.strftime(smst_obj.cleaned_data.get("end_time"),
                                         "%Y-%m-%d")  # 格式化用户输入终止日期
            qudao_name = smst_obj.cleaned_data.get("qudao_name")  # 获取用户输入渠道名称
            data_type_id = smst_obj.cleaned_data.get(
                "data_type")  # 获取用户输入的是实名还是首投
            # 获取渠道名称对应的渠道标识
            qudao_sign_list = db_connect.get_info_list(
                "rz_bi", "SELECT sign from rzjf_qudao_name where name = '%s'" %
                qudao_name)
            if qudao_sign_list:  # 能获取到渠道名称对应的渠道标识
                qudao_sign_list = [
                    "'%s'" % i["sign"] for i in qudao_sign_list
                ]  # 以逗号分隔渠道标识
                qudao_sign = ",".join(qudao_sign_list)  # 重组渠道标识
                # 获取sql语句
                sql = db_connect.get_sql("crm", "RzSql", "tg",
                                         data_type_dict[data_type_id])
                # 格式化sql语句
                sql = sql.format(start_time=start_time,
                                 end_time=end_time,
                                 name=qudao_sign)
                info_list = db_connect.get_info_list("rz", sql)  # 获取查询结果
                info_list = json.loads(
                    json.dumps(info_list, cls=JsonCustomEncoder))
                request.session["tg_info_list"] = info_list  # 将查询结果放入session
                request.session[
                    "smst_start_time"] = start_time  # 将用户查询的日期,保存以便告诉用户刚才所查询的日期
                request.session["smst_end_time"] = end_time
                request.session[
                    "smst_qudao_name_id"] = qudao_name  # 存放这次查询的渠道名称
                request.session[
                    "smst_data_type_id"] = data_type_id  # 存放这次查询的是实名还是首投
                page_obj = Page(1, len(info_list))  # 生成分页对象
                info_list = info_list[page_obj.start:
                                      page_obj.end]  # 获取当前页的所有文章
                page_str = page_obj.page_str("/backend/tg_info/")  # 获取分页html
                return render(
                    request, "backend_tg_info.html", {
                        "username": username,
                        "userobj": userobj,
                        "info_list": info_list,
                        "page_str": page_str,
                        "smst_obj": smst_obj
                    })
            else:
                smst_obj.add_error("qudao_name", "该渠道不存在,或者未添加!")  # 添加错误信息
                return render(request, "backend_tg_info.html", {
                    "username": username,
                    "userobj": userobj,
                    "smst_obj": smst_obj
                })
        else:
            return render(request, "backend_tg_info.html", {
                "username": username,
                "userobj": userobj,
                "smst_obj": smst_obj
            })