コード例 #1
0
ファイル: poempost.py プロジェクト: benywon/PyDjangoBlog
def ShowPoem(request):
    lengh = len(BlogPoem.objects.all())
    try:
        num = request.GET['p']
        num = int(num)
    except:
        num = 1
    #我们先来确定这个范围
    if num == 0:
        num = 1
    if lengh <= showlen:
        start = 0
        end = showlen
    else:
        start = (num - 1) * showlen
        end = num * showlen
    posts = BlogPoem.objects.all().order_by('-id')[start:end]
    for po in posts:
        pre = po.body.encode("utf-8")
        prestr = __getdiv(pre)
        div = u";".encode('utf-8')
        po.k = prestr.split(div)
    IsLogin = checkLogin(request)
    t = loader.get_template("shuo.html")
    c = Context({
        'poems': posts,
        'number': num,
        'pre': num - 1,
        'next': num + 1,
        'IsLogin': IsLogin
    })
    return t.render(c)
コード例 #2
0
def ShowPic(request):
    lengh = len(BlogPic.objects.all())
    try:
        num = request.GET['p']
        num = int(num)
    except:
        num = 1
    #我们先来确定这个范围
    if num == 0:
        num = 1
    if lengh <= showlen:
        start = 0
        end = showlen
    else:
        start = (num - 1) * showlen
        end = num * showlen
    username = request.COOKIES.get('username')
    if username == 'god':
        posts = BlogPic.objects.all().order_by('-id')[start:end]
    else:
        posts = BlogPic.objects.filter(
            Q(isshow__exact=True)
            | Q(username=username)).order_by('-id')[start:end]

    IsLogin = checkLogin(request)
    t = loader.get_template("xc.html")
    c = Context({
        'posts': posts,
        'number': num,
        'pre': num - 1,
        'next': num + 1,
        'IsLogin': IsLogin
    })
    return t.render(c)
コード例 #3
0
ファイル: poempost.py プロジェクト: benywon/PyDjangoBlog
def ShowPoem(request):
    lengh=len(BlogPoem.objects.all())
    try:
        num=request.GET['p']
        num=int(num)
    except:
        num=1
    #我们先来确定这个范围
    if num==0:
        num=1
    if lengh<=showlen:
        start=0
        end=showlen
    else:
        start=(num-1)*showlen
        end=num*showlen
    posts=BlogPoem.objects.all().order_by('-id')[start:end]
    for po in posts:
        pre=po.body.encode("utf-8")
        prestr=__getdiv(pre)
        div=u";".encode('utf-8')
        po.k=prestr.split(div)
    IsLogin=checkLogin(request)
    t = loader.get_template("shuo.html")
    c = Context({'poems':posts,'number':num,'pre':num-1,'next':num+1,'IsLogin':IsLogin})
    return t.render(c)
コード例 #4
0
ファイル: BlogContent.py プロジェクト: benywon/PyDjangoBlog
def ShowBlog(request):
    showlen=10
    lengh=len(BlogsPost.objects.using('Articles').all())
    try:
        num=request.GET['p']
        num=int(num)
    except:
        num=1
    #我们先来确定这个范围
    if num==0:
        num=1
    if lengh<=showlen:
        start=0
        end=showlen
    else:
        start=(num-1)*showlen
        end=num*showlen
    posts=BlogsPost.objects.using('Articles').all().order_by('-id')[start:end]
    for post in posts:
        [post.ishowpic,post.picshow]=__findAnav(post.body)

    IsLogin=checkLogin(request)
    t = loader.get_template("learn.html")
    c = Context({'posts':posts,'number':num,'pre':num-1,'next':num+1,'IsLogin':IsLogin})
    return t.render(c)
