Exemplo n.º 1
0
    def post(self, post_id):
        if not self.user:
            return self.redirect('/blog')

        subject = self.request.get('subject')
        content = self.request.get('content')

        post = self.post_exists(post_id)
        if not post:
            return

        if not self.users_own_post(self.user, post):
            postComm = Comment.all().filter('post_id =', post_id)
            self.render("permalink.html",
                        post=post,
                        error="You don't have access to edit this record.",
                        comments=postComm)
        elif subject and content:
            post.subject = subject
            post.content = content
            post.put()
            postComm = Comment.all().filter('post_id =', post_id)
            self.render("permalink.html", post=post, comments=postComm)
        else:
            error = "subject and content, please!"
            self.render("editpost.html",
                        subject=subject,
                        content=content,
                        error=error)
Exemplo n.º 2
0
 def post(self):
     comment = self.request.get("comment")
     id = self.session.get("user")["id"]
     if self.session.get("city"):
         city = str(self.session.get("city")).lower()
     else:
         city = "dresden"
     co = Comment(name=city, uid=id, comment=comment)
     Comment.put(co)
     self.redirect('/mobile')
Exemplo n.º 3
0
    def POST(self):
        content = web.input()
        comment = content.get('comment')
        date = content.get('date')
        channel_id = content.get('channel_id')
        for key, val in content.items():
            print(key, ': ', val)

        conn = DBUtils.get_connection()
        Comment.create_comment_from_args(channel_id=channel_id, content=comment, date=date).insert(conn)
        DBUtils.release_connection(conn)
        return u'insert comment successfully'
Exemplo n.º 4
0
def get_comments(postid):
    conn = mysql.connect()
    cursor = conn.cursor()
    sql_string = "select commentid, authorid, postid, commentdate, content from comments where postid=%s order by commentdate desc"
    cursor.execute(sql_string, (postid))
    data = cursor.fetchall()
    comments = []
    for d in data:
        authorname = userid_to_object(d[1]).username
        comment = Comment(d[0], d[1], d[2], d[3], d[4], authorname)
        comment.set_likes(get_comment_likes(comment.commentid))
        comments.append(comment)

    return comments
Exemplo n.º 5
0
    def get(self):
        find_orphans = self.request.get('find_orphans')
        num_comments = Comment.query().count()
        query = Plaque.query()
        num_plaques = query.count()
        num_pending = query.filter(Plaque.approved == False).count()
        num_images = 0
        images = gcs.listbucket(GCS_BUCKET)
        for image in images:
            num_images += 1

        orphan_pics = set()
        pics_count = defaultdict(int)
        pics = set()

        if find_orphans == 'true':
            # Record which pics are linked to a plaque:
            plaques = Plaque.query().fetch()
            for plaque in plaques:
                pics.add(plaque.pic)
                pics_count[plaque.pic] += 1

            # Find pics that aren't:
            for pic in images:
                if pic not in pics:
                    orphan_pics.add(pic)
        else:
            orphan_pics.add("didn't check for orphans")

        msg = "Count: %s comments, %s plaques (%s pending), %s images, orphans: %s<hr>%s" % (
                num_comments, num_plaques, num_pending, num_images, orphan_pics, pics_count)
        self.response.write(msg)
Exemplo n.º 6
0
    def get(self, post_id):
        if self.user_logged_in(self.user):
            post = self.post_exists(post_id)
            if post:
                postComm = Comment.all().filter('post_id =', post_id)
                if self.users_own_post(self.user, post):
                    return self.render(
                        "permalink.html",
                        post=post,
                        error="You cannot dislike your own post",
                        comments=postComm)

                dislikes = Dislike.all()
                dislikes.filter('user_id =', str(self.user.key().id())).filter(
                    'post_id =', post_id)

                if dislikes.get():
                    self.render("permalink.html",
                                post=post,
                                error="You have already disliked the post",
                                comments=postComm)
                    return

                l = Dislike(user_id=str(self.user.key().id()), post_id=post_id)
                l.put()

                post.dislikes = str(int(post.dislikes) + 1)
                post.put()
                self.render("permalink.html", post=post, comments=postComm)
Exemplo n.º 7
0
    def post(self, comm_id):
        if not self.user_logged_in(self.user):
            return

        comment = self.comment_exists(comm_id)
        if not comment:
            return

        newComment = self.request.get("comment")
        if not newComment:
            error = "enter valid content"
            self.render("editcomment.html", content=newComment, error=error)
            return

        post = self.post_exists(comment.post_id)
        if not post:
            return

        # update the row and the Comment entity
        key = db.Key.from_path('Comment', int(comm_id))
        comment = db.get(key)
        comment.comment = newComment
        comment.put()

        postComm = Comment.all().filter('post_id =',
                                        comment.post_id).order('-created')
        self.render("permalink.html", post=post, comments=postComm)
Exemplo n.º 8
0
 def process(session, data):
     comment = Comment()
     Helper().fill_object_from_data(
         comment, data,
         ['comment', 'status', 'origin_ip', 'origin_agent'])
     comment.created = Helper().get_current_datetime()
     self.raise_if_has_different_parent_reference(
         data, session, [('parent_id', 'post_id', Comment),
                         ('parent_id', 'language_id', Comment)])
     self.add_foreign_keys(comment, data, session,
                           [('user_id', User), ('post_id', Post),
                            ('language_id', Language),
                            ('parent_id', Comment)])
     session.add(comment)
     session.commit()
     return self.handle_success(None, None, 'create', 'Comment',
                                comment.id)
