Exemple #1
0
def configuration_upload(request):
    if request.method == 'POST':
        # script= request.POST.get('script')
        # print type(script)
        print request
        myFile = request.FILES.get('script', None)
        name = request.POST.get('name')
        describe = request.POST.get('describe')
        print name, describe
        if name:
            save_name = name
        else:
            save_name = myFile
        # print(myFile._size)  # 文件大小字节数
        if Configuration.objects.filter(configuration_name=myFile).exists():
            return render_to_response('400.html', {'info': '脚本已经存在'})
        data = myFile.read()
        job_obj = Configuration()

        job_obj.configuration_name = save_name
        job_obj.info = data
        job_obj.describe = describe
        job_obj.save()
        return render_to_response('configuration_upload.html',
                                  {'username': request.user.username})

    else:

        return render_to_response('configuration_upload.html',
                                  {'username': request.user.username})
Exemple #2
0
    def upload_configuration(self, request):
        if request.GET.get('source') == 'master':
            data = request.DATA
            myFile = request.FILES.get('script', None)

            name = data.get('name')
            describe = data.get('describe')

            if name:
                save_name = name
            else:
                save_name = myFile.name
            # print(myFile._size)  # 文件大小字节数
            if Configuration.objects.filter(
                    configuration_name=save_name).exists():
                return Response('脚本已经存在', status=status.HTTP_400_BAD_REQUEST)
            data = myFile.read()
            job_obj = Configuration()

            job_obj.configuration_name = save_name
            job_obj.info = data
            job_obj.describe = describe
            job_obj.save()
            return Response("success", status=status.HTTP_200_OK)