Ejemplo n.º 1
0
Archivo: weibo.py Proyecto: fxyan/Dawn
def delete(request):
    weibo_id = int(request.query['weibo_id'])
    Weibo.delete(weibo_id)
    comments = Comment.all(weibo_id=weibo_id)
    for comment in comments:
        Comment.delete(comment.id)
    return redirect('/weibo')
Ejemplo n.º 2
0
def change_ticket_status():
    userInfo = session.get('userProfile')

    # Fetch all required information from the front end
    ticket_id = request.form.get('ticketid')
    project_id = request.form.get('projectid')
    status = request.form.get('status')
    t_date = DATE

    # Fetch the ticket from the backend by the ticket_id
    ticket = Ticket.query.get(ticket_id)

    # if status changed that record it to ticket_history, notification table and add a comment
    if ticket.t_status != status:
        new_id = db.session.query(func.max(Ticket_history.id))
        if new_id[0][0] == None:
            new_id[0][0] = 0

        ticket_history = Ticket_history(new_id[0][0] + 1, ticket_id,
                                        ticket.users_id, status, t_date,
                                        ticket.t_priority)
        try:
            ticket_history.insert()
        except:
            print(sys.exc_info())
            abort(500)

        project_user = Map_users_proj.query.with_entities(
            Map_users_proj.users_id).filter(
                Map_users_proj.p_id == project_id).all()
        for p in project_user:
            notify = Notification(ticket_id, p, type='update')
            try:
                notify.insert()
            except:
                print(sys.exc_info())
                abort(500)

        comment = "Status changed to " + status
        new_id = db.session.query(func.max(Comment.c_id))
        if new_id[0][0] == None:
            new_id[0][0] = 0

        comment = Comment(new_id[0][0] + 1, ticket_id, userInfo['id'], t_date,
                          comment)
        try:
            comment.insert()
        except:
            print(sys.exc_info())
            abort(500)

    # if updated status = closed than update the close_date in the ticket table
    if ticket.t_status != status and status == "closed":
        ticket.t_close_date = t_date

    # finally update the status in the ticket table
    ticket.t_status = status
    ticket.update()

    return redirect('/ticket-details/' + str(ticket_id))
Ejemplo n.º 3
0
    def post(self, post_id):
        a = Article.check_if_valid_post(post_id)
        if a:
            if self.user:
                key = db.Key.from_path('Article',
                                       int(post_id),
                                       parent=blog_key())
                a = db.get(key)
                comment = self.request.get('comment')
                created_by = self.user.name

                if comment:
                    c = Comment(parent=blog_key(),
                                comment=comment,
                                post_id=int(post_id),
                                created_by=created_by)
                    c.put()

                    comments = db.GqlQuery(
                        "select * from Comment where post_id = " + post_id +
                        " order by created desc")
                    self.render("permalink.html", a=a, comments=comments)
            else:
                self.redirect('/blog/login')
        else:
            self.error(404)
            return
Ejemplo n.º 4
0
    def get(self, post_id):
        post = Post.getById(post_id)

        if not post:
            self.error(404)
            self.write(
                "<h1>404 Not Found</h1>The resource could not be found.")
            return

        comments = Comment.getByPostID(post_id)
        comments_count = Comment.countByPostID(post_id)

        likes_num = Like.countByPostID(post_id)
        # Get post status (liked or not) by a specific user
        like_btn_txt = "Like"
        if self.user:
            if Like.getByPostAndAuthor(post_id, self.user.name):
                like_btn_txt = "Unlike"

        self.render("post.html",
                    post=post,
                    comments_count=comments_count,
                    comments=comments,
                    likes_num=likes_num,
                    like_text=like_btn_txt)
Ejemplo n.º 5
0
def delete():
    weibo_id = int(request.args.get('id'))
    w = Weibo.remove(weibo_id)
    comments = Comment.find_all(weibo_id=weibo_id)
    for comment in comments:
        Comment.remove(comment.id)
    return jsonify(w.json())
Ejemplo n.º 6
0
def download_comments_to_database():
    with open('data/comment.json', 'r') as jsonfile:
        data = json.load(jsonfile)

    for datum in data:
        Comment.create(email_address=None,
                       type_of_organization=datum.get('Type of Organization'),
                       name=datum.get('Name'),
                       text=datum.get('Comment').replace('_x000D_', ' '))
Ejemplo n.º 7
0
    def post(self, blog_id):
        if not self.user:
            self.redirect("/login")

        user_id = self.request.cookies.get('user_id').split('|')[0]
        commentstr = self.request.get('comment')
        com = Comment(user_id=user_id, blog_id=blog_id, comment=commentstr)
        com.put()

        self.redirect("/blog/")
