Example #1
0
def tag(request, id=None):
    """
    ===============================================================================
    function:    博客搜索
    developer:    BeginMan
    add-time      2014/1/7
    ===============================================================================
    """
    context = {}
    if request.method == "GET":
        if not id:
            return HttpResponseRedirect('/404/')
        tag = Tags.objects.get(pk=id)
        tag_name = tag.name
        b_list = []
        blogList = Blog.objects.filter(status=1).order_by('-add_time')
        for obj in blogList.extra(where=['length(tags)>0']):        # 获取标签不为空的
            if tag_name in [i for i in obj.tags.split('|') if i]:        # 如果该标签在其中则填充
                b_list.append(obj)

        page = request.GET.get('page', None)
        result = get_page_result(page, b_list, 20)
        context['result'] = result
        context['tag_name'] = tag_name
        context['num'] = len(b_list)

        blog_list = []
        for obj in result.object_list:
            dict = {}
            dict['blog'] = obj
            dict['category'] = obj.category_id
            dict['tags'] = [i for i in obj.tags.split('|') if i]
            blog_list.append(dict)
        context['blog_list'] = blog_list
    return render_template(request, 'blog/tag.html', context)
Example #2
0
def list(request):
    """
    ===============================================================================
    function:    博客列表
    developer:    BeginMan
    add-time      2014/1/8
    ===============================================================================
    """
    context = {}
    if request.method == "POST":
        blog = Blog.objects.filter(status=1, istop=0).order_by('-add_time')
        page = request.POST.get('page')
        # 最新博客(12个一分页)

        new_blogs = get_page_result(page, blog, 12)

        blog_list = []
        for obj in new_blogs.object_list:
            dict = {}
            dict['blog'] = obj
            dict['category'] = obj.category_id
            dict['tags'] = [i for i in obj.tags.split('|') if i]
            blog_list.append(dict)
        context['blog_list'] = blog_list
        context['new_blogs'] = new_blogs
    return render_template(request, 'blog/list.html', context)
Example #3
0
def blog_manage(request):
    """
    ===============================================================================
    function:    博客管理
    developer:    BeginMan
    add-time      2014/1/2
    ===============================================================================
    """
    context = {}
    try:
        tag = Tags.objects.order_by('-add_time')
        category_num = tag.aggregate(Sum('count'))
        category = Category.objects.order_by('sequence')
        p_cates = category.filter(parent_id=0)
        c_list = []
        for obj in p_cates:
            dic = {}
            dic['parent'] = obj
            dic['child'] = category.filter(parent_id=obj.id)
            c_list.append(dic)

        context['c_list'] = c_list
        context['category_num'] = category_num
        context['tag'] = tag
        return render_template(request, 'manager/blog/blog.html', context)
    except Exception ,e:
        log.error('blogManager:%s' %e)
        return HttpResponse('err')
Example #4
0
def category(request, id=None):
    """
    ===============================================================================
    function:    博客搜索
    developer:    BeginMan
    add-time      2014/1/7
    ===============================================================================
    """
    context = {}
    if request.method == "GET":
        if not id:
            return HttpResponseRedirect('/404/')
        category = Category.objects.get(pk=id)
        blogs = Blog.objects.filter(category_id__id=id, status=1).order_by('-add_time')
        page = request.GET.get('page', None)
        result = get_page_result(page, blogs, 20)
        context['result'] = result
        context['category_title'] = category.title
        context['num'] = len(blogs)

        blog_list = []
        for obj in result.object_list:
            dict = {}
            dict['blog'] = obj
            dict['category'] = obj.category_id
            dict['tags'] = [i for i in obj.tags.split('|') if i]
            blog_list.append(dict)
        context['blog_list'] = blog_list
    return render_template(request, 'blog/category.html', context)
Example #5
0
def get_tags(request):
    """
    ===============================================================================
    function:            获取标签
    developer:    BeginMan
    add-time      2013/12/28 
    ===============================================================================
    """
    context = {}
    tag_list = Tags.objects.all().order_by('-add_time')
    context['tag_list'] = tag_list
    return render_template(request, 'manager/blog/get_tags.html', context)
Example #6
0
File: user.py Project: eetif/myblog
def update_pwd(request):
    """
    ===============================================================================
    function:    用户修改密码
    developer:    BeginMan
    add-time      2014/1/6
    ===============================================================================
    """
    context = {}
    user = request.user
    if request.method == 'POST':
        form = PasswordForm(user, request.POST)     # 参数位置不能出错
        if form.is_valid():
            pwd = form.cleaned_data['password1']
            user.set_password(pwd)
            return HttpResponseRedirect('/account/user/%s/' % user.id)
    else:
        form = PasswordForm()
    context['form'] = form
    return render_template(request, 'manager/user/pwd.html', context)
