Exemple #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'))
Exemple #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 postId is None:
        return redirect(url_for('PetCare.create_post'))
    prevPost = dict(postDao.get_post(postId))
    if request.method == 'GET':
        # TODO: return with post information shown
        return render_template('edit_post.html', error=None)
    postInfo = Entities.make_post_info(session['logged_in'], request, prevPost)
    if not postInfo:
        return render_template('edit_post.html',
                               error="Required Informaion Missing")
    postInfo['id'] = postId
    postDao.update_post(postInfo)
    return redirect(url_for('PetCare.list_posts'))