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


Python Document.filename方法代码示例

本文整理汇总了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)
开发者ID:imAlan,项目名称:NYU-Emerging-Solutions,代码行数:25,代码来源:views.py

示例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()
开发者ID:bplower,项目名称:cssef,代码行数:26,代码来源:utils.py


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