예제 #1
0
파일: posts.py 프로젝트: Edin93/old_Mynd
def post_comments(post_id):
    """Get the comments of a post, or adds a comment"""
    post = storage.get(Post, post_id)
    if not post:
        return ClientError(404, 'Post not found', 'Not Found')
    user = storage.get(User, post.user_id)
    if request.method == 'GET':
        d = {'Post owner': user.username, 'Post id': post_id, 'number of comments': len(post.comments), 'comments': []}
        for comment in post.comments:
            dc = {'comment id': comment.id,
                  'written by': storage.get(User, comment.user_id).username,
                  'content': comment.text}
            d['comments'].append(dc)
        return jsonify(d)
    if not request.get_json():
        return ClientError(400, 'Not a JSON', 'Invalid')
    comment = Comment()
    comment.user_id = current_identity['id']
    comment.post_id = post_id
    if 'text' in request.get_json() and request.get_json()['text'].strip() != "":
        comment.text = request.get_json()['text']
    elif 'content' in request.get_json() and request.get_json()['content'].strip() != "":
        comment.text = request.get_json()['content']
    else:
        return ClientError(400, 'Empty comments are not allowed', 'Error')
    comment.save()
    return {"status_code": 1, "info": "Created"}
예제 #2
0
 def post(self):
     logging.debug("Inside Comment handler Post method")
     data = json.loads(self.request.body)
     comment = data['comment']
     blogId = data['blogId']
     if self.isvalid_login():
         # TODO: Refactor to getUser Method Later to get user object
         user_id = self.getCookieValue("user_id")
         user = User.get_by_id(int(user_id))
         # TODO: Refactor to getBlogbyId method to getBlogData Object
         blogId = data['blogId']
         blogData = BlogData.by_id(int(blogId))
         if blogData:
             comment = Comment(commenttext=comment,
                               user=user,
                               blog=blogData)
             comment.put()
             self.response.out.write(
                 json.dumps(({
                     'commenttext': comment.commenttext
                 })))
         else:
             self.response.out.write(
                 json.dumps(({
                     'error': "This Blog doesnt Exists"
                 })))
     else:
         logging.debug("Redirect to login")
         self.response.out.write(json.dumps(({'redirect': 'true'})))
예제 #3
0
def create(thread_id):
    comment = request.get_json()

    comment_text = comment["text"]
    comment_user = comment["user"]

    new_comment = Comment(
        text=comment_text, thread=thread_id, user=comment_user)
    if new_comment.save():
        # xtra_info = Comment.get_by_id(Comment.id == new_comment.id)
        return jsonify({
            'message': 'new comment created!',
            'status': 'success',
            'data' : {
                        'user': new_comment.user.id,
                        'text': new_comment.text,
                        'thread': new_comment.thread.id,
                        'created_at': new_comment.created_at,
                        'updated_at': new_comment.updated_at,
                        # 'info' : xtra_info,
                        
            }
            
        }), 200
    else:
        return jsonify({'message': 'comment create failed'}), 400
예제 #4
0
    def post(self, topicid):
        user = users.get_current_user()

        if not user:
            return self.write("Please, login before")

        csrf_token = self.request.get("paco")
        mem_token = memcache.get(key=csrf_token)

        if not mem_token:
            return self.write("This website es protected")

        comment_value = self.request.get("comment")

        if "<script>" in comment_value:
            return self.write("No Hack script")

        if not comment_value:
            return self.write("Required")

        topic = Topic.get_by_id(int(topicid))

        new_comment = Comment(
            content=comment_value,
            author_email=user.email(),
            topicid=topic.key.id(),
            topic_title=topic.title
        )

        new_comment.put()

        return self.redirect_to("topic-detail", topicid=topic.key.id())
예제 #5
0
def get_all_comments():
    with sqlite3.connect("./rare.db") as conn:
        conn.row_factory = sqlite3.Row
        db_cursor = conn.cursor()

        db_cursor.execute("""
            SELECT
                c.id, 
                c.post_id, 
                c.author_id, 
                c.content,
                c.created_on
            FROM Comments c
        """)

        comments = []

        data = db_cursor.fetchall()

        for row in data:
            comment = Comment(row['id'], row['post_id'], row['author_id'],
                              row['content'], row['created_on'])
            comments.append(comment.__dict__)

        return json.dumps(comments)
예제 #6
0
    def post(self):
        """Check if content is not empty and register it.

        If content is empty, render post page with error.
        """
        content = self.request.get('content')
        post_id = self.request.get('post_id')

        if post_id:
            try:
                post = Post.get_by_id(int(post_id))
            except ValueError:
                return self.redirect('/blog')

        if content:
            comment = Comment(user=self.user, post=post, content=content)
            comment.put()

            # Delay for DB processing.
            time.sleep(0.1)

            return self.redirect('/blog/%s' % post.key().id())
        else:
            error = 'Comment is needed'
            self.render('permalink.html', post=post, error=error)
