Beispiel #1
0
def create_post():
	if session.get('logged_in') is None:
		return redirect(url_for('PetCare.login'))
	accountDao = AccountDao()
	postDao = PostDao()
	postId = accountDao.get_account_post(session['logged_in'].rstrip())
	if postId is not None:
		return redirect(url_for('PetCare.edit_post'))
	if request.method == 'GET':
		return render_template('create_post.html', error=None)
	postInfo = Entities.make_post_info(session['logged_in'].rstrip(), request)
	if not postInfo:
		return render_template('create_post.html', error="Required Informaion Missing")
	postId = postDao.add_post(postInfo)
	accountDao.update_account_post(session['logged_in'].rstrip(), postId)
	return redirect(url_for('PetCare.list_posts'))
Beispiel #2
0
def edit_post():
	if session.get('logged_in') is None:
		return redirect(url_for('PetCare.login'))
	accountDao = AccountDao()
	postDao = PostDao()
	postId = accountDao.get_account_post(session['logged_in'])
	if request.method == 'GET':
		if postId is None:
			return render_template('edit_post.html', error=None)
		post = postDao.get_post(postId)
		# TODO: return with post information shown
		return render_template('edit_post.html', error=None)
	postInfo = make_post_info(session['logged_in'], request.form)
	if not postInfo:
		return render_template('edit_post.html', error="Required Informaion Missing")
	if postId is None:
		postId = postDao.add_post(postInfo)
		accountDao.update_account_post(session['logged_in'], postId)
	else:
		postInfo['id'] = postId
		postDao.update_post(postInfo)
	return redirect(url_for('PetCare.list_posts'))