Beispiel #1
0
def profile(): 

	form = CreatePostForm()		
	# session gets the encrypted ID and hashes it to get the value i.e. the username
	user = User.query.filter_by(username = session['username']).first()

	if user is None:
		return redirect(url_for('signin'))
	else:
		if request.method == 'POST':						
			if form.validate() == False:				
				return render_template('profile.html', form=form,communityform=CreateCommunityForm())
			else:				
				newpost = Post(form.text.data, session['userID'], form.categoryID)				
				db.session.add(newpost)
				
				file = request.files[form.image.name]				
				if file: 					
					filename = secure_filename(file.filename)
					# flush to ge the postID to be used as filename
					db.session.flush()				
					filename = str(newpost.postID) + os.path.splitext(filename)[1]
					newpost.imageURI = filename
					file.save(os.path.join(APP_UPLOADS, filename))								
					flash(filename+" uploaded!")		
										
					
				db.session.commit()
				
				flash("posted!")			
				return redirect(url_for('profile'))
		elif request.method == 'GET':		
			# posts = Post.query.filter_by(username = session['username']).first()
			return render_template('profile.html', form=form, communityform=CreateCommunityForm())