Ejemplo n.º 8
0
    def post(self, post_id):
        if not self.user:
            self.render('/login')
            return

        comment_text = self.request.get("comment_text")
        # check if there is anything entered in the comment text area
        if comment_text:
            # add comment to the comments database and refresh page
            Comment.create(post_id, comment_text, self.user.name)
            time.sleep(0.1)
            self.redirect('/post/' + post_id)
Ejemplo n.º 9
0
 def post_comment_in_loc(loc):
     state = CommentToggle.get_state(loc)
     if state is None:
         abort(404)
     elif not state:
         abort(403, 'comments are disabled')
     new_comment = Comment(username=request.json['username'],
                           email=request.json.get('email', ''),
                           text=request.json['text'],
                           loc=loc)
     db.session.add(new_comment)
     # TODO: Akismet
     db.session.commit()
     return api_jsonify(new_comment.to_dict())
Ejemplo n.º 10
0
def create_comment():
    new = Comment()
    try:
        new.who = request.form["who"]
        new.target = request.form["target"]
        new.created_time = datetime.now()
        new.text = request.form["text"]

        db.session.add(new)
        db.session.commit()
    except KeyError:
        return jsonify({"result": "fail", "description": "create_commnet"}), 400

    return jsonify({"result": "succese", "description": "create_comment"})
def start_commentary():
    global match_start_time, match_end_time, last_comment

    current_time = TimeUtils.get_current_time()
    match_start_time = current_time.replace(
        hour=properties.MATCH_START_HOURS,
        minute=properties.MATCH_START_MINUTES,
        second=0,
        microsecond=0)
    match_end_time = current_time.replace(hour=properties.MATCH_END_HOURS,
                                          minute=properties.MATCH_END_MINUTES,
                                          second=0,
                                          microsecond=0)
    last_comment = Comment("None", "No comment yet...")
    URL = "https://web.whatsapp.com"

    if (properties.BROWSER.lower() == "safari"):
        driver = webdriver.Safari()
    elif (properties.BROWSER.lower() == "chrome"):
        driver = webdriver.Chrome("../chromedriver")
    elif (properties.BROWSER.lower() == "firefox"):
        driver = webdriver.Firefox()
    else:
        error_message = "Web browser should be one of Safari/Chrome/Firefox"
        LOGGER.error_with_time(error_message)

        return

    driver.get(URL)

    user_input = input(
        "Enter the names of the groups/users you want to text, separated by commas(Eg. - Arya Stark, Sansa Stark, Jon Snow, Bran, Rickon, Robb) : "
    )
    names = [x.strip() for x in user_input.split(',')]
    scheduler(driver, names)
Ejemplo n.º 12
0
    def get(self, post_id):
        """
        Renders the post.html template with the requested post
        """
        current_user = self.authenticate_user()

        if not post_id:
            self.render("post.html", error="No post id provided")
        else:
            post = Post.get_by_id(long(post_id))

            if not post:
                self.render("post404.html")
            else:
                user = User.get_by_id(post.user.id())
                comments = Comment.query().filter(Comment.post == post.key).fetch()
                likes = Like.query(Like.post == post.key).fetch()
                like = Like.query(
                    Like.user == current_user.key,
                    Like.post == post.key).get()

                self.render(
                    "post.html",
                    post=post,
                    current_user=current_user,
                    user=user,
                    like_count = len(likes),
                    like=like,
                    comments=comments)
Ejemplo n.º 13
0
def update():
	data = request.json
	comment_id = int(data.get('id', -1))
	c = Comment.find_by(id=comment_id)
	c.content = data.get('content')
	c.save()
	return jsonify(c.json())
Ejemplo n.º 14
0
    def post(self, comment_id):
        """
        Attempt to create a new blog post
        """
        current_user = self.authenticate_user()

        if not current_user:
            self.redirect("/login")
        else:
            content = self.request.get("content")
            comment = Comment.get_by_id(long(comment_id))

            if not comment:
                self.redirect("/post/" + str(comment.post.id()))
            elif current_user.key != comment.user:
                self.redirect("/post/" + str(comment.post.id()))
            elif not content:
                self.render_front(
                    comment_id, content,
                    "Your comment does not contain any content.")
            else:
                comment.content = content
                comment.put()

                self.redirect("/post/" + str(comment.post.id()))
Ejemplo n.º 15
0
def add():
	u = current_user()
	form = request.json
	form['user_id'] = u.id
	form['username'] = u.username
	c = Comment.new(form)
	c.save()
	return jsonify(c.json())
