Esempio n. 1
0
def new_post():
    form = post_form()
    if form.validate_on_submit():
        # post = posts(title=form.title.data, author=form.content.data, content=form.content.data)
        flash("Post Created", "success")
        return redirect(url_for("home"))
    return render_template("create_post.html", title="New Post", form=form)
Esempio n. 2
0
def profile(request):
	is_user = False
	if request.session.get('search_for'):
		name = request.session.get('search_for')
		request.session['current_pro'] = name
		request.session['search_for'] = None
		request.session['from_method'] = 'profile'
	else:
		if request.session.get('current_pro') == request.session.get('username'):
			is_user = True
			name = request.session.get('username')
		else:
			name = request.session.get('current_pro')
	u = userProfile.objects.get(username=name)
	posts = post.objects.all()
	counter = len(posts)
	all_comments = comment.objects.all()
	if request.method == 'POST':
		form = post_form(request.POST)
		if form.is_valid():
			counter += 1
			newpost = form.save(commit=False)
			newpost.username = request.session.get('username') #username of the person posting
			newpost.user_wall = name #username of the wall being posted to
			newpost.date = datetime.datetime.now()
			newpost.messageId=counter
			newpost.save()
		else:
			print form.errors
	else:
		form = post_form()
	if u.photoId != 0:
		picture = addImage.objects.get(photoId=u.photoId)
	else:
		picture = None
	user_posts = posts.filter(user_wall=request.session.get('current_pro'))
	details = {'user_profile':name, 'location':u.location, 'picture': picture, 'joined':u.joined, 'birthday':u.birthday, 'current_pro':name,  'username':request.session.get('username'), 'posts':user_posts}
	if is_user:
		print "to user profile"
		return render(request, 'kerbie/user_profile.html', details)
	else:
		print "to other profile"
		return render(request, 'kerbie/profile.html', details)
Esempio n. 3
0
 def POST(self):
     f=post_form()
     if f.validates():
         username, password=f.username.value, f.password.value
         user=get_userid(username)
         if user and user.get('password')==hashlib.sha1(password).hexdigest():
             s=Session(user)
             addSession(s)
             web.setcookie('localpost_sessionid', s.dumps().get('id'), 604800)
             raise web.seeother('/list')
     return render_template('generic_form.html', f=f)
Esempio n. 4
0
 def GET(self):
     f=post_form()
     return render_template('generic_form.html',f=f)