예제 #1
0
파일: views.py 프로젝트: zombrie/kerbie
def comments(request, post_id):
	print 'comments'
	all_comments = comment.objects.all()
	main_post = post.objects.get(messageId=post_id)
	post_comments = comment.objects.filter(messageId=post_id)
	counter = len(all_comments)
	print 'counter= ' + str(counter)
	if request.method == 'POST':
		print 'if post comments'
		form = comment_form(request.POST)
		if form.is_valid():
			print 'form is valid comments'
			counter += 1
			newcomment = form.save(commit=False)
			newcomment.username = request.session.get('username')
			newcomment.messageId = post_id
			newcomment.date = datetime.datetime.now()
			newcomment.commentId = counter
			newcomment.save()
			print len(comment.objects.all())
		else:
			print "fml"+str(form.errors)
	else:
		print 'comment GET'
		form = comment_form()
	return render(request, 'kerbie/comment.html', {'post':main_post, 'comments':post_comments})
예제 #2
0
 def get(self, username):
     user = User.one({'username': username})
     if not user:
         raise tornado.web.HTTPError(404)
     
     if user == self.current_user and user.is_admin:
         self.redirect('/admin')
         return
     
     pagination = self.get_comments_for(user)
     f = comment_form()
     self.render('profile/wall', pagination=pagination, user=user, f=f)
예제 #3
0
 def GET(self, arg):
     post = self.get_post(arg)
     f = comment_form()
     if post:
         post.view_count += 1
         widget = get_sidebar()
         widget['relative_posts'] = sidebar.relative_posts(post)               # get relative posts in sidebar widget
         return render_template('single.html',
                                post=post, widget=widget,
                                form=f, admin=web.ctx.session.username,
                                location='single')
     else:
         raise web.notfound()
예제 #4
0
 def post(self, username):
     user, pagination = self.get_comments_for(username)
     f = comment_form()
     data = self.get_arguments()
     try:
         if f.validates(tornado.web._O(data)):
             comment = Comment()
             comment.save(
                     { 'from': self.current_user,
                       'for': user,
                       'comment': data['comment']
                      }
                 )
             self.set_flash(self._("Comment has been saved."))
             self.redirect("/profile/%s" % username)
             return
         raise Exception()
     except Exception, e:
         f.note = f.note if f.note else e
         self.render('profile/%s' % username, pagination=pagination, user=user, f=f)
예제 #5
0
 def POST(self, arg):
     post = self.get_post(arg)
     f = comment_form()
     if not f.validates():
         return render.single(post=post, widget=get_sidebar(),
                              form=f, location='single')
     else:
         # store the comment data here
         comment = Comment(
             author = f.author.value,
             email = f.email.value,
             url = f.url.value,
             content = markdown(f.comment.value),
             ip = web.ctx.get('ip', ''),
             post_id = post.id
         )
         web.ctx.orm.add(comment)
         post.comment_count += 1                   # update the comment_count of this post
         post.view_count -= 1                      # as we will redirect to the same page next, so~
        # self.validate_comment(comment)
         web.ctx.orm.commit()
         web.seeother(comment.get_absolute_url())
예제 #6
0
    def POST(self,arg):
        post = self.get_post(arg)
        f = comment_form()

        if post:
            if f.validates():
                #store comment
                comment = Comment(
                    author  = f.author.value,
                    email   = f.email.value,
                    url     = f.url.value,
                    content = f.comment.value,
                    ip = web.ctx.get('ip', '') ,
                    post_id = post.id
                )

                web.ctx.orm.add(comment)
                post.comment_count += 1
                web.ctx.orm.commit()
                web.seeother(comment.get_absolute_url())
            else:
                return render.single(post=post, widget=get_sidebar(),form = f,location='single')
        else:
            raise web.notfound
예제 #7
0
파일: Index.py 프로젝트: ricardo1470/server
def index():#function
    comment_form = forms.comment_form()
    title = "my form"
    return render_template('index.html', title = title, form = comment_form)
예제 #8
0
파일: uimodules.py 프로젝트: apit/rinjani
 def render(self, user=None):
     from forms import comment_form
     f = comment_form()
     return self.render_string('modules/comment-box', f=f)