Ejemplo n.º 16
0
def assign_dev_ticket():

    userInfo = session.get('userProfile', 'not set')
    if userInfo['role'] != 'dev':
        abort(401)
    # Fetch the ticket that is to be assigned and assign the developer to it
    ticket = Ticket.query.get(request.form.get('ticket_id'))
    ticket.users_id = request.form.get('user_name')
    ticket.update()

    #insert Ticket History of assign the Devloper
    new_id = db.session.query(func.max(Ticket_history.id))
    if new_id[0][0] == None:
        new_id[0][0] = 0
    ticket_history = Ticket_history(new_id[0][0] + 1, ticket.t_id,
                                    ticket.users_id, ticket.t_status, DATE,
                                    ticket.t_priority)
    try:
        ticket_history.insert()
    except:
        print('error')

    #insert comment of which User assigned the Dev
    userInfo = session.get('userProfile', 'not set')
    user1 = userInfo['id']
    user2 = Users.query.with_entities(
        Users.users_name).filter(Users.users_id == ticket.users_id).one()
    text = user2[0] + ' assigned to this ticket'
    new_id = db.session.query(func.max(Comment.c_id))
    if new_id[0][0] == None:
        new_id[0][0] = 0
    comment = Comment(new_id[0][0] + 1, ticket.t_id, user1, DATE, text)
    try:
        comment.insert()
    except:
        print(sys.exc_info())

    #Insert notification for assignnig the Dev
    notify = Notification(ticket.t_id, ticket.users_id, 'assigned')
    try:
        notify.insert()
    except:
        print(sys.exc_info())

    return redirect('/ticket-details/' + request.form.get('ticket_id'))
Ejemplo n.º 17
0
def add_comment():
    ticket_id = request.form.get('ticket_id')
    comment = request.form.get('comment')
    date = DATE
    users_id = Users.query.with_entities(Users.users_id).filter_by(
        users_email=session.get('userProfile')['email'])

    new_id = db.session.query(func.max(Comment.c_id))
    if new_id[0][0] == None:
        new_id[0][0] = 0

    comment = Comment(new_id[0][0] + 1, ticket_id, users_id, date, comment)
    try:
        comment.insert()
    except:
        print(sys.exc_info())
        abort(500)
    return redirect('/ticket-details/' + ticket_id)
Ejemplo n.º 18
0
def add_comment():
    data = request.json
    user_id = current_user.get_id()
    author = db.session.query(User).get(user_id)
    print(data)
    c = Comment(user_id=author.id, username=author.username, post_id=data["post_id"], body=data["body"])
    db.session.add(c)
    db.session.commit()
    return jsonify('', render_template('feed/feed.html.jinja2'))
Ejemplo n.º 19
0
 def get(self, post_id, comment_id):
     if self.user:
         c = Comment.check_if_user_owns_comment(comment_id, self.user.name)
         if c:
             c.delete()
             self.redirect('/blog/%s' % post_id)
         else:
             error = "Oops, this is not your comment"
             self.render("error.html", error=error)
Ejemplo n.º 20
0
    def post(self, post_id, posts):
        content = self.request.get('content')
        name = self.user.name
        # created = self.request.get('created')

        # key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        # posts = db.get(key)
        # if posts is None:
        #    return self.redirect('/blog')
        if content:
            c = Comment(comment=content,
                        name=name,
                        post_id=posts,
                        postId=int(post_id))
            c.put()
            return self.redirect('/blog')
        else:
            error = "content is required"
            self.render('comment.html', content=content, error=error)
Ejemplo n.º 21
0
def sub_comment():
    text = request.values.get('text')
    name = request.values.get('name')
    mail = request.values.get('mail')
    a_id = request.values.get('a_id')
    if name and mail and text and a_id:
        db.session.add(Comment(Article_id=a_id, name=name, content=text, mail=mail))
        db.session.commit()
        return '0'
    else:
        return '1'
Ejemplo n.º 22
0
def reset_database():
    # Delete 'emails.db' sqlite database
    if os.path.exists('emails.db'):
        os.remove('emails.db')
        logger.info("Deleted database 'emails.db'")

    # Re-create 'emails.db' sqlite database
    db = SqliteDatabase('emails.db')
    logger.info("Created database 'emails.db'")
    Email.create_table()
    SenderMetadata.create_table()
    Comment.create_table()
    Form.create_table()
    Category.create_table()

    Category(name="Meetings").save()
    Category(name="Opinions").save()
    Category(name="Question").save()
    Category(name="Action").save()
    Category(name="Thank You").save()
