Exemplo n.º 1
0
def upload_file(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            handle_uploaded_file(request.FILES['file'])
           #return HttpResponseRedirect('successs/success.html'/)
	    return HttpResponseRedirect('/success/url/')
    else:
        form = UploadFileForm()
    return render_to_response('index.html', {'form': form},RequestContext(request))
Exemplo n.º 2
0
def file_share(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            result = handle_uploaded_file(request.FILES['file'])
            if result:
                try:
                    file = File.objects.get(sha512=result['sha512'], user=request.user)
                    messages.error(request, 'You have already reported this file')
                    return HttpResponseRedirect('/file/%s' % file.id)
                except ObjectDoesNotExist:
                    file = form.save(commit=False)
                    file.uuid = uuid.uuid4().urn
                    file.user = request.user
                    file.filename = result['filename']
                    file.filesize = result['filesize']
                    file.md5 = result['md5']
                    file.sha1 = result['sha1']
                    file.sha256 = result['sha256']
                    file.sha512 = result['sha512']
                    file.save()
                    form.save_m2m()
                    for n in request.POST.getlist('nodes'):
                        node = PubSubNode.objects.get(node=int(n))
                        file.nodes.add(node)
                        xmpp.publish(node=node.node, payload=file.activity_fordrop_file())
                        if file.tags.all():
                            xmpp.publish(node.node, payload=file.activity_tags())

                    print json.dumps(file.activity_fordrop_file(), indent=4)
                    messages.success(request, "Sharing is caring, file successfully recieved!")
                    mail_body = '%s reported the same file as you, %s\n%s' % (file.user.profile.name, file.sha1, file.get_full_uri())
                    notify_by_mail(users=file.get_reporters(), subject='%s reported the same file as you' % file.user.profile.name, body=mail_body, obj=file)
    return HttpResponseRedirect('/file/%s' % file.id)
Exemplo n.º 3
0
def ProjectApply(request):
    user = request.user
    if not request.user.is_authenticated():
        return render_to_response('redirect.html',RenderContext(request))
    if request.method == 'POST':
        try:
            if request.POST['logout']:
                logout(request)
                return HttpResponseRedirect('/')
        except:
            projectDict={}
            projectDict['project_name'] = request.POST['project_name']
            projectDict['project_department'] = request.POST['project_department']#思科信息学院
            projectDict['batch'] = request.POST['batch'] #2012,2013,2014,2015
            projectDict['project_variety'] = request.POST['variety']  #创新实验项目 ,创新训练项目
            projectDict['project_type'] = request.POST['type'] #文科
            projectDict['project_year'] = request.POST['year'] #1 year ,2year
            projectDict['project_id'] = request.POST['project_id']
            projectDict['project_file'] = request.FILES['fileField']

            projectDict['s1_name'] = request.POST['s1_name']
            projectDict['s1_department'] =request.POST['s1_department']
            projectDict['s1_id'] = request.POST['s1_id']
            projectDict['s1_grade'] = request.POST['s1_grade']
            filedir = u'申报待审核/'
            projectDict['filepath']=handle_uploaded_file(projectDict['project_file'],request.FILES['fileField'].name,projectDict['project_department'],projectDict['s1_id'],filedir)

            projectDict['t1_name'] = request.POST['t1_name']
            projectDict['t1_department'] = request.POST['t1_department']
            projectDict['t1_title'] = request.POST['t1_title']
            projectDict['t1_id'] = request.POST['t1_id']

            projectDict['t2_name'] = request.POST['t2_name']
            projectDict['t2_department'] = request.POST['t2_department']
            projectDict['t2_title'] = request.POST['t2_title']
            projectDict['t2_id'] = request.POST['t2_id']

            projectDict['s2_name'] = request.POST['s2_name']
            projectDict['s2_department'] =request.POST['s2_department']
            projectDict['s2_id'] = request.POST['s2_id']
            projectDict['s2_grade'] = request.POST['s2_grade']

            projectDict['s3_name'] = request.POST['s3_name']
            projectDict['s3_department'] =request.POST['s3_department']
            projectDict['s3_id'] = request.POST['s3_id']
            projectDict['s3_grade'] = request.POST['s3_grade']

            projectDict['s4_name'] = request.POST['s4_name']
            projectDict['s4_department'] =request.POST['s4_department']
            projectDict['s4_id'] = request.POST['s4_id']
            projectDict['s4_grade'] = request.POST['s4_grade']

            projectDict['s5_name'] = request.POST['s5_name']
            projectDict['s5_department'] =request.POST['s5_department']
            projectDict['s5_id'] = request.POST['s5_id']
            projectDict['s5_grade'] = request.POST['s5_grade']
            #
            projectDict['project_key1'] = request.POST['project_key1']
            projectDict['project_key2'] = request.POST['project_key2']
            projectDict['project_key3'] = request.POST['project_key3']
            projectDict['project_info'] = request.POST['project_info']
            projectDict['pro_status']=u'申报待审核'

            dll = DllprojectApply()
            if dll.ProjectApply(projectDict):
                message = 'apply success!!'
                return render_to_response('confure.html',{'message':message})
            return render_to_response('ProjectApply.html',{'user':user})
    return render_to_response('ProjectApply.html',{'user':user})