Example #7
0
File: user.py Project: eetif/myblog
def update_nickname(request):
    """
    ===============================================================================
    function:    用户修改昵称
    developer:    BeginMan
    add-time      2014/1/6
    ===============================================================================
    """
    context ={}
    user = request.user
    if request.method == 'POST':
        nickname = request.POST.get('nickname')
        if nickname:
            if User.objects.filter(nickname=nickname).exists():
                return HttpResponse(0)
            else:
                user.nickname = nickname
                user.save()
                return HttpResponse(1)
    return render_template(request, 'manager/user/nickname.html', context)
Example #8
0
def index(request):
    """
    ===============================================================================
    function:    图册首页
    developer:    BeginMan
    add-time      2014/1/8
    ===============================================================================
    """
    context = {}
    try:
        photo_cates = PhotoCategory.objects.order_by('sequence')
        context['photo_cates'] = photo_cates
    except Exception, e:
        log.error('photo>index:%s' %e)
        return HttpResponse(e)
    return render_template(request, 'photo/index.html', context)

def create(request, id=None):
    """
    ===============================================================================
    function:    相册分类创建
    developer:    BeginMan
    add-time      2014/1/17
    ===============================================================================
    """
    context = {}
    try:
        p_cate = None       # 分类实例
        if id and id != '0':
            p_cate = PhotoCategory.objects.get(id=id)
        if request.method == 'POST':
