Esempio n. 1
0
def picAdd(request):
    """
    ===============================================================================
    function:    图片上传(图片没有关联对象则自动删除,写个脚本处理下。)
    developer:    BeginMan
    add-time      2013/12/31
    ===============================================================================
    """
    if request.method == 'POST':
        try:
            type = request.POST.get('type', 1)
            img = request.FILES['blogPic']
            pic = Pic(type=type, ori_image=img, image=img)
            pic.save(200)
            return HttpResponse('%s:%s' % (pic.id, pic.image))    # 返回上传图片的id和路径
        except Exception, e:
            log.error('picAdd:%s' % e)
            return HttpResponse('err')
Esempio n. 2
0
File: user.py Progetto: eetif/myblog
def update_pro(request):
    """
    ===============================================================================
    function:    用户修改头像
    developer:    BeginMan
    add-time      2014/1/6
    ===============================================================================
    """
    context = {}
    from blog.form import PicForm
    user = request.user
    profiles = Profiles.objects.filter(user=user)   # 用户额外信息
    if profiles:
        profiles = profiles[0]
    else:
        return HttpResponseRedirect('/404/')

    try:
        user_portrait = "/site_media/images/user/01.png"     # 默认头像
        if request.method == 'POST':
            form = PicForm(request.POST, request.FILES)
            if form.is_valid():
                image = request.FILES['image']
                pic = Pic(type=2, image=image)
                pic.save(120)   # 用户头像120宽度
                profiles.portrait = pic.id
                profiles.save()
                user_portrait = '/upload_media/%s' %pic.image

        else:
            form = PicForm()
            if profiles.portrait:       # 头像
                portrait = Pic.objects.filter(id=profiles.portrait)
                if portrait:
                    portrait = Pic.objects.get(pk=profiles.portrait).image
                    user_portrait = '/upload_media/%s' %portrait


        context['form'] = form
        context['profiles'] = profiles
        context['portrait'] = user_portrait
    except Exception, e:
        log.error('account/index:%s' %e)
        return HttpResponse(e)
Esempio n. 3
0
def upload(request):
    """
    ===============================================================================
    function:    图片上传处理
    developer:    BeginMan
    add-time      2014/1/18
    ===============================================================================
    """
    try:
        if request.method == 'POST':
            print request.POST
            type = request.POST.get('type', 3)      # 表示相册
            img = request.FILES['photo']
            pic = Pic(type=type, ori_image=img, image=img)
            pic.save(180)
            return HttpResponse('%s:%s' % (pic.id, pic.image))    # 返回上传图片的id和路径
    except Exception, e:
        log.error(e)
        return HttpResponse(e)
Esempio n. 4
0
def edit_post(request, post_id):
    post = get_object_or_404(Post, pk=post_id)
    if request.method == "POST":
        new_post_form = PostForm(request.POST, instance=post)
        if new_post_form.is_valid():
            post = new_post_form.save(commit=False)
            post.title = new_post_form.cleaned_data['title']
            post.text = new_post_form.cleaned_data['text']
            post.mod_date = datetime.datetime.now()
            post.save()

            files1 = request.FILES.getlist('img')
            for file in files1:
                img = Pic(image=file, post_id=post_id)
                img.save()
            files2 = request.FILES.getlist('video')
            for file in files2:
                vid = Video(content=file, post_id=post_id)
                vid.save()

            return redirect(reverse('blog:post_detail', args=(post_id,)))
    else:
        new_post_form = PostForm(instance=post)
        return render(request, 'blog/blogEdit.html', {'new_post_form': new_post_form, 'post_id':post_id})
Esempio n. 5
0
def post(request, user_id):
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.text = form.cleaned_data['text']
            post.title = form.cleaned_data['title']
            post.user_id = user_id
            post.save()

            files1 = request.FILES.getlist('img')
            for file in files1:
                img = Pic(image=file, post=post)
                img.save()
            files2 = request.FILES.getlist('video')
            for file in files2:
                vid = Video(content=file, post=post)
                vid.save()
        return redirect('blog:show')

    else:
        form = PostForm()
        user = User.objects.get(id=user_id)
        return render(request, 'blog/blogEdit.html', {'user':user, 'form': form})