Esempio n. 1
0
def SpecificProject(request, projectslug):
	project = Project.objects.get(slug=projectslug)
	if request.method == 'POST':
		form = CommentForm(request.POST)
		if form.is_valid():
			content = form.cleaned_data['content']
			sender = Employee.objects.get(username=request.user.username)
			new_comment = Comment(sender=sender,project=project,content=content)
			new_comment.save()
			context = {'project':project,'form':form}
			return HttpResponseRedirect('/projects/' + projectslug + '/')
	form = CommentForm()
	comments = Comment.objects.filter(project=project)
	context = {'project':project,'comments':comments,'form':form}
	return render_to_response('singleproject.html', context, context_instance=RequestContext(request))
Esempio n. 2
0
def comment_reply(parent_id, post_id, user_id):
    target_post = Post.query.filter_by(id=post_id).first_or_404()
    target_comment = Comment.query.filter_by(id=parent_id).first_or_404()
    subreddits = Subreddit.query.all()
    print('replied')
    print('parent_id: ', parent_id)
    print('post_id: ', post_id)
    print('user_id: ', user_id)
    text = request.form['reply-text']
    time = datetime.now()
    newtime = datetime.strftime(time, '%d/%m/%Y')
    author = User.query.filter_by(id=current_user.id).first_or_404().name
    author_id = User.query.filter_by(name=current_user.name).first_or_404().id
    reply = Comment(text=text,
                    post_id=post_id,
                    user_id=current_user.id,
                    author=author,
                    votes=0,
                    timestamp=newtime,
                    father_id=parent_id)
    db.session.add(reply)
    db.session.commit()
    comments = Comment.query.filter_by(post_id=post_id)
    for reply in target_comment.replies:
        print('reply: ', reply.id)
    return render_template('post_details.html',
                           post=target_post,
                           name=current_user.name,
                           subreddits=subreddits,
                           comments=comments)
Esempio n. 3
0
def create_comment(post_id, user_id):
    target_post = Post.query.filter_by(id=post_id).first_or_404()
    subreddits = Subreddit.query.all()
    text = request.form['comment-text']
    post_id = post_id
    user_id = user_id
    author_id = User.query.filter_by(name=current_user.name).first_or_404().id
    author = User.query.filter_by(id=user_id).first_or_404().name
    print('author: ', author)
    time = datetime.now()
    newtime = datetime.strftime(time, '%d/%m/%Y')
    new_comment = Comment(text=text,
                          post_id=post_id,
                          user_id=user_id,
                          author=author,
                          votes=0,
                          timestamp=newtime)
    comments = Comment.query.filter_by(post_id=post_id)
    db.session.add(new_comment)
    db.session.commit()
    return render_template('post_details.html',
                           post=target_post,
                           name=current_user.name,
                           subreddits=subreddits,
                           comments=comments)
Esempio n. 4
0
 def setUp(self):
     #self.create_app() # Create the app with TestConfig
     db.create_all()
     admin = User("admin", "*****@*****.**", "admin")
     admin.private_favorites = True
     db.session.add(admin)
     db.session.add(User("abd", "*****@*****.**", "abd"))
     db.session.add(User("tester", "*****@*****.**", "tester"))
     c = Category("testing")
     db.session.add(c)
     db.session.add(Category("testing_cat"))
     testing_post = BlogPost("Testing Post",
                             "This is just a test post",
                             author_id=1)
     testing_post.category = c
     db.session.add(testing_post)
     post1 = BlogPost("Testing Tag",
                      "This is just a test post to test tags",
                      author_id=2)
     post2 = BlogPost("From Abd",
                      "This is just a test post From Abd",
                      author_id=2)
     post1.category = c
     post2.category = c
     db.session.add(post1)
     db.session.add(post2)
     tag = Tag("tests")
     post1.tags.append(tag)
     db.session.add(Comment("Test comment", 1, 2))
     admin.fav_posts.append(testing_post)
     db.session.commit()
Esempio n. 5
0
def post_by_id(id):
    post = BlogPost.query.filter_by(id=id).first_or_404()
    comments = Comment.query.filter_by(post_id=post.id)
    form = CommentForm()
    if form.validate_on_submit():
        db.session.add(Comment(form.content.data, post.id, current_user.id))
        db.session.commit()
        flash("Added new comment successfully!")
    return render_template("post.html",
                           post=post,
                           comments=comments,
                           form=form)
Esempio n. 6
0
def create_commment(post_id):
    post = BlogPost.query.filter_by(id=post_id).first()
    form = CommentForm()
    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data

        comment = Comment(post_id=post_id,
                          user_id=current_user.id,
                          title=title,
                          content=content)
        db.session.add(comment)
        db.session.commit()
        flash('Komentar shranjen OK')
        return redirect(url_for('blog.blog_details', post_id=post_id))
Esempio n. 7
0
def blog_detail(id):
    article = Article.query.get(id)
    comments = Comment.query.filter_by(blog_id=id).order_by(
        Comment.id.desc()).all()
    # comments = Comment.query.all()
    form = CommentInput()
    if form.validate_on_submit():
        blog_id = id
        body = form.body.data
        blog_author = Article.query.get(blog_id).author
        comment = Comment(blog_id=blog_id, blog_author=blog_author, body=body)
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for('personal_page'))
    return render_template('blog-detail.html',
                           article=article,
                           form=form,
                           comments=comments)
Esempio n. 8
0
def init_database():
    db.drop_all()
    db.create_all()
    for i in range(0, 100):
        db.session.add(User('User' + str(i + 1), 'a' + str(i + 1)))
        for j in range(0, 10):
            db.session.add(Image(get_image_url(), i + 1))
            for k in range(0, 3):
                db.session.add(
                    Comment('This is a comment' + str(k), 1 + 10 * i + j,
                            i + 1))

    db.session.commit()

    for i in range(50, 100, 2):
        user = User.query.get(i)
        user.username = '******' + user.username

    User.query.filter_by(id=51).update({'username': '******'})
    db.session.commit()

    for i in range(50, 100, 2):
        comment = Comment.query.get(i + 1)
        db.session.delete(comment)
    db.session.commit()

    print 1, User.query.all()
    print 2, User.query.get(3)
    print 3, User.query.filter_by(id=5).first()
    print 4, User.query.order_by(User.id.desc()).offset(1).limit(2).all()
    print 5, User.query.filter(User.username.endswith('0')).limit(3).all()
    print 6, User.query.filter(or_(User.id == 88, User.id == 99)).all()
    print 7, User.query.filter(and_(User.id > 88, User.id < 93)).all()
    print 8, User.query.filter(and_(User.id > 88, User.id < 93)).first_or_404()
    print 9, User.query.order_by(User.id.desc()).paginate(page=1,
                                                          per_page=10).items
    user = User.query.get(1)
    print 10, user.images

    image = Image.query.get(1)
    print 11, image, image.user
Esempio n. 9
0
def create_comment(id):
    comment = Comment(user_id = current_user.id, post_id = id, image_url = request.form['image_url'], body = request.form['body'])
    db.session.add(comment)
    db.session.commit()
    flash('Thank you for your comment', 'success')
    return redirect(url_for('view_post', id=id))