当前位置: 首页>>代码示例>>Python>>正文


Python UploadFileForm.is_valid方法代码示例

本文整理汇总了Python中forms.UploadFileForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python UploadFileForm.is_valid方法的具体用法?Python UploadFileForm.is_valid怎么用?Python UploadFileForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.UploadFileForm的用法示例。


在下文中一共展示了UploadFileForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload_file

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def upload_file(request):
    file_types=""
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid() and request.POST['1'] == 'xml':
            if '.xml' in request.FILES['file'].name:
                 form = UploadFileForm()
                 file_types = "input and output files have same type, please chose different type:"
            else:
                link = uploaded_file_toxml(request.FILES['file'])
                return HttpResponseRedirect('/'+link+'.xml/')
        if form.is_valid() and request.POST['1'] == 'json':
            if '.json' in request.FILES['file'].name:
                form = UploadFileForm()
                file_types = "input and output files have same type, please chose different type:"
            else:
                link = uploaded_file_tojson(request.FILES['file'])
                return HttpResponseRedirect('/'+link+'.json/')
        if form.is_valid() and request.POST['1'] == 'csv':
            if '.csv' in request.FILES['file'].name:
                form = UploadFileForm()
                file_types = "input and output files have same type, please chose different type:"
            else:
                link = uploaded_file_tocsv(request.FILES['file'])
                return HttpResponseRedirect('/'+link+'.csv/')
    else:
        form = UploadFileForm()
    return render_to_response('converter.html', {'form': form , 'type': file_types})
开发者ID:SADJUK,项目名称:firstproj,代码行数:30,代码来源:views.py

示例2: upload_file

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def upload_file(request):
    if request.method == 'POST':
        print "UNUTRA"
        form = UploadFileForm(request.POST, request.FILES)
        print form.is_valid()
        if form.is_valid():
            handle_uploaded_file(VideoObject.path, request.FILES['file'])
            return HttpResponse('yay')
    else:
        print "U GETU SAM"
        form = UploadFileForm()
    return HttpResponse("nesto se desilo")
开发者ID:Vizualni,项目名称:hometv,代码行数:14,代码来源:views.py

示例3: upload

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def upload(request):
	userid = request.session['_auth_user_id']
	form = UploadFileForm(request.POST)
	form.is_valid()
	game = Game.objects.get(brand=form.cleaned_data['game'])
	date_to_draw = form.cleaned_data['lottery_date']
	player = Player.objects.get(user=userid)
	image = request.FILES['image']
	ticket = LotteryTicket(
			player = player,
			lottery_image = image,
			game = game,
			lottery_date = date_to_draw)
	ticket.save()
	return render_to_response('editTicket.html', {'image': ticket.lottery_image, 'ticketId': ticket.id}, context_instance=RequestContext(request))
开发者ID:alfredozhou,项目名称:lottery,代码行数:17,代码来源:ticketupload.py

示例4: upload

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def upload(request):
    c = all_page_infos(request)
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            ufile = request.FILES['file']
            short = request.POST['short']
            long_text = request.POST['long_text']
            tags = request.POST['tags']
            (path, written_bytes) = save_uploaded_file(ufile)
            logger.info("User '%s' uploaded file '%s' with title '%s', parsing it now.", request.user, os.path.basename(path), short[:20])
#            try:
            if written_bytes != ufile.size:
                return HttpResponse("Could not store the replay file. Please contact the administrator.")

            demofile = parse_demo_file.Parse_demo_file(path)
            demofile.check_magic()
            demofile.parse()

            try:
                replay = Replay.objects.get(gameID=demofile.header["gameID"])
                logger.info("Replay already existed: pk=%d gameID=%s", replay.pk, replay.gameID)
                return HttpResponse('Uploaded replay already exists: <a href="/replay/%s/">%s</a>'%(replay.gameID, replay.__unicode__()))
            except:
                shutil.move(path, settings.MEDIA_ROOT)
                replay = store_demofile_data(demofile, tags, settings.MEDIA_ROOT+os.path.basename(path), file.name, short, long_text, request.user)
                logger.info("New replay created: pk=%d gameID=%s", replay.pk, replay.gameID)
            return HttpResponseRedirect(replay.get_absolute_url())
#            except Exception, e:
#                return HttpResponse("The was a problem with the upload: %s<br/>Please retry or contact the administrator.<br/><br/><a href="/">Home</a>"%e)
    else:
        form = UploadFileForm()
    c['form'] = form
    return render_to_response('upload.html', c, context_instance=RequestContext(request))
开发者ID:abma,项目名称:spring-replay-site,代码行数:36,代码来源:upload.py

