Example #1
0
def filter_by(request, by, id):
    """
    按标签或分类筛选博客
    """
    if by == "tag":
        tag = Tag.objects.get_by_id(id)
        if tag is None:
            raise Http404
        return render_and_response(request, "index.html", pager(request, "tag", id))
    elif by == "cate":
        cate = Category.objects.get_by_id(id)
        if cate is None:
            raise Http404
        return render_and_response(request, "index.html", pager(request, "cate", id))
    else:
        raise Http404
Example #2
0
def shorten(req):
    """
    Generate a short url from a long url
    """
    t = 'shorten.html'
    if req.method == 'GET':
        return render_and_response(req, t)
    ori_url = req.POST.get('url')
    name = req.POST.get('name')
    if not re.search(URL_REGEX, ori_url):
        return render_and_response(req, t, {'msg': 'invalid url'})
    code = get_short_url(ori_url)
    obj = models.ShortLink.objects.get_or_create(code=code,
                                                 defaults={'name': name,
                                                           'link': ori_url})[0]
    return render_and_response(req, t, {'result': obj.get_short_url()})
Example #3
0
def search(request):
    """
    搜索博客
    """
    return render_and_response(
        request, 'index.html',
        pager(request, 'search', request.REQUEST.get('k')))
Example #4
0
def filter_by(request, by, id):
    """
    按标签或分类筛选博客
    """
    if by == 'tag':
        tag = Tag.objects.get_by_id(id)
        if tag is None:
            raise Http404
        return render_and_response(request, 'index.html',
                                   pager(request, 'tag', id))
    elif by == 'cate':
        cate = Category.objects.get_by_id(id)
        if cate is None:
            raise Http404
        return render_and_response(request, 'index.html',
                                   pager(request, 'cate', id))
    else:
        raise Http404
Example #5
0
def shorten(req):
    """
    Generate a short url from a long url
    """
    t = 'shorten.html'
    if req.method == 'GET':
        return render_and_response(req, t)
    ori_url = req.POST.get('url')
    name = req.POST.get('name')
    if not re.search(URL_REGEX, ori_url):
        return render_and_response(req, t, {'msg': 'invalid url'})
    code = get_short_url(ori_url)
    obj = models.ShortLink.objects.get_or_create(code=code,
                                                 defaults={
                                                     'name': name,
                                                     'link': ori_url
                                                 })[0]
    return render_and_response(req, t, {'result': obj.get_short_url()})
Example #6
0
def detail(request, blog_id):
    """
    博客详情
    """
    blog = Blog.objects.get_by_id(blog_id)
    if blog is None or blog.is_draft:
        raise Http404
    init = None
    if request.user.is_superuser:
        init = {"contact": "*****@*****.**", "name": "tom kliyes"}
    return render_and_response(request, "blog/detail.html", {"blog": blog, "form": CommentForm(initial=init)})
Example #7
0
def detail(request, blog_id):
    """
    博客详情
    """
    blog = Blog.objects.get_by_id(blog_id)
    if blog is None or blog.is_draft:
        raise Http404
    init = None
    if request.user.is_superuser:
        init = {'contact': '*****@*****.**', 'name': 'tom kliyes'}
    return render_and_response(request, 'blog/detail.html', {
        'blog': blog,
        'form': CommentForm(initial=init)
    })
Example #8
0
def comment(request, blog_id):
    """
    提交评论
    """
    blog = Blog.objects.get_by_id(blog_id)
    if blog is None:
        return Http404
    form = CommentForm(request.POST)
    if request.method == "POST":
        if form.is_valid():
            cmt = form.post(blog)
            cmt.ip = get_ip(request)
            cmt.save()
            return HttpResponseRedirect("/blog/%s#cmt" % blog.id)
    return render_and_response(request, "blog/detail.html", {"blog": blog, "form": form})
Example #9
0
def comment(request, blog_id):
    """
    提交评论
    """
    blog = Blog.objects.get_by_id(blog_id)
    if blog is None:
        return Http404
    form = CommentForm(request.POST)
    if request.method == "POST":
        if form.is_valid():
            cmt = form.post(blog)
            cmt.ip = get_ip(request)
            cmt.save()
            return HttpResponseRedirect('/blog/%s#cmt' % blog.id)
    return render_and_response(request, 'blog/detail.html',
                               {'blog': blog, 'form': form})
Example #10
0
def search(request):
    """
    搜索博客
    """
    return render_and_response(request, "index.html", pager(request, "search", request.REQUEST.get("k")))
Example #11
0
def about_me(request):
    """
    关于我页面
    """
    return render_and_response(request, "about.html")
Example #12
0
def home_page(request):
    """
    博客首页
    """
    return render_and_response(request, "index.html", pager(request, "all"))
Example #13
0
def about_me(request):
    """
    关于我页面
    """
    return render_and_response(request, 'about.html')
Example #14
0
def home_page(request):
    """
    博客首页
    """
    return render_and_response(request, 'index.html', pager(request, 'all'))
Example #15
0
def catalog(req):
    return render_and_response(req, 'catalog.html')
Example #16
0
def catalog(req):
    return render_and_response(req, 'catalog.html')