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


Python Tag.strip方法代码示例

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


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

示例1: editProject

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import strip [as 别名]
def editProject(pid):
    project = Project.query.filter_by(id=pid).first()
    user = User.query.filter_by(id=session.get('user_id')).first()
    form = EditProjectForm(request.form)
    if request.method == 'POST' and form.validate():
	if user == project.author:
	    if form.title.data:
		project.title = form.title.data
	    if form.status.data:
		project.public = not project.public
	    if form.tags.data:
		newTags = form.tags.data
		newTags = newTags.split(',')
		oldTags = Tag.query.filter_by(project_id=project.id).all()
		for tag in oldTags:
		    db_session.delete(tag)
		for tag in newTags:
		    if tag.strip() != "":
			tag = Tag(tag.strip(), project.id)
			db_session.add(tag)
	    db_session.add(project)
	    db_session.commit()
	    return redirect(url_for('project', pid=project.id))
	return redirect(url_for('index'))
    return render_template('edit.html', form=form, project=project)
开发者ID:connienguyen,项目名称:knitting,代码行数:27,代码来源:app.py

示例2: upload

# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import strip [as 别名]
def upload():
    form = UploadForm(request.form)
    if request.method == 'POST' and form.validate() and current_user.is_authenticated():
	image = request.files['image']
	if image:
	    filename = secure_filename(image.filename)
	    filename, ext = filename.split('.', 1)
	    if ext not in IMG_EXTS:
		return redirect(url_for('upload'))
	    timestamp = cleanTime(str(datetime.utcnow()))
	    filename = filename + timestamp + '.' + ext
	    image_data = request.files[image.name].read()
	    open(os.path.join(app.config['UPLOAD_FOLDER'], filename), 'w').write(image_data)
	    flash('You have uploaded a file')
	    if form.maxColors.data:
		patternfile, across, tall = processImage(filename, form.stitches.data, form.maxColors.data)
		colors = form.maxColors.data
	    else:
		patternfile, across, tall = processImage(filename, form.stitches.data)
		colors = 256
	    os.remove(UPLOAD_FOLDER + filename)
	    patternsave = url_for('static', filename=patternfile)
	    project = Project(session.get('user_id'), patternsave, form.title.data, form.public.data, across, tall, colors) 
	    db_session.add(project)
	    db_session.commit()
	    tags = form.tags.data
	    if tags:
		tags = tags.split(',')
		for tag in tags:
		    if tag != '':
			tag = Tag(tag.strip(), project.id)
			db_session.add(tag)
		db_session.commit()
	    return redirect(url_for('project', pid=project.id))
	return redirect(url_for('index.html'))
    return render_template('upload.html', form = form)
开发者ID:connienguyen,项目名称:knitting,代码行数:38,代码来源:app.py


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