示例5: cloud_storage

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def cloud_storage(request):

	print '-- cloud_storage:'

	if not request.user.is_authenticated():
		return HttpResponseRedirect("/")

	user = request.user
	profile = userprofile.objects.get(user=request.user)
	secret = profile.secret

	print request.user

	if request.method == 'POST':
		form = UploadFileForm(request.POST, request.FILES)
		if form.is_valid():
			new_file = Files(file=request.FILES['file'])
			new_file.save()
			Uploaded_Files.objects.create(file=new_file,user=request.user)
  
	uploaded_files = Uploaded_Files.objects.filter(user=request.user).order_by('-pk')
	cloud_storage_menu_open = True

	# XXX batch sync files to the S3.....
	
	return render_to_response('cloud_storage.html', {'cloud_storage_menu_open':cloud_storage_menu_open,'uploaded_files':uploaded_files,'user':user,'profile':profile,}, context_instance=RequestContext(request))
开发者ID:mecirt,项目名称:cloudly,代码行数:28,代码来源:views.py

示例6: api_upload

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def api_upload(request):
    if request.method == 'POST':
        picture = Picture()
        user = User.objects.get(email=request.POST['email'])
        picture.user = user
        form = UploadFileForm(request.POST, request.FILES, instance=picture)
        if form.is_valid():
            picture.picture = request.FILES['picture']
            if request.POST.has_key('gallery_id'):
                gallery = Gallery.objects.get(id=request.POST['gallery_id'], user=user)
                picture.gallery = gallery

            picture.picture.name = unidecode(picture.picture.name)
            picture.save()
            rotate_picture(picture)
            picture.update_thumb()

            if request.POST.has_key('description'):
                picture_description = PictureDescription(picture=picture)
                picture_description.text = request.POST['description']
                picture_description.save()  

            response = {'status':'OK'}
            response['data'] = serialize_picture(picture)
            return HttpResponse(json.dumps(response))

    return HttpResponse(content_200)
开发者ID:PicUpIt,项目名称:picup-it,代码行数:29,代码来源:api_views.py

示例7: main

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def main(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/',RequestContext(request))

    path = '{}/media/files'.format(os.getcwd())
    file_list = list(os.listdir(path))

    form_1 = UploadFileForm()
    form_2 = UploadDocForm()

    if request.method == 'POST':
        form_1 = UploadFileForm(request.POST, request.FILES)

        if form_1.is_valid():
            new_file = UploadFile(file=request.FILES['file'])
            new_file.save()
            filename = request.FILES['file'].name
            #handle_uploaded_file(request.FILES['file'])
            data = {'name':filename}
            return HttpResponse('Form_1 post file and form is_valid')
    else:
        form_1 = UploadFileForm()


    data = {'form_1': form_1, 'file_list':file_list }
    return render(request,'vedio_parser/vedio_parser_main.html', data)
开发者ID:KentChun33333,项目名称:Django-AE,代码行数:28,代码来源:video_parser_view.py

示例8: upload_customer_report

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def upload_customer_report(request):
    result = ""

    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if (form.is_valid()):
            upload_file = request.FILES['upload_file']
            filename = upload_file.name
            store_path = os.path.join(config.WORKING_DIR, filename)
            store_file = open(store_path, "wb")

            #upload_file.read()
            for content in upload_file.chunks():
                store_file.write(content)
                #print content[:100]

            store_file.close()
            #result = filename + " is uploaded successfully"
            result = "ok"
        else:
            result = "invalid upload"

        return HttpResponse(result)

    else:
        form = UploadFileForm()
        return render_to_response( "upload_customer_report.html",
                {"upload_customer_report_form":form },
            context_instance=RequestContext(request) )
开发者ID:privateprojects,项目名称:sosproject,代码行数:31,代码来源:views.py

示例9: post

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
    def post(self, request):
        form = UploadFileForm(request.POST, request.FILES)
        msg = ''

        if form.is_valid():
            test = Test(
                start_time = convert_time(form.cleaned_data['start']),
                end_time = convert_time(form.cleaned_data['end']),
                author_id = UserProfile.objects.get(user__id=request.user.id),
                time = int(form.cleaned_data['time'])
                )
            test.save()
            try:
                test.room = Room.objects.get(id=form.cleaned_data.get('room'))
            except:
                test.room = None
            finally:
                test.save()
            try:
                self.handle_uploaded_file(test.id, request.FILES['file'])
            except:
                test.delete()
                msg = {'error': 'Wystąpił konflikt terminów. Test nie został dodany.'}
                return render(request, self.template_name, {'form': form, 'msg': msg})

            else:
                test.name = self.get_test_name_from_file(test.id)
                test.save()
            return HttpResponseRedirect(reverse('tests'))
        else:
            msg = {'error': u'Wystąpił błąd podczas ładowania pliku.'}
            form = UploadFileForm()
            return render(request, self.template_name, {'form': form, 'msg': msg})
开发者ID:piotut,项目名称:TestSystem,代码行数:35,代码来源:views.py

示例10: home

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def home(request):
    form = UploadFileForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        form.my_save(request)
        return redirect('/')
    else:
        return render(request, "index.html", {"form": form})

# @login_required()
# def userfiles(request):
#     files = DropObjet.objects.filter(user=request.user)
#     #files = DropObjet.objects.all()
#     for file in files:
#         print file.name
#     return render(request, "userfiles.html", {'files': files})
#
# @login_required()
# def show_file(request):
#     name = request.GET.get('name')
#     #name = name.replace('_', ' ')
#     print name
#     print 'Good'
#     file = get_object_or_404(DropObjet, name=name, user=request.user)
#     client = dropbox.client.DropboxClient(settings.AUTH_TOKEN)
#     shared_url = client.share(file.get_path(), short_url=True)
#     print shared_url['url']
#     return render(request, "show_file.html", {'link': shared_url['url']})
开发者ID:anmekin,项目名称:DjBox,代码行数:29,代码来源:views.py

示例11: upload_file

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def upload_file(request, pk):
    #获得一个任务的实例
    task_ins = get_object_or_404(Task, pk=pk)

    #如果获取到了POST的提交
    if request.method == 'POST':
        #获取form表单,request.FILES是存放文件的地方
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            #通过处理上传文件函数来获得返回值
            uf = handle_uploaded_file(request.FILES['file'])

            #获取上传文件的实例,并补充相应信息至数据库中
            upload_ins = Upload()
            #绑定相应的task id
            upload_ins.task_id = task_ins.id
            #记录相应的文件名
            upload_ins.upload_title = uf[0]
            #记录相应的上传路径
            upload_ins.upload_path = uf[1]
            #保存upload的实例
            upload_ins.save()
            return redirect('task_edit', pk=task_ins.id)
    else:
        form = UploadFileForm()

    #构建相应的context,传递至上传文件页面
    context = {
        'form': form,
        'page_title': '任务处理',
        'sub_title': '上传文件',

    }
    return render(request, 'upload.html', context)
开发者ID:alexchen16,项目名称:echo_site,代码行数:36,代码来源:views.py

示例12: file_share

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
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)
开发者ID:berggren,项目名称:fordropweb,代码行数:36,代码来源:views.py

