def DL(name): form = UploadForm() if form.validate_on_submit(): customer = Customer.query.filter_by(name=name).first() if customer is None: flash('No customer with this name', 'warning') return redirect(url_for('signup')) try: files = form.license.data picture = Picture(customer_id=customer.id, License=files.read()) db.session.add(picture) uril = "https://static.wixstatic.com/media/cd5c35_e4e3005990ea4a879a280fd6dfe3bdbf~mv2.jpg/v1/fill/w_312,h_318,al_c,q_80,usm_0.66_1.00_0.01/empty-dp.webp" newprofile = Propic(customer_id=customer.id, pic_url=uril) db.session.add(newprofile) db.session.commit() except: flash('Couldnt Insert License', 'danger') db.session.execute('delete from "customer" where id= :ids', {"ids": customer.id}) db.session.execute('DELETE from "User_login" where id = :ids', {"ids": customer.id}) db.session.execute('DELETE from "profile" where id= : ids', {"ids": customer.id}) db.session.commit() return redirect(url_for('signup')) flash(f'Account created for {name} Please Login !', 'success') return redirect(url_for('login')) return render_template("imageupload.html", form=form)
def welcome_page(request): template = get_template("main.html") data = '' if request.method == 'POST': uploadform = UploadForm(request.POST, request.FILES) if uploadform.is_valid(): f = request.FILES['File'] new_file = UploadFile(FileName=f.name,File=f) new_file.save() file_path = os.path.join(PROJ_ROOT, str(new_file.File)) data = text_recognition.text_recognition.pipline(file_path, os.path.join(STATICFILES_DIRS[0], 'text_rec')) text_rec = [TextRecRes(Rects=str(x[0]), Text=x[1], FK_UFile=new_file) for x in data] map(lambda x: x.save(), text_rec) faces = face_detection.face_dnr.detect_faces(file_path, os.path.join(STATICFILES_DIRS[0], 'face_rec')) face_rec = [FaceRecRes(Rects=str(x[1]), FK_UFile=new_file, FileName=x[0][len(STATICFILES_DIRS[0]) - len('static/'):]) for x in faces] map(lambda x: x.save(), face_rec) uploadform = UploadForm() up_files = UploadFile.objects.all().order_by('-id') for x in up_files: x.info = TextRecRes.objects.filter(FK_UFile=x) x.people = FaceRecRes.objects.filter(FK_UFile=x) x.num_of_people = len(x.people) context = RequestContext(request, { 'form' : uploadform, 'up_files' : up_files[:10] }) return HttpResponse(template.render(context))
def upload(): form = UploadForm() if form.validate_on_submit(): f = form.upload.data filename = secure_filename(f.filename) f.save(os.path.join('uploads/', filename)) return redirect('/yml') return render_template('upload.html', tiile='Upload File', form=form)
def predict_load(): form = UploadForm() if form.validate_on_submit(): filename = photos.save(form.photo.data) file_url = photos.url(filename) res = perd(basedir + "/static/image/" + filename)[0][0] else: file_url, res= None, None return render_template('predict_load.html', form=form, file_url=file_url, res=res)
def upload(): # Panggil UploadForm dari form.py form = UploadForm() docList = renderDocList() global fileList , wordList , mVec # Jika ada file tersubmit, ambil nama file (secured oleh werkzeug) , cek ekstensinya jika .txt, simpan file ke folder test if form.validate_on_submit(): for files in form.file.data : filename = secure_filename(files.filename) file_ext = os.path.splitext(filename)[1] if file_ext != '.txt': flash(f'Format of file(s) uploaded is not allowed (.txt only), file submission canceled!' , 'danger') return redirect(url_for('upload')) files.save('../test/' + filename) flash(f'File(s) added!' , 'success') # Karena ada input file baru, database kamus di-update # Menampung semua nama file ke dalam suatu variabel list fileList fileList = [] for root, dirs, files in os.walk('../test', topdown=False): for name in files : dir = os.path.join(root,name).split('\\') # Mengambil hanya nama filenya, tidak bersama direktori yang displit oleh \ fileList.append(dir[1]) contentList = [] for name in fileList : # Menampung tiap konten dalam tiap file, melakukan cleaning, konversi ke token, menghapus stopword, dan lemmatize content = Read.readfile('../test/'+name) content = Read.cleaning(content) content = Read.token(content) content = Preprocessing.stopwords(content) content = Preprocessing.stemming(content) # Menggabungkan semua konten menjadi satu list contentList.append(content) # Membuat variabel penampung kata-kata yang ada di dokumen wordList = [] for content in contentList : for word in content : if word not in wordList : wordList.append(word) # Membuat variabel penampung jumlah kemunculan tiap kata pada tiap data mVec = [[0 for x in range(len(wordList))] for y in range(len(fileList))] j = 0 for content in contentList : for word in content : for i in range(len(wordList)) : if word == wordList[i] : mVec[j][i] = mVec[j][i] + 1 j = j + 1 return redirect(url_for('upload')) return render_template('upload.html', form=form, docs = docList)
def upload(): form = UploadForm() if form.validate_on_submit(): f = form.photo.data filename = random_filename(f.filename) f.save(os.path.join(app.config['UPLOAD_PATH'], filename)) flash('Upload success.') session['filenames'] = [filename] return redirect(url_for('show_images')) return render_template('upload.html', form=form)
def upload(): if not os.path.exists('static/' + str(session.get('id'))): os.makedirs('static/' + str(session.get('id'))) file_url = os.listdir('static/' + str(session.get('id'))) file_url = [str(session.get('id')) + "/" + file for file in file_url] formUpload = UploadForm() if formUpload.validate_on_submit(): filename = photos.save(formUpload.file.data, name=str(session.get('id')) + '.jpg', folder=str(session.get('id'))) file_url.append(filename) return render_template("upload_image.html", formupload=formUpload, filelist=file_url)
def upload(): form = UploadForm() if form.validate_on_submit(): f = form.photo.data # filename = random_filename(f.filename) #如果不能确定文件来源安全的话,就需要这样的来设置。 filename = f.filename print(filename) f.save(os.path.join(app.config['UPLOAD_PATH'], filename)) #这样就是直接的文件保存的东西了。 session['filenames'] = filename #直接通过session来传递。 return redirect(url_for('showImage')) return render_template("uploadTest.html", form=form)
def upload(): form = UploadForm() if form.validate_on_submit(): f = form.photo.data #生成随机文件名 我们调用这个函数来获取随机文件名,传入原文 件名作为参数 filename = random_filename(f.filename) #保存文件 f.save(os.path.join(app.config['UPLOAD_PATH'], filename)) flash('Upload success') #session['filenames'] = [filename] #return redirect(url_for('show_images')) return redirect(url_for('watchlist')) return render_template('upload.html', form=form)
def hello_world(): if request.method == 'GET': return render_template('upload.html') else: if not os.path.exists(UPLOAD_PATH): os.makedirs(UPLOAD_PATH) form = UploadForm(CombinedMultiDict([request.form, request.files]))
def upload(): if not session.get('logged_in'): abort(401) # Instantiate your form class upform = UploadForm() # Validate file upload on submit if request.method == 'POST' and upform.validate_on_submit(): # Get file data and save to your uploads folder sumn = upform.uploadfile.data name = secure_filename(sumn.filename) sumn.save(app.config['UPLOAD_FOLDER']+name) flash('File Saved', 'success') return redirect(url_for('home')) return render_template('upload.html', f=upform)
def upload(): if not session.get('logged_in'): abort(401) # Instantiate your form class Up_form = UploadForm() # Validate file upload on submit if request.method == 'POST': # Get file data and save to your uploads folder if Up_form.validate_on_submit(): File = Up_form.upload.data Filename = secure_filename(File.filename) File.save(os.path.join(UploadFolder, Filename)) flash('File Saved', 'success') return redirect(url_for('home')) return render_template('upload.html', form=Up_form)
def get_content(request): content = RepositoryUploaddata.objects.order_by('file_name') if request.method == 'POST': upload_form = UploadForm(request.POST, request.FILES) if upload_form.is_valid(): if request.FILES['upload_data']._size < 1024: size = request.FILES['upload_data']._size else: size = request.FILES['upload_data']._size /1024 name = request.FILES['upload_data'] file = RepositoryUploaddata(upload_data = request.FILES['upload_data'], file_name = name, file_size = size) file.save() return HttpResponseRedirect('uploaded') else: upload_form = UploadForm() return render_to_response('Home.html', { 'files': content, 'upload_form': upload_form }, context_instance=RequestContext(request))
def upload(): if session.get('username'): user_info = User.query.filter(User.username == session.get('username')).first() os.chdir('/Users/lorenzocosta/Documents/Information System/Labs/Lab4_IS_database/static') if not os.path.exists(str(session.get('username'))): os.makedirs(str(session.get('username'))) file_url = os.listdir('/Users/lorenzocosta/Documents/Information System/Labs/Lab4_IS_database/static/'+str(session.get('username'))) print file_url file_url = [str(session.get('username')) + "/" + file for file in file_url] print file_url form_upload = UploadForm() if form_upload.validate_on_submit(): filename = photos.save(form_upload.file.data, name=str(session.get('username')) + '.jpg', folder='/Users/lorenzocosta/Documents/Information System/Labs/Lab4_IS_database/static/'+str(session.get('username'))) file_url.append(filename) return render_template("upload.html", title='Uploads', form_upload=form_upload, user_info=user_info, filelist=file_url) else: return redirect('home')
def upload(): """"Define the upload route.""" form = UploadForm() if form.validate_on_submit(): # check if the file already exist in the db # try to get by PK and receive None if it does not exist : PDBid = form.pdb_file.data.filename.split('.')[0][-4:] # ex : filename = pdb1234.pdb # PDBid = 1234 current_pdb = model.PDBFile.query.get(PDBid) if not current_pdb: # insert data contains in pdb into db : filename = pdb_set.save(storage=form.pdb_file.data) # The uploaded file to save path = pdb_set.path(filename) # compute annotation current_pdb = model.PDBFile(path) dssp_data = model.Annotation(pdb_id=current_pdb.id, method="dssp", result=annot.dsspAnnot(path)) current_pdb.annotations.append(dssp_data) pross_data = model.Annotation(pdb_id=current_pdb.id, method="pross", result=annot.prossAnnot(path)) current_pdb.annotations.append(pross_data) # Add all annotations into db db.session.add(current_pdb) db.session.commit() flask.flash("The pdb was added in the database") else: flask.flash("This pdb was already in the database") return flask.redirect( flask.url_for('resultsForOnePDB', PDBid=current_pdb.id, unit=form.angle_unit.data)) return flask.render_template('upload.html', form=form)
def update_status(order_no): order = Order.query.filter_by(order_id=order_no).first() departments = Department.query.all() order_status = order.order_state if order.order_state == 'TO BE STARTED': order_status = departments[0].department_name else: i = 0 for department in departments: if order.order_state == department.department_name: try: if departments[i+1]: order_status = departments[i+1].department_name break except IndexError: order_status = 'FINISHED' break else: i = i+1 order.order_state = order_status db.session.commit() #ToDo: come rimuovere codice duplicato? se scrivo return order() mi da errore formNextStep = FormNextStep() if session['type'] == 'COMPANY': orders = Order.query.filter(or_(Order.user == session['id_user'], Order.user == session['username_user'], Order.order_company_customer == session['id_user'], Order.company == session['id_user'])).all() if formNextStep.is_submitted(): return redirect('order') elif session['type'] == 'PRIVATE': orders = Order.query.filter_by(order_private_customer=session['id_user']).all() if not os.path.exists('static/' + str(session.get('id'))): os.makedirs('static/' + str(session.get('id'))) file_url = os.listdir('static/' + str(session.get('id'))) file_url = [str(session.get('id')) + "/" + file for file in file_url] formUpload = UploadForm() if formUpload.validate_on_submit(): filename = photos.save(formUpload.file.data, name=str(session.get('id')) + '.jpg', folder=str(session.get('id'))) file_url.append(filename) return render_template('order.html', orders=orders, formNextStep=formNextStep, formupload=formUpload, filelist=file_url)
def order(): formNextStep = FormNextStep() if session['type'] == 'COMPANY': orders = Order.query.filter(or_(Order.user == session['id_user'], Order.user == session['username_user'], Order.order_company_customer == session['id_user'], Order.company == session['id_user'])).all() if formNextStep.is_submitted(): return redirect('order') elif session['type'] == 'PRIVATE': orders = Order.query.filter_by(order_private_customer=session['username']).all() if not os.path.exists('static/' + str(session.get('id'))): os.makedirs('static/' + str(session.get('id'))) file_url = os.listdir('static/' + str(session.get('id'))) file_url = [str(session.get('id')) + "/" + file for file in file_url] formUpload = UploadForm() if formUpload.validate_on_submit(): filename = photos.save(formUpload.file.data, name=str(session.get('id')) + '.jpg', folder=str(session.get('id'))) file_url.append(filename) return render_template('order.html', orders=orders, formNextStep=formNextStep, formupload=formUpload, filelist=file_url)
def upload(): if not session.get('logged_in'): abort(401) # Instantiate your form class photoform = UploadForm() # Validate file upload on submit if request.method == 'POST' and photoform.validate_on_submit(): # Get file data and save to your uploads folder photo = photoform.photo.data description = photoform.description.data filename = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) flash('File Saved', 'success') return redirect(url_for('home')) flash_errors(photoform) return render_template('upload.html', form=photoform)
def upload(): if not session.get('logged_in'): abort(401) # Instantiate your form class uploadForm = UploadForm() # Validate file upload on submit if request.method == 'POST': if uploadForm.validate() == False: flash_errors(uploadForm) else: # Get file data and save to your uploads folder f = uploadForm.upload.data filename = secure_filename(f.filename) f.save(os.path.join(app.config["UPLOAD_FOLDER"], filename)) flash('File Saved', 'success') return redirect(url_for('home')) return render_template('upload.html', uploadForm=uploadForm)
def upload_file(): from form import UploadForm form = UploadForm() from Task import MainTask file = MainTask() if form.validate_on_submit(): _filename = form.file.data.filename # 获取上传文件的文件名 _filetype = '.' + _filename.split('.')[-1] # 获取上传文件的文件类型 file.mname = _filename # 根据文件名和当前时间计算哈希值作为文件的存储名 _file_savename = str(hash(_filename + str(time.time()))) + _filetype file.name = files.save(form.file.data, name=_file_savename) file.sourcefile_url = files.url(file.name) file.sourcefile_path = files.path(file.name) file.add_to_db() success = True else: file_url = None success = False return render_template('upload.html', form=form, file_url=file.sourcefile_url, success=success)
def get_content(request): content = RepositoryUploaddata.objects.order_by('file_name') if request.method == 'POST': upload_form = UploadForm(request.POST, request.FILES) if upload_form.is_valid(): if request.FILES['upload_data']._size < 1024: size = request.FILES['upload_data']._size else: size = request.FILES['upload_data']._size / 1024 name = request.FILES['upload_data'] file = RepositoryUploaddata( upload_data=request.FILES['upload_data'], file_name=name, file_size=size) file.save() return HttpResponseRedirect('uploaded') else: upload_form = UploadForm() return render_to_response('Home.html', { 'files': content, 'upload_form': upload_form }, context_instance=RequestContext(request))
def upload(): if request.method == 'GET': return render_template('upload.html') else: # 将两个不可变字典(request.form,request.file)组合成一个字典 from werkzeug.datastructures import CombinedMultiDict form = UploadForm(CombinedMultiDict([request.form, request.files])) if form.validate(): desc = request.form.get('desc', 'No DESCRIBE') # 或 desc = form.desc.data avatar = request.files.get('avatar') # 或 avatar = form.avatar.data upload_path = os.path.join(os.path.dirname(__file__), 'upload_files') from werkzeug.utils import secure_filename # 对文件名进行包装,解决安全隐患 filename = secure_filename(avatar.filename) print(filename) avatar.save(os.path.join(upload_path, filename)) print(desc) return 'success' else: print(form.errors) return 'fail'