Example #1
0
def dog():
    '''
    View dog
    '''

    form = CommentForm()
    arguments = request.args
    if 'id' in arguments:
        post_id = int(arguments['id'])
    else:
        return redirect(url_for('index'))

    query = Post.query.filter_by(id=post_id).first()
    if query is None:
        return redirect(url_for('index'))

    if form.validate_on_submit():
        gigi = Comment(text=form.text.data,
                       user_id=current_user.id,
                       post_id=post_id)
        query.comments.append(gigi)
        DB.session.commit()

    comments = Comment.query.filter_by(post_id=post_id)
    print(comments)
    return render_template('dog.html', dog=query, comments=comments, form=form)
Example #2
0
    def _copyCommentToForm(self, comment, article_key=None, author=None):
        """Copy relevant fields from Comment to CommentForm."""
        cf = CommentForm()

        if not author:
            author = Author.query()\
                .filter(Author.authorID==comment.authorID)\
                .get()

        if not article_key:
            article_key = comment.key.parent()

        for field in cf.all_fields():
            if hasattr(comment, field.name):
                # convert Date to date string
                if field.name.startswith('date'):
                    setattr(cf, field.name, str(getattr(comment, field.name)))
                else:
                    setattr(cf, field.name, getattr(comment, field.name))
            # add the fields that are not part of the Comment model
            elif field.name == "websafeCommentKey":
                setattr(cf, field.name, comment.key.urlsafe())
            elif field.name == "websafeArticleKey":
                setattr(cf, field.name, article_key.urlsafe())
            elif field.name == "websafeAuthorKey":
                setattr(cf, field.name, author.key.urlsafe())
        cf.check_initialized()
        return cf
Example #3
0
def show(aid):
    res = Article.query.filter(Article.id == aid)
    if res.count() > 0:
        article = res.one()
        cmform = CommentForm(request.form)
        fbfm = FeedbackForm(request.form)
        return render_template('article/show.html',
                               article=article,
                               cmform=cmform,
                               fbfm=fbfm)
    else:
        abort(404)
Example #4
0
def post(post_id, page):
    form = CommentForm()
    if (current_user.is_authenticated() and form.validate_on_submit()):
        form.comment.author_id = current_user.id
        form.comment.post_id = post_id
        db.session.add(form.comment)
        db.session.commit()
        fragment.reset(posts_list)
        fragment.reset(comments_list, post_id)
        fragment.reset(user_info, current_user.id)
        flash('Your comment has saved successfully.', 'info')
    return render_template('post.html', form=form, post_id=post_id, page=page)
Example #5
0
def show(mid):
    res =  db.query(Movie).filter(Movie.id==mid)
    if res.count()==0:
        abort(404)
    else:
        movie = res.one()
        ip = request.remote_addr
        res = db.query(MovieRead).filter(MovieRead.ip==ip, MovieRead.movie_id==mid)
        if res.count()==0:
            mr = MovieRead(
                    ip=ip,
                    movie_id=mid,
                    created_at=now_datetime()
                )
            db.add(mr)
            db.commit()
            if mr.id>0:
                movie.read_count+=1
                db.commit()

        form = LoginForm(request.form)
        cmform = CommentForm(request.form)
        fbfm = FeedbackForm(request.form)
        followers = movie.followers().all()
        sql = "select c.*,mc.celebrity_type from movie_celebrity mc LEFT JOIN celebrity c on c.id=mc.celebrity_id WHERE mc.movie_id=:movie_id"
        celebrities = conn.execute(text(sql), {'movie_id':mid})
        actors = []
        directors = []
        for cel in celebrities:
            if cel.celebrity_type==u'演员':
                actors.append(cel)
            elif cel.celebrity_type==u'导演':
                directors.append(cel)

        sql = "select u.* from movie_favorite mf left join users u on u.id=mf.user_id where mf.movie_id=:mid limit 10"
        favorites = conn.execute(text(sql),{'mid':mid})
        subjects = movie.subjects.all()
        articles = movie.articles.all()
    return render_template('movie/detail.html', movie=movie, form=form, cmform=cmform,favorites=favorites,subjects=subjects,
                               followers=followers, fbfm=fbfm, actors=actors, directors=directors, articles=articles)