Exemplo n.º 9
0
def get_comment(commentid):
    conn = mysql.connect()
    cursor = conn.cursor()
    cursor.execute(
        'select commentid, authorid, postid, commentdate, content from comments where commentid=%s',
        (commentid))
    data = cursor.fetchone()
    if not data:
        return None
    return Comment(data[0], data[1], data[2], data[3], data[4],
                   userid_to_object(data[1]).username)
Exemplo n.º 10
0
    def post(self, post_id):
        if self.user_logged_in(self.user):
            newComment = self.request.get("comment")
            if not newComment:
                self.render("permalink.html",
                            content=newComment,
                            error="enter valid content")
                return

            # create a new comments row and update the Comment entity
            c = Comment(user_id=str(self.user.key().id()),
                        post_id=post_id,
                        comment=newComment,
                        author=self.user.name)
            c.put()

            post = self.post_exists(post_id)
            if post:
                postComm = Comment.all().filter('post_id =',
                                                post_id).order('-created')
                self.render("permalink.html", post=post, comments=postComm)
Exemplo n.º 11
0
 def get(self, post_id):
     if self.user_logged_in(self.user):
         post = self.post_exists(post_id)
         if post:
             if self.users_own_post(self.user, post):
                 self.render("editpost.html",
                             subject=post.subject,
                             content=post.content)
             else:
                 postComm = Comment.all().filter('post_id =', post_id)
                 self.render(
                     "permalink.html",
                     post=post,
                     error="You don't have access to edit this record.",
                     comments=postComm)
Exemplo n.º 12
0
    def get(self, comm_id):
        if not self.user_logged_in(self.user):
            return

        comment = self.comment_exists(comm_id)
        if not comment:
            return

        post_id = comment.post_id
        post = self.post_exists(post_id)
        if not post:
            return

        if int(comment.user_id) == self.user.key().id():
            comment.delete()
            postComm = Comment.all().filter('post_id =', post_id)
            self.render("permalink.html", post=post, comments=postComm)
        else:
            postComm = Comment.all().filter('post_id =', post_id)
            self.render(
                "permalink.html",
                post=post,
                error="You can only delete the comments posted by you.!",
                comments=postComm)
Exemplo n.º 13
0
 def get(self, post_id):
     if self.user_logged_in(self.user):
         post = self.post_exists(post_id)
         if post:
             if self.users_own_post(self.user, post):
                 post.delete()
                 posts = greetings = Post.all().order('-created')
                 self.redirect('/blog/')
             else:
                 postComm = Comment.all().filter('post_id =', post_id)
                 self.render(
                     "permalink.html",
                     post=post,
                     error="You don't have access to delete this record.",
                     comments=postComm)
Exemplo n.º 14
0
async def api_create_comment(id, request, *, content):
    user = request.__user__
    if user is None:
        raise APIPermissionError('please signin first.')
    if not content or not content.strip():
        raise APIValueError('content')
    blog = await Blog.find(id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    comment = Comment(blog_id=blog.id,
                      user_id=user.id,
                      user_name=user.name,
                      user_image=user.image,
                      content=content.strip())
    await comment.save()
    return comment
Exemplo n.º 15
0
    def post(self):
        if not self.user:
            return self.redirect('/blog')

        subject = self.request.get('subject')
        content = self.request.get('content')

        if subject and content:
            p = Post(parent=blog_key(), subject=subject, content=content)
            p.user_id = str(self.user.key().id())
            p.put()
            postComm = Comment.all().filter('post_id =', p.key().id())
            self.render("permalink.html", post=p, comments=postComm)
        else:
            error = "subject and content, please!"
            self.render("newpost.html",
                        subject=subject,
                        content=content,
                        error=error)
Exemplo n.º 16
0
async def api_create_comment(id, request, *, content):
    # 对某个博客发表评论
    user = request.__user__
    # 必须为登陆状态下,评论
    if user is None:
        raise APIPermissionError('content')
    # 评论不能为空
    if not content or not content.strip():
        raise APIValueError('content')
    # 查询一下博客id是否有对应的博客
    blog = await Blog.find(id)
    # 没有的话抛出错误
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    # 构建一条评论数据
    comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name,
                      user_image=user.image, content=content.strip())
    # 保存到评论表里
    await comment.save()
    return comment
Exemplo n.º 17
0
    def get(self, comm_id):
        if not self.user_logged_in(self.user):
            return

        comment = self.comment_exists(comm_id)
        if not comment:
            return

        post = self.post_exists(comment.post_id)
        if not post:
            return
        postComm = Comment.all().filter('post_id =',
                                        comment.post_id).order('-created')

        if int(comment.user_id) == self.user.key().id():
            self.render("editcomment.html",
                        post=post,
                        content=comment.comment,
                        comment=comment)
        else:
            self.render("permalink.html",
                        post=post,
                        error="You can only edit the comments posted by you.!",
                        comments=postComm)
Exemplo n.º 18
0
 def get(self, post_id):
     if self.user_logged_in(self.user):
         post = self.post_exists(post_id)
         if post:
             postComm = Comment.all().filter('post_id =', post_id)
             self.render("permalink.html", post=post, comments=postComm)
Exemplo n.º 19
0
from coroweb import get, post