Example #9
0
    ===============================================================================
    function:    博客列表
    developer:    BeginMan
    add-time      2014/1/3
    ===============================================================================
    """
    context = {}
    try:
        # 推荐博客
        topBlog = Blog.objects.filter(status=1, istop=1).order_by('-add_time').values('id', 'title', 'add_time')
        context['topBlog'] = topBlog

    except Exception, e:
        log.error('blog>index:%s' %e)
        return HttpResponse(e)
    return render_template(request, 'blog/index.html', context)


def list(request):
    """
    ===============================================================================
    function:    博客列表
    developer:    BeginMan
    add-time      2014/1/8
    ===============================================================================
    """
    context = {}
    if request.method == "POST":
        blog = Blog.objects.filter(status=1, istop=0).order_by('-add_time')
        page = request.POST.get('page')
        # 最新博客(12个一分页)
Example #10
0
def manager_list(request):
    """
    ===============================================================================
    function:    博客列表
    developer:    BeginMan
    add-time      2014/1/14
    ===============================================================================
    """
    try:
        context = {}
        if request.method == "POST":
            categoryId = request.POST.get("categoryId")  # 分类
            date1 = request.POST.get("date1")  # 日期1
            date2 = request.POST.get("date2")  # 日期2
            is_top = request.POST.get("is_top")  # 是否置顶 2全部 1置顶;0不置顶
            status = request.POST.get("status")  # 状态 2全部;1分布;0草稿
            title = request.POST.get("title")  # 搜索的标题

            transList = Translate.objects.filter(status__lt=2).order_by("-add_time")
            if categoryId != "0":
                if TransCategory.objects.get(pk=categoryId).parent_id == 0:  # 父分类
                    c_id_list = list(TransCategory.objects.filter(parent_id=categoryId).values_list("id", flat=True))
                    c_id_list.append(int(categoryId))
                    transList = Translate.objects.filter(category__id__in=c_id_list, status__lt=2)
                else:
                    transList = Translate.objects.filter(category__id=categoryId, status__lt=2)

            if is_top != "2":
                transList = transList.filter(istop=is_top)

            if status != "2":
                transList = transList.filter(status=status)
            if title:
                transList = transList.filter(title__icontains=title)  # icontains 不区分大小写

            # 日期
            start = datetime.date(2013, 1, 1)  # 起始时间
            if date1 and date2:
                split_date1 = date1.split("-")
                split_date2 = date2.split("-")
                d_date1 = datetime.date(int(split_date1[0]), int(split_date1[1]), int(split_date1[2]))
                d_date2 = datetime.date(int(split_date2[0]), int(split_date2[1]), int(split_date2[2]))
                transList = transList.filter(add_time__range=(d_date1, d_date2))
            else:
                if date1:
                    split_date1 = date1.split("-")
                    d_date1 = datetime.date(int(split_date1[0]), int(split_date1[1]), int(split_date1[2]))
                    transList = transList.filter(add_time__range=(start, d_date1))

                if date2:
                    split_date2 = date2.split("-")
                    d_date2 = datetime.date(int(split_date2[0]), int(split_date2[1]), int(split_date2[2]))
                    transList = transList.filter(add_time__range=(start, d_date2))

            page = request.POST.get("page", "1")
            trans = get_page_result(page, transList, 20)
            context["trans"] = trans
            return render_template(request, "translate/manager_list.html", context)

    except Exception, e:
        log.error("translate/manager_list:%s" % e)
        return HttpResponse("err")
Example #11
0
File: user.py Project: eetif/myblog
            form = LoginForm(request, request.POST)
            if form.is_valid():
                user = form.get_user()  # 获取用户实例
                login(request, user)
                if user.is_superuser:   # 管理员跳转到管理页面
                    return HttpResponseRedirect('/manager/')
                else:                   # 非管理员跳转首页
                    return HttpResponseRedirect('.')

        else:
            form = LoginForm(error_class=DivErrorList)
        context['form'] = form
    except Exception, e:
        log.error('account>index:%s' %e)
        return HttpResponse(e)
    return render_template(request, 'account/login.html', context)

def logut(request):
    """退出"""
    logout_(request)
    return HttpResponseRedirect('/')

def register(request):
    """
    ===============================================================================
    function:    申请注册
    developer:    BeginMan
    add-time      2014/1/4
    ===============================================================================
    """
    context = {}
Example #12
0
def demo(request, demo=None):
    """练兵场"""
    context = {}
    return render_template(request, 'demo/%s' % demo, context)
Example #13
0
        for obj in newBlog:
            dict = {}
            dict['blog'] = obj
            dict['category'] = obj.category_id
            dict['tags'] = [i for i in obj.tags.split('|') if i]
            picUrl = '/upload_media/blog/love/default.jpg/'       # 缩略图
            if obj.pic:
                pic = Pic.objects.filter(id=obj.pic)
                if pic:
                    pic = Pic.objects.get(pk=obj.pic)
                    if pic.image:
                        picUrl = '/upload_media/%s' %pic.image

            dict['picUrl'] = picUrl
            blog_list.append(dict)
        context['blog_list'] = blog_list
        # 轮播展示
        c = Carousel.objects.all()
        carousels = Carousel.objects.filter(status=1).order_by('sequence')[:4]

        context['carousels'] = carousels
    except Exception, e:
        log.error('index:%s' % e)
    return render_template(request, 'index.html', context)
    

def demo(request, demo=None):
    """练兵场"""
    context = {}
    return render_template(request, 'demo/%s' % demo, context)
Example #14
0
def blog_list(request):
    """
    ===============================================================================
    function:    博客列表
    developer:    BeginMan
    add-time      2014/1/2
    ===============================================================================
    """
    try:
        context = {}
        if request.method == 'POST':
            categoryId = request.POST.get('categoryId')             # 分类
            cmms = request.POST.get('cmms')                         # 是否允许评论,2全部;1允许;0不允许
            date1 = request.POST.get('date1')                       # 日期1
            date2 = request.POST.get('date2')                       # 日期2
            is_top = request.POST.get('is_top')                  # 是否置顶 2全部 1置顶;0不置顶
            pwds = request.POST.get('pwds')                         # 密码,0全部;1正常;2加密
            status = request.POST.get('status')                     # 状态 2全部;1分布;0草稿
            tag = request.POST.get('tag')                           # 获取标签名称
            title = request.POST.get('title')                       # 搜索的标题


            blogList = Blog.objects.filter(status__lt=2).order_by('-add_time')

            if categoryId != '0':
                if Category.objects.get(pk=categoryId).parent_id == 0:     # 父分类
                    c_id_list = list(Category.objects.filter(parent_id=categoryId).values_list('id', flat=True))
                    c_id_list.append(int(categoryId))
                    blogList = blogList.filter(category_id__id__in=c_id_list, status__lt=2)
                else:
                    blogList = blogList.filter(category_id__id__in=categoryId, status__lt=2)

            if cmms != '2':
                blogList = blogList.filter(cancomment=cmms)
            if is_top != '2':
                blogList = blogList.filter(istop=is_top)
            if pwds == '2':
                blogList = blogList.filter(password__isnull=True)
            if pwds == '1':
                blogList = blogList.filter(password__isnull=False)
            if status != '2':
                blogList = blogList.filter(status=status)
            if title:
                blogList = blogList.filter(title__icontains=title)      # icontains 不区分大小写
            # 标签处理可能有些麻烦
            if tag != u'全部':
                b_list = []
                for obj in blogList.extra(where=['length(tags)>0']):        # 获取标签不为空的
                    if tag in [i for i in obj.tags.split('|') if i]:        # 如果该标签在其中则填充
                        b_list.append(obj)
                blogList = b_list

            # 日期
            start = datetime.date(2013, 1, 1)       # 起始时间
            if date1 and date2:
                split_date1 = date1.split('-')
                split_date2 = date2.split('-')
                d_date1 = datetime.date(int(split_date1[0]), int(split_date1[1]), int(split_date1[2]))
                d_date2 = datetime.date(int(split_date2[0]), int(split_date2[1]), int(split_date2[2]))
                blogList = blogList.filter(add_time__range=(d_date1, d_date2))
            else:
                if date1:
                    split_date1 = date1.split('-')
                    d_date1 = datetime.date(int(split_date1[0]), int(split_date1[1]), int(split_date1[2]))
                    blogList = blogList.filter(add_time__range=(start, d_date1))

                if date2:
                    split_date2 = date2.split('-')
                    d_date2 = datetime.date(int(split_date2[0]), int(split_date2[1]), int(split_date2[2]))
                    blogList = blogList.filter(add_time__range=(start, d_date2))

            try:
                page = request.POST.get('page', '1')
            except ValueError:      # Make sure page request is an int. If not, deliver first page.
                page = 1
            paginator = MyPaginator(blogList, 15)     # 15个一分页

            try:
                blog = paginator.page(page)
            except (EmptyPage, InvalidPage):    # # If page request (9999) is out of range, deliver last page of results
                blog = paginator.page(paginator.num_pages)
            context['blog'] = blog
            return render_template(request, 'manager/blog/blog_list.html', context)

    except Exception, e:
        log.error('blog_list:%s' %e)
        return HttpResponse('err')
Example #15
0
                        return HttpResponse('0')   
                # create
                if p_id:
                    
                    Category.objects.create(parent_id=p_id, title=title, des=des, sequence=sequence)
                else:
                    Category.objects.create(title=title, des=des, sequence=sequence)
            else:           # 编辑
                category = Category.objects.filter(id=type).update(title=title, des=des, sequence=sequence)
            return HttpResponse(1)
        except Exception,e:
            log.error('categroy:%s' % e)
            return HttpResponse(e)
    context['p_categroes'] = p_categroes
    context['categroy_list'] = categroy_list
    return render_template(request, 'manager/blog/categroy.html', context)



@user_passes_test(lambda u: u.is_superuser, login_url='/commons/prem_tip/1/')   # 只有管理员才能进
def categroy_delete(request):
    """
    ===============================================================================
    function:            分类删除
    developer:    BeginMan
    add-time      2013/12/28 
    ===============================================================================
    """
    try:
        if request.method == 'POST':
            id = request.POST.get('id')
Example #16
0
log = logging.getLogger(__name__)
from django.contrib.auth.decorators import login_required, user_passes_test, permission_required

@user_passes_test(lambda u: u.is_superuser, login_url='/commons/prem_tip/1/')   # 只有管理员才能进
@csrf_protect
def carousel(request):
    """
    ===============================================================================
    function:            轮播管理
    developer:    BeginMan
    add-time      2013/12/29 
    ===============================================================================
    """
    context = {}
    try:
        if request.method == "POST":
            form = AddCarousel(request.POST, request.FILES)
            if form.is_valid():
                form.save()     # 保存
                return HttpResponseRedirect('/')
                
        else:
             form = AddCarousel()
                    
        context['form'] = form
    except Exception, e:
        log.error('carousel:%s' % e)
        return HttpResponse('err')
    return render_template(request,'manager/system/carousel.html',context)
Example #17
0
#coding=utf-8
import datetime
from django.http import HttpResponse, HttpResponseRedirect
from commons.common import render_template
from blog.models import Category,Tags
from django.contrib.auth.decorators import login_required, user_passes_test, permission_required

@user_passes_test(lambda u: u.is_superuser, login_url='/commons/prem_tip/1/')   # 只有管理员才能进
def index(request):
    """后台管理首页"""
    try:
        pass
    except Exception, e:
        return HttpResponse(e)
    return render_template(request, 'manager/index.html')
Example #18
0
def index(request):
    """
    ===============================================================================
    function:    翻译首页
    developer:    BeginMan
    add-time      2014/1/8
    ===============================================================================
    """
    context = {}
    try:
        t_category = TransCategory.objects.filter(parent_id=0, status=1).order_by("sequence", "-add_time")
        context["t_category"] = t_category
    except Exception, e:
        log.error("translatate/index:%s" % e)
        return HttpResponse(e)
    return render_template(request, "translate/index.html", context)


def add_category(request):
    """
    ===============================================================================
    function:    创建分类
    developer:    BeginMan
    add-time      2014/1/13
    ===============================================================================
    """
    try:
        if request.method == "POST":
            title = request.POST.get("title", None)
            summary = request.POST.get("summary", None)
            sequence = request.POST.get("sequence", 1)