コード例 #5
0
ファイル: BlogContent.py プロジェクト: benywon/PyDjangoBlog
def ShowBlog(request):
    showlen = 10
    lengh = len(BlogsPost.objects.using('Articles').all())
    try:
        num = request.GET['p']
        num = int(num)
    except:
        num = 1
    #我们先来确定这个范围
    if num == 0:
        num = 1
    if lengh <= showlen:
        start = 0
        end = showlen
    else:
        start = (num - 1) * showlen
        end = num * showlen
    posts = BlogsPost.objects.using('Articles').all().order_by(
        '-id')[start:end]
    for post in posts:
        [post.ishowpic, post.picshow] = __findAnav(post.body)

    IsLogin = checkLogin(request)
    t = loader.get_template("learn.html")
    c = Context({
        'posts': posts,
        'number': num,
        'pre': num - 1,
        'next': num + 1,
        'IsLogin': IsLogin
    })
    return t.render(c)
コード例 #6
0
ファイル: BlogContent.py プロジェクト: benywon/PyDjangoBlog
def ShowArticle(request):

    try:
        num = request.GET['id']
        num = int(num)
    except:
        num = 1
    post = BlogsPost.objects.using('Articles').get(id=num)
    post.timestamp = post.timestamp.date()
    post.comments = post.blogcomments_set.using('Articles').all().order_by(
        '-id')
    username = request.COOKIES.get('username')
    if request.method == "POST":
        uf = ArticleCommentsForm(request.POST)
        if uf.is_valid():
            commentscontent = uf.cleaned_data['body']
            comments = BlogComments()
            comments.body = commentscontent
            comments.timestamp = datetime.datetime.now()
            if username == '' or username is None:
                username = '******'
            comments.auther = username
            post.blogcomments_set.add(comments)
            uf = ArticleCommentsForm()
    try:
        dnum = request.GET['DcId']
        dnum = int(dnum)
    except:
        dnum = -1
    uf = ArticleCommentsForm()
    if username == 'god':
        if dnum > 0:
            BlogComments.objects.using('Articles').filter(
                id__exact=dnum).delete()
        post.god = True
    else:
        post.god = False
        for co in post.comments:
            if co.auther == username:
                co.candele = True
                if dnum > 0:
                    BlogComments.objects.using('Articles').filter(
                        id__exact=dnum).delete()
                    dnum = -1
            else:
                co.candele = False
    if username == 'god':
        post.god = True
    else:
        post.god = False
    IsLogin = checkLogin(request)
    t = loader.get_template("Articles.html")
    c = Context({'post': post, 'uf': uf, "Aid": num, 'IsLogin': IsLogin})
    return HttpResponse(t.render(c))
コード例 #7
0
ファイル: BlogContent.py プロジェクト: benywon/PyDjangoBlog
def ShowArticle(request):

    try:
        num=request.GET['id']
        num=int(num)
    except:
        num=1
    post=BlogsPost.objects.using('Articles').get(id=num)
    post.timestamp=post.timestamp.date()
    post.comments=post.blogcomments_set.using('Articles').all().order_by('-id')
    username = request.COOKIES.get('username')
    if request.method=="POST":
        uf = ArticleCommentsForm(request.POST)
        if uf.is_valid():
            commentscontent = uf.cleaned_data['body']
            comments=BlogComments()
            comments.body=commentscontent
            comments.timestamp=datetime.datetime.now()
            if username =='' or username is None:
                username='******'
            comments.auther=username
            post.blogcomments_set.add(comments)
            uf=ArticleCommentsForm()
    try:
        dnum=request.GET['DcId']
        dnum=int(dnum)
    except:
        dnum=-1
    uf=ArticleCommentsForm()
    if username =='god':
        if dnum>0:
            BlogComments.objects.using('Articles').filter(id__exact=dnum).delete()
        post.god=True
    else:
        post.god=False
        for co in post.comments:
            if co.auther == username:
                co.candele=True
                if dnum>0:
                    BlogComments.objects.using('Articles').filter(id__exact=dnum).delete()
                    dnum=-1
            else:
                co.candele=False
    if username =='god':
        post.god=True
    else:
        post.god=False
    IsLogin=checkLogin(request)
    t = loader.get_template("Articles.html")
    c = Context({'post':post,'uf':uf,"Aid":num,'IsLogin':IsLogin})
    return HttpResponse(t.render(c))
