Beispiel #1
0
 def test_sharedfile_comments_returns_comments(self):
     sharedfile = self._post_to_shake(self.user_a)
     Comment.add(user=self.user_a, sharedfile=sharedfile, body="A comment")
     self.assertEqual(1, sharedfile.comment_count())
     url = self.get_url('/api/sharedfile/%s/comments' % sharedfile.id)
     response = api_request(self, url, method='GET')
     self.assertEqual(response.code, 200)
     j_response = json_decode(response.body)
     self.assertEqual(1, len(j_response['comments']))
     self.assertEqual("A comment", j_response['comments'][0]['body'])
Beispiel #2
0
 def post(self, post_id):
     if self.user:
         comment = self.get_form_value('comment')
         if comment:
             Comment.add(comment=comment,
                         user_id=str(self.user.key().id()),
                         post_id=post_id,
                         user_name=self.user.firstname).put()
             print('comment added')
         self.redirect('/posts/' + post_id)
     else:
         self.redirect('/login')
Beispiel #3
0
def add_comment(did):
    """Agrega un comentario a un dispositivo como seguimiento del eventos
    asociados al mismo"""
    form = forms.CommentForm(request.form)
    if request.method == 'POST' and form.validate():
        comment = Comment(session['user_id'], did, form.comment.data)
        try:
            comment.add()
            flash(('success', 'Comentario guardado exitosamente!.'))
            return redirect(url_for('view_devices', did=did))
        except Exception as e:
            print(e)
            flash(('danger', 'Lo sentimos algo salio mal!.'))
            return redirect(url_for('view_devices', did=did))
    flash(('danger', 'Lo sentimos algo salio mal!.'))
    return redirect(url_for('view_devices', did=did))
Beispiel #4
0
 def test_as_json(self):
     """
     Make sure as_json returns comment body and user dict in the dict response.
     """
     comment = Comment.add(user=self.user, sharedfile=self.sharedfile, body='hello')
     comment_j = comment.as_json()
     self.assertEqual(comment_j['body'], comment.body)
     self.assertEqual(comment_j['user'], comment.user().as_json())
Beispiel #5
0
    def post(self, sharedfile_key):
        user = User.get('id = %s', int(self.oauth2_user_id))
        sharedfile = Sharedfile.get_by_share_key(sharedfile_key)
        if not sharedfile:
            self.set_status(404)
            return self.write({'error': 'No such file.'})

        body = self.get_argument('body', None)
        comment = Comment.add(user=user, sharedfile=sharedfile, body=body)
        if not comment:
            self.set_status(400)
            return self.write({'error': 'Could not save comment'})
        return self.write(comment.as_json())
Beispiel #6
0
    def post(self, share_key):
        shared_file = Sharedfile.get_by_share_key(share_key)
        if not shared_file:
            raise tornado.web.HTTPError(404)

        ajax = self.get_argument('ajax', False)
        body = self.get_argument('body', None)

        redirect_suffix = ""
        if ajax:
            # Prevent IE cache.
            self.set_header("Cache-Control","no-store, no-cache, must-revalidate");
            self.set_header("Pragma","no-cache");
            self.set_header("Expires", 0);
            redirect_suffix = "/quick-comments?expanded=1"

        user = self.get_current_user_object()
        if user and user.email_confirmed == 1:
            comment = Comment.add(user=user, sharedfile=shared_file, body=body)
        return self.redirect("/p/%s%s" % (share_key, redirect_suffix))
Beispiel #7
0
def add_comments():
    """
    Create db entries for comments
    :return:
    """
    comments = get_articles_comments(get_hot_article_ids(), get_ids=True)
    for index, comment in enumerate(comments):
        logger.info("[VIEW COMMENT {}]".format(index))
        comment_id, comment_text = comment
        print("[VIEW] Comment {}".format(index))

        comment_obj, created = Comment.add(comment_id, comment_text)
        if not created and comment_obj.text == comment_text:
            continue
        counted_words = get_words_count(comment_text)

        # delete old words
        if not created:
            words_to_delete = (
                db.session.query(WordsCount)
                .filter(
                    WordsCount.comment == comment_obj,
                    ~WordsCount.word.has(Word.text.in_([s[0] for s in counted_words])),
                )
                .all()
            )
            if words_to_delete:
                for word in words_to_delete:
                    db.session.delete(word)

        for word, count in counted_words:
            word_obj, created = Word.add(word)
            WordsCount.add(comment_obj, word_obj, count)

        db.session.commit()

    return render_template("stats.html", data=comments)