예제 #7
0
  def get_comments(self, placeId, store_name, store_id):
    page = 1
    display = 10
    url = "https://store.naver.com/sogum/api/receiptReviews?businessId=%s&page=%d&display=%d"
    
    comments = []
    is_exist = False

    while True:
      res = rq.get(url%(store_id, page, display), headers = {
        'Referer': 'https://store.naver.com/restaurants/detail?entry=plt&id=%s&tab=receiptReview'%(store_id),
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"
      })
      res_data = res.json()
      res_comments = res_data.get('items', [])
      for res_comment in res_comments:
        C = Comment(
          placeId, store_id, self.platform, 
          res_comment['authorId'], encode_sha2(res_comment['body']), res_comment['body'], res_comment['rating']
        )
        is_exist = C.is_exist_comment()
        print(is_exist)
        if not is_exist:
          comments.append(C)
        if is_exist:
          break
      
      page += 1

      if len(res_comments) < display or is_exist:
        break

    return comments
예제 #8
0
파일: issue.py 프로젝트: vedsofie/SPNv2
def unfollow_issue(issue_id):
    follow = Follower.query.filter(Follower.FollowerID == issue_id).first()
    if follow.Type == 'Forums':
        forum = Forum.query.filter_by(ForumID=follow.ParentID).first()
        can_unfollow = forum.AccountID != SOFIEBIO_ACCOUNTID or g.user.AccountID == SOFIEBIO_ACCOUNTID
        owner = forum.AccountID == g.user.AccountID

        if owner:
            msg = 'Unfollowing case'
            comment = Comment(UserID=g.user.UserID,
                              Message=msg,
                              Type='Forums',
                              ParentID=forum.ForumID)
            comment.save()

        if can_unfollow:
            db.session.delete(follow)
            db.session.commit()
            return "OK"
    else:
        db.session.delete(follow)
        db.session.commit()
        return "OK"

    return Response("Cannot Unfollow", 401)
예제 #9
0
파일: issue.py 프로젝트: vedsofie/SPNv2
def do_close_issue(issue_id, user):
    follower = Follower.query.filter(Follower.FollowerID == issue_id).first()
    if follower.Type == 'Forums':
        forum = Forum.query.filter(Forum.ForumID == follower.ParentID).first()
        can_close = user.AccountID == SOFIEBIO_ACCOUNTID

        if can_close:
            """
            followings = Follower.query.filter(and_(Follower.ParentID == forum.ForumID,
                                                    Follower.Type=='Forums')).all()
            for following in followings:
                if following.user.AccountID == SOFIEBIO_ACCOUNTID:
                    db.session.delete(following)
                elif forum.AccountID == following.user.AccountID and user.AccountID != forum.AccountID:
                    pass
                else:
                    db.session.delete(following)
            """
            msg = 'Closing Case'
            print msg
            comment = Comment(UserID=user.UserID,
                              Message=msg,
                              Type='Forums',
                              ParentID=follower.ParentID)
            comment.save()
            forum.ReadOnly = True
            forum.close_salesforce_case()
            db.session.add(forum)
            db.session.commit()
            return True
    return False
예제 #10
0
    def post(self):
        data = Comments.parser.parse_args()
        comment = Comment(**data)

        print(comment.comment)

        return comment.json()
예제 #11
0
    def post(self, post_id):
        #comment
        content = self.request.get('content')

        #check if post exists
        if not self.post_exists(post_id):
            page_error = 'This post does not exist !'
            return self.render('login-form.html', page_error = page_error)

        #Check if user is logged in
        if self.user:
            u = self.user.name
            author = User.by_name(u)

            post = Post.by_id(post_id)

            #Check if user wrote comment
            if content:
                c = Comment(author = author, post = post, content = content )
                c.put()
                time.sleep(0.1)
                self.redirect('/%s' %str(c.post.key().id()))

            else:
                page_error = "content, please!!"
                self.render('permalink.html', page_error = page_error, post = post)


        #User is redirected to login
        else:
            page_error = "You must login in to comment!"
            self.render('login-form.html', page_error = page_error)
예제 #12
0
파일: app.py 프로젝트: hoangcuong9x/test
def view(picid):
    pic = Savepicture.objects(id=picid).first()
    artist = User.objects(username=pic.picartist).first()
    comment_list = Comment.objects(picid=picid)
    if request.method == 'GET':
        return render_template("view.html",
                               pic=pic,
                               artist=artist,
                               comment_list=comment_list)
    else:
        form = request.form
        comment = form['comment']
        warning = ''
        if 'token' in session:
            user = User.objects(username=session['token']).first()
            new_comment = Comment(comment=comment,
                                  who_fullname=user.fullname,
                                  who_username=user.username,
                                  picid=picid)
            if comment == '':
                warning = 'Bạn chưa viết gì nên không có gì để đăng!'
            else:
                new_comment.save()
        else:
            warning = 'Vui lòng đăng nhập để like & comment!'
        return render_template('view.html',
                               pic=pic,
                               artist=artist,
                               comment_list=comment_list,
                               warning=warning)