Exemple #1
0
def create_bbs(request):

    if request.method == 'GET':

        return  render(request,'create_bbs.html')
        #return render_to_response()
    elif request.method == 'POST':
        print request.POST,request.FILES

        #obj = models.BBS.objects.create() no return
        obj = models.BBS(
            title = request.POST.get('title'),
            content = request.POST.get('content'),
            category_id = 1,
            author_id = 1,

        )

        obj.save()

        #save file
        filename = utils.handle_upload_file(request,request.FILES["head_image"])
        obj.head_img = 'upload/%s' %filename
        obj.save()
        print obj.id

        return render(request,'create_bbs.html',{
            'new_article': obj
        })
Exemple #2
0
def create_bbs(request):

    if request.method == 'GET':

        return render(request, 'create_bbs.html')
        #return render_to_response()
    elif request.method == 'POST':
        print request.POST, request.FILES

        #obj = models.BBS.objects.create() no return
        obj = models.BBS(
            title=request.POST.get('title'),
            content=request.POST.get('content'),
            category_id=1,
            author_id=1,
        )

        obj.save()

        #save file
        filename = utils.handle_upload_file(request,
                                            request.FILES["head_image"])
        obj.head_img = 'upload/%s' % filename
        obj.save()
        print obj.id

        return render(request, 'create_bbs.html', {'new_article': obj})
Exemple #3
0
def multitask_file_upload(request):
    filename = request.FILES['filename']
    print '-->',request.POST
    file_path = utils.handle_upload_file(request,filename)

    return HttpResponse(json.dumps({'uploaded_file_path':file_path,
                                    'text':'success'}))
Exemple #4
0
def volunteer_apply(request, user_id):
    # before register volunteer, the user must be the system's user
    template_name = "volunteer/apply_volunteer.html"
    data = {}
    if request.method == "GET":
        volunteer_model = Volunteer.objects.filter(user_id=user_id)
        if volunteer_model:
            data["volunteer_form"] = VolunteerForm(instance=volunteer_model[0])
        else:
            data["volunteer_form"] = VolunteerForm()
        return render_to_response(template_name,
                                  data,
                                  context_instance=RequestContext(request))
    else:  # POST
        volunteer_form = VolunteerForm(request.POST, request.FILES)
        if volunteer_form.is_valid():
            volunteer_model = Volunteer.objects.filter(user_id=user_id)
            if len(volunteer_model) > 0:
                data["message"] = "您的申请已修改。请等待管理员联系。 谢谢您的参与!"
                volunteer_model = VolunteerForm(
                    instance=volunteer_model[0]).save(commit=False)
            else:
                data["message"] = "您的申请已递交,请等待管理员联系。 谢谢您的参与!"
                volunteer_model = volunteer_form.save(commit=False)

            if volunteer_form.cleaned_data.get("headshot"):
                utils.handle_upload_file(request.FILES["headshot"],
                                         "hs_" + user_id + ".jpeg",
                                         MEDIA_ROOT + '/headshot/')
                volunteer_model.headshot = "/media/headshot/" + "hs_" + user_id + ".jpeg"
            volunteer_model.free_time = request.POST.get("free_time")
            volunteer_model.user_id = user_id
            volunteer_model.status = '10'
            volunteer_model.volunteer_type = '01'

            volunteer_model.save()
            data["volunteer_form"] = volunteer_form

        else:
            data["volunteer_form"] = volunteer_form

        return render_to_response(template_name,
                                  data,
                                  context_instance=RequestContext(request))
Exemple #5
0
def volunteer_apply(request, user_id):
    # before register volunteer, the user must be the system's user
    template_name = "volunteer/apply_volunteer.html"
    data = {}
    if request.method == "GET":
        volunteer_model = Volunteer.objects.filter(user_id=user_id)
        if volunteer_model:
            data["volunteer_form"] = VolunteerForm(instance=volunteer_model[0])
        else:
            data["volunteer_form"] = VolunteerForm()
        return render_to_response(template_name, data,
                                  context_instance=RequestContext(request))
    else:  # POST
        volunteer_form = VolunteerForm(request.POST, request.FILES)
        if volunteer_form.is_valid():
            volunteer_model = Volunteer.objects.filter(user_id=user_id)
            if len(volunteer_model) > 0:
                data["message"] = "您的申请已修改。请等待管理员联系。 谢谢您的参与!"
                volunteer_model = VolunteerForm(instance=volunteer_model[0]).save(commit=False)
            else:
                data["message"] = "您的申请已递交,请等待管理员联系。 谢谢您的参与!"
                volunteer_model = volunteer_form.save(commit=False)

            if volunteer_form.cleaned_data.get("headshot"):
                utils.handle_upload_file(request.FILES["headshot"], "hs_" + user_id + ".jpeg", MEDIA_ROOT + '/headshot/')
                volunteer_model.headshot = "/media/headshot/" + "hs_" + user_id + ".jpeg"
            volunteer_model.free_time = request.POST.get("free_time")
            volunteer_model.user_id = user_id
            volunteer_model.status = '10'
            volunteer_model.volunteer_type = '01'

            volunteer_model.save()
            data["volunteer_form"] = volunteer_form

        else:
            data["volunteer_form"] = volunteer_form

        return render_to_response(template_name, data, context_instance=RequestContext(request))
Exemple #6
0
def file_upload(request):
    filename = request.FILES['filename']  #传文件从files取
    print '-->',request.POST
    file_path =utils.handle_upload_file(request,filename)

    return HttpResponse(json.dumps({'uploaded_file_path':file_path}))  #将这个字典传到后端,作为前端的全局变量先存储下来
Exemple #7
0
def multitask_file_upload(request):
    filename = request.FILES["filename"]
    print "-->", request.POST
    utils.handle_upload_file(request, filename)

    return HttpResponse(json.dumps({"text": "success"}))
Exemple #8
0
def file_upload(request):
    filename = request.FILES['file']
    file_path =utils.handle_upload_file(request,filename)
    # return HttpResponse(json.dumps({'uploaded_file_path':file_path}))
    return HttpResponse(file_path)
Exemple #9
0
def multitask_file_upload(request):
    filename = request.FILES['filename']
    print '-->',request.POST
    utils.handle_upload_file(request,filename)

    return HttpResponse(json.dumps({'text':'success'}))
Exemple #10
0
def file_upload(request):
    filename = request.FILES.get("filename")
    print "--->",request.POST,"--->",filename,"---->",filename.name
    file_path = utils.handle_upload_file(request,filename)

    return HttpResponse(json.dumps({"uploaded_file_path":file_path}))