Exemple #1
0
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)
Exemple #2
0
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)