本文整理汇总了Python中models.Document.filename方法的典型用法代码示例。如果您正苦于以下问题:Python Document.filename方法的具体用法?Python Document.filename怎么用?Python Document.filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Document
的用法示例。
在下文中一共展示了Document.filename方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submit
# 需要导入模块: from models import Document [as 别名]
# 或者: from models.Document import filename [as 别名]
def submit():
dForm = documentForm(request.form)
print current_user.id
if dForm.validate_on_submit():
title=dForm.title.data
description=dForm.description.data
location=dForm.location.data
issue_idea=dForm.issue_idea.data
category=dForm.category.data
submitter=current_user.id
document = Document(title=title,description=description,location=location,issue_idea=issue_idea,category=category,submitter=submitter)
db.session.add(document)
db.session.commit()
did = db.session.query(func.max(Document.id)).scalar()
document = Document.query.get(did)
file = request.files['file']
filename = str(did) + ".png"
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
document.filename = filename
doc_vote = Votes(docid=did,userid=current_user.id)
db.session.add(doc_vote)
db.session.commit()
return render_template('submission.html',dForm=dForm)
示例2: save_document
# 需要导入模块: from models import Document [as 别名]
# 或者: from models.Document import filename [as 别名]
def save_document(request_file, content_subdir, related_obj, ashash = True):
uploadedfile = UploadedFile(request_file)
file_content = uploadedfile.read()
doc_obj = Document()
doc_obj.filehash = md5(file_content).hexdigest()
doc_obj.urlencfilename = quote(uploadedfile.name)
doc_obj.filename = uploadedfile.name
doc_obj.content_type = uploadedfile.file.content_type
if ashash:
doc_obj.filepath = settings.BASE_DIR + content_subdir + doc_obj.filehash
else:
doc_obj.filepath = settings.BASE_DIR + content_subdir + doc_obj.filename
if related_obj.__class__.__name__.lower() == "queryset":
if len(related_obj) == 1:
setattr(doc_obj, related_obj[0].__class__.__name__.lower(), related_obj[0])
else:
print "ERROR: The queryset object had %s elements to it" % str(len(related_obj))
else:
setattr(doc_obj, related_obj.__class__.__name__.lower(), related_obj)
doc_obj.save()
wfile = open(doc_obj.filepath, "w")
wfile.write(file_content)
wfile.close()