コード例 #8
0
ファイル: CommentPost.py プロジェクト: benywon/PyDjangoBlog
def ShowComment(request):
    if request.method == "POST":
        comment=request.POST.get('comment')
        yourname=request.POST.get('name')
        if yourname=='':
            yourname='匿名'
        canshow=request.POST.get('canshow')
        time=datetime.datetime.now()
        if canshow=='True':
            canshow=True
        else:
            canshow=False

        mycomment=BlogComment()
        mycomment.comments=comment
        mycomment.canshow=canshow
        mycomment.name=yourname
        mycomment.timestamp=time
        mycomment.save()
    lengh=len(BlogComment.objects.all())
    try:
        num=request.GET['p']
        num=int(num)
    except:
        num=1
    #我们先来确定这个范围
    if num==0:
        num=1
    if lengh<=showlen:
        start=0
        end=showlen
    else:
        start=(num-1)*showlen
        end=num*showlen
    username = request.COOKIES.get('username')
    if username == 'god':
        posts=BlogComment.objects.all().order_by('-id')[start:end]
    else:
        posts=BlogComment.objects.filter(canshow__exact=True).order_by('-id')[start:end]
    IsLogin=checkLogin(request)
    t = loader.get_template("guestbook.html")
    c = Context({'posts':posts,'number':num,'pre':num-1,'next':num+1,'IsLogin':IsLogin})
    return t.render(c)
コード例 #9
0
def ShowTweet(request):
    lengh = len(GodTweet.objects.all())
    try:
        num = request.GET['p']
        num = int(num)
    except:
        num = 1
    #我们先来确定这个范围
    if num == 0:
        num = 1
    if lengh <= showlen:
        start = 0
        end = showlen
    else:
        start = (num - 1) * showlen
        end = num * showlen
    posts = GodTweet.objects.all().order_by('-id')[start:end]
    for post in posts:
        numb = len(post.tweet.encode('utf-8'))
        if numb < 110:
            post.shownumber = range(5)
        elif numb < 200:
            post.shownumber = range(4)
        elif numb < 300:
            post.shownumber = range(3)
        elif numb < 406:
            post.shownumber = range(2)
        elif numb < 500:
            post.shownumber = range(1)
        else:
            post.shownumber = False
    IsLogin = checkLogin(request)
    t = loader.get_template("riji.html")
    c = Context({
        'posts': posts,
        'number': num,
        'pre': num - 1,
        'next': num + 1,
        'IsLogin': IsLogin
    })
    return t.render(c)
コード例 #10
0
ファイル: VideoPost.py プロジェクト: benywon/PyDjangoBlog
def ShowVideo(request):
    showlen = 10
    lengh = len(BlogVideo.objects.all())
    username = request.COOKIES.get('username')
    if username == '' or username is None:  #检测是否已经登录
        return HttpResponseRedirect('/blog/login')
    try:
        num = request.GET['p']
        num = int(num)
    except:
        num = 1
    #我们先来确定这个范围
    if num == 0:
        num = 1
    if lengh <= showlen:
        start = 0
        end = showlen
    else:
        start = (num - 1) * showlen
        end = num * showlen
    if username == 'god':
        posts = BlogVideo.objects.all().order_by('-id')[start:end]
    else:
        posts = BlogVideo.objects.filter(
            Q(isshow__exact=True)
            | Q(user=username)).order_by('-id')[start:end]

    IsLogin = checkLogin(request)
    t = loader.get_template("VideoShow.html")
    c = Context({
        'posts': posts,
        'number': num,
        'pre': num - 1,
        'next': num + 1,
        'IsLogin': IsLogin
    })
    return HttpResponse(t.render(c))