示例13: upload

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def upload(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            dest = form.cleaned_data['dest']
            handle_uploaded_file(dest, request.FILES['file'])
    return redirect('/')
开发者ID:traceur,项目名称:lbplayer,代码行数:9,代码来源:views.py

示例14: add_avatar

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def add_avatar(request):
	#get image from client
	#save image to media folder
	if request.method == "POST":
		logger.debug("[photo]request POST form: "+ str(request.POST))
		form = UploadFileForm(request.POST, request.FILES)
		logger.debug("[photo]request FILES form: "+ str(request.FILES))

		user_name = request.POST.get('username')
		logger.debug("user name: "+user_name)
		if form.is_valid() and form.is_multipart():
			logger.debug("[photo]upload image: "+str(request.FILES))
			save_file(request.FILES['image'])

			# save image path to avatar url
			client_user = User.objects.get(username = user_name)
			client_info = UserInfo.objects.get(user=client_user)
			client_info.avatar.save(request.FILES['image'].name, request.FILES['image'])
			client_info.save()

			return HttpResponse(200)
		else:
			return HttpResponse('invalid image')

	if request.method == "GET":
		return render(request, 'times/photo.html')
开发者ID:youtaya,项目名称:mothertree,代码行数:28,代码来源:views.py

示例15: upload

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import is_valid [as 别名]
def upload(request):
    if request.method != 'POST':
        return redirect('index')

    form = UploadFileForm(request.POST, request.FILES)
    if form.is_valid():
        f = request.FILES['file']
        try:
            name = str(f)
            try:
                isnew = False
                c = Cert.objects.get(filename=name)
            except ObjectDoesNotExist:
                isnew = True
                c = Cert()

            c.frombuffer(f.read())
            if isnew:
                c.filename = name
            c.save()

            return render(request, 'success.html', {
                'vdict': c.verbose_dict(),
                'cert': c,
                'isnew': isnew
            })
        except crypto.Error as e:
            raise e

    return redirect('index')
开发者ID:glebofff,项目名称:djssl,代码行数:32,代码来源:views.py


注:本文中的forms.UploadFileForm.is_valid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。