Ejemplo n.º 23
0
 def post(self):
     arg_data = json.loads(self.get_argument('data'))
     user_info = self.session['index_user'].to_json()
     data = {
         "UserID": user_info['UserID'],
         "ProductID": arg_data['pid'],
         "Content": arg_data['user_comment_content'],
         "Status": False
     }
     obj = Comment(**data)
     session.add(obj)
     session.commit()
     self.write_json(u"新增成功、审核成功后即可显示!", code=1)
Ejemplo n.º 24
0
 def post(self, post_id, comment_id):
     if not self.user:
         self.render("/login")
         return
     
     # get the comment from the comment id
     comment = Comment.get_by_id(int(comment_id))
     # check if there is a comment associated with that id
     if comment:
         # check if this user is the author of this comment
         if comment.author == self.user.name:
             # delete the comment and redirect to the post page
             Comment.delete(comment_id)
             time.sleep(0.1)
             self.redirect('/post/%s' % str(post_id))
         # otherwise if this user is not the author of this comment throw an
         # error
         else:
             self.write("You cannot delete other user's comments")
     # otherwise if there is no comment associated with that id throw an
     # error
     else:
         self.write("This comment no longer exists")
Ejemplo n.º 25
0
def add(form):
    result = dict(success=False)
    res = comment_schema.load(form)
    if res.errors == {}:
        result['success'] = True
        c = Comment.new(res.data)
        user = c.user
        data = dict(comment=comment_schema.dump(c).data,
                    user=user_schema.dump(user).data)
        result['data'] = data
        create_notify(c.post, user)
        subscribe_comment(c, user)
    result['message'] = res.errors
    return result
Ejemplo n.º 26
0
    def post(self, post_id):
        """
        Handles the post request from the post page. This is the comment submission.
        """
        content = self.request.get("content")
        current_user = self.authenticate_user()

        post = Post.get_by_id(long(post_id))

        if not post:
            self.render("post404.html")
        else:
            user = User.get_by_id(post.user.id())
            comments = Comment.query().filter(Comment.post == post.key).fetch()

            if not current_user:
                self.redirect("/login")
            elif not content:
                self.render("post.html",
                    comments=comments,
                    post=post,
                    current_user=current_user,
                    user=user,
                    error="No comment text was received")
            else:
                comment = Comment(content=content, user=current_user.key, post=post.key)
                comment.put()
                current_user.comments.append(comment.key)
                current_user.put()

                self.render(
                    "post.html",
                    post=post,
                    user=user,
                    current_user=current_user,
                    comments=comments)
Ejemplo n.º 27
0
    def post(self, post_id, comment_id):
        a = Article.check_if_valid_post(post_id)
        c = Comment.check_if_user_owns_comment(comment_id, self.user.name)
        if a and c:
            comment = self.request.get('comment')
            if comment:
                c.comment = comment
                c.put()
                self.redirect('/blog/%s' % post_id)
            else:
                error = "Please input comment"
                self.redner("comment.html", error=error, c=c)

        else:
            error = "Oops, this is not your comment"
            self.render("error.html", error=error)
Ejemplo n.º 28
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
Ejemplo n.º 29
0
    def post(self, comment_id):
        '''
        Deletes the comment if the current
        user is the author of the comment
        '''
        current_user = self.authenticate_user()

        if not current_user:
            self.redirect("/login")
        else:
            comment = Comment.get_by_id(long(comment_id))

            if comment and comment.user == current_user.key:
                remove_user_comment(current_user, comment)
                comment.key.delete()

            self.redirect(self.request.referer)
Ejemplo n.º 30
0
def create_comment(id):
    req_data = request.get_json()
    data, errors = comment_schema.load(req_data)

    if errors:
        return jsonify({'errors': errors}), 422

    comment = Comment(data)
    comment.cocktail_id = id
    comment.user_id = g.get('user').id
    comment.save()

    return comment_schema.jsonify(comment)
Ejemplo n.º 31
0
    def render_front(self, comment_id="", content="", error=""):
        """
        Simplify the rendering of the new post template
        """
        current_user = self.authenticate_user()
        comment = Comment.get_by_id(long(comment_id))
        user = User.get_by_id(comment.user.id())

        if not content:
            content = comment.content

        if not current_user:
            self.redirect("/login")
        elif current_user.key != comment.user:
            self.write("You are not the author of this comment")
        else:
            self.render("edit_comment.html",
                        content=content,
                        error=error,
                        user=user,
                        current_user=current_user)