Beispiel #1
0
  def post(self, forum_id, post_reference):
    user = self.user_model
    post = ForumPost.query(ForumPost.forum_name == forum_id, ForumPost.reference == post_reference).get()
    text = cgi.escape(self.request.get('text'))
    sender = cgi.escape(self.request.get('sender'))
    recipient = cgi.escape(self.request.get('recipient'))
    replied_to_urlsafe = cgi.escape(self.request.get('parent'))
    comment = Comment(parent = post.key)
    if len(replied_to_urlsafe) != 0:
      replied_to_key = ndb.Key(urlsafe=replied_to_urlsafe)
      parent_comment = replied_to_key.get()
      comment.parent = replied_to_key
      comment.offset = parent_comment.offset + 20
      recipient_comment = ndb.Key(urlsafe=replied_to_urlsafe).get()
      comment.recipient = recipient_comment.sender
      comment.sender = user.username
      comment.root = False
    else:
      comment.sender = sender
      comment.recipient = recipient

    comment.text = text
    comment.time = datetime.datetime.now() - datetime.timedelta(hours=7) #For PST
    comment.put()

    if comment.root == False:
      parent_comment.children.append(comment.key)
      parent_comment.put()
      
    post.comment_count += 1
    post.put()
    self.redirect('/tech/{}/{}'.format(forum_id, post_reference))
Beispiel #2
0
 def get(self, forum_id):
   forum_id = forum_id.lower()
   user = self.user_model
   forum_posts = ForumPost.query(ForumPost.forum_name == forum_id)
   forum = Forum.query(Forum.name == forum_id).get()
   if user == None:
     override_base = "visitorBase.html"
   else:
     override_base = "base.html"
   self.response.out.write(template.render('views/forum.html', {'viewer': user,
                                     'posts': forum_posts, 'forum': forum, 'forum_name': forum_id, 
                                     'override_base': override_base}))
Beispiel #3
0
 def get(self, forum_id, post_reference):
     user = self.user_model_
     post = ForumPost.query(ForumPost.forum_name == forum_id,
                            ForumPost.reference == post_reference).get()
     comments = Comment.query(Comment.parent == post.key).order(
         Comment.time).fetch()
     self.render_google(
         'forumComments.html', {
             'viewer': user,
             'post': post,
             'forum_name': forum_id,
             'comments': comments
         })
Beispiel #4
0
 def post(self, topic_id):
     member = validate_member(self)
     if not member: 
         return True
     title = self.request.get('title')
     content = self.request.get('content')
     topic_id = int(topic_id)
     author = Member.get_by_user(users.get_current_user())
     topic_obj = validate_topic_id(self, topic_id)
     new_post = ForumPost(idx=next_post_idx(topic_obj),
                         title=title,
                         content=content,
                         author=author,
                         category=topic_obj.category)
     new_post.put()
     tail_post = topic_obj.tail_post
     tail_post.next_post = new_post
     topic_obj.tail_post = new_post
     topic_obj.put()
     tail_post.put()
     last_page = topic_obj.post_count / POSTS_PER_PAGE + 1
     self.redirect('/forum/%i/page/%i' % (topic_obj.key().id(), last_page))
Beispiel #5
0
 def post(self, category_code):
     member = validate_member(self)
     if not member:
         return True
     title = self.request.get('title')
     content = self.request.get('content')
     author = Member.get_by_user(users.get_current_user())
     category_obj = validate_category_code(self, category_code)
     new_topic = ForumTopic(idx=next_topic_idx(category_obj),
                         author=author,
                         category=category_obj)
     new_topic.put()
     new_post = ForumPost(idx=next_post_idx(new_topic),
                         title=title,
                         content=content,
                         author=author,
                         category=category_obj)
     new_post.put()
     new_topic.head_post = new_post
     new_topic.tail_post = new_post
     new_topic.put()
     self.redirect('/forum/' + str(new_topic.key().id()) + '/page/1')
Beispiel #6
0
 def get(self, forum_id):
     forum_id = forum_id.lower()
     user = self.user_model_
     forum_posts = ForumPost.query(ForumPost.forum_name == forum_id).order(
         ForumPost.time)
     forum = Forum.query(Forum.name == forum_id).get()
     self.render_google(
         'forum.html', {
             'viewer': user,
             'posts': forum_posts,
             'forum': forum,
             'forum_name': forum_id,
             'forum_aty': forum.aty
         })
Beispiel #7
0
 def post(self, forum_id, post_reference):
     user = self.user_model_
     post = ForumPost.query(ForumPost.forum_name == forum_id,
                            ForumPost.reference == post_reference).get()
     text = cgi.escape(self.request.get('text'))
     sender = cgi.escape(self.request.get('sender'))
     recipient = cgi.escape(self.request.get('recipient'))
     comment = Comment(parent=post.key)
     comment.text = text
     comment.sender = sender[3:-2]
     comment.recipient = recipient
     comment.time = datetime.datetime.now() - datetime.timedelta(
         hours=8)  #For PST
     comment.put()
     post.comment_count += 1
     post.put()
     self.redirect('/forum/{}/{}'.format(forum_id, post_reference))
Beispiel #8
0
def post_data():
    user_id = session['user_id']
    data = request.get_json()
    comment = data.get('comment')
    video_id = data.get('video_id')
    tag = data.get('tag')
    title = data.get('title')

    new_comment = ForumPost(title=title,
                            comment=comment,
                            user_id=user_id,
                            video_id=video_id,
                            tag=tag)
    db.session.add(new_comment)
    db.session.commit()

    return redirect(url_for('forum.forum_index'))
Beispiel #9
0
  def get(self, forum_id, post_reference):
    user = self.user_model
    post = ForumPost.query(ForumPost.forum_name == forum_id, ForumPost.reference == post_reference).get()
    comments = Comment.query(Comment.parent==post.key).fetch()
    # Get nested Comments
    index = 0
    while index < len(comments):
      children = Comment.query(Comment.parent == comments[index].key).fetch()
      index +=1
      comments[index:index] = children

    if user == None:
      override_base = "visitorBase.html"
    else:
      override_base = "base.html"
    self.response.out.write(template.render('views/forumComments.html',
      {'override_base':override_base, 'viewer': user, 'post':post,
      'forum_name':forum_id, 'comments':comments, 'post_reference':post_reference}))
Beispiel #10
0
 def post(self, forum_id):
   author = cgi.escape(self.request.get('author'))
   forum_name = cgi.escape(self.request.get('forum'))
   title = cgi.escape(self.request.get('title'))
   url = cgi.escape(self.request.get('url'))
   text = cgi.escape(self.request.get('text'))
   forums = forum_name.strip().replace(" ", "").split(",")
   for submissions in forums[0:3]:
     post = ForumPost()
     forum = Forum.query(Forum.name == submissions).get()
     if forum != None:
       forum.posts += 1
     else:
       forum = Forum(name=submissions, posts=1)
     forum.put()
     post.text = text
     post.author = author
     post.forum_name = submissions
     post.title = title
     post.time = datetime.datetime.now() - datetime.timedelta(hours=7) #For PST
     post.url = url
     post.url_host = urlparse(url).hostname
     post.reference = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(8))
     post.put()
   self.redirect('/tech/{}'.format(forums[0]))
Beispiel #11
0
 def post_list(self, offset_count):
   index = 0
   viewer = self.user_model
   posts = ForumPost.query(ForumPost.forum_name.IN(viewer.subscriptions)).order(-ForumPost.vote_count, -ForumPost.time).fetch(10, offset=offset_count)
   more = len(posts)
   return posts, more
Beispiel #12
0
    def post(self, forum_id):
        author = cgi.escape(self.request.get('author'))
        forum_name = cgi.escape(self.request.get('forum'))
        title = cgi.escape(self.request.get('title'))
        url = cgi.escape(self.request.get('url'))
        text = cgi.escape(self.request.get('text'))
        post = ForumPost()
        forum = Forum.query(Forum.name == forum_name).get()
        if forum != None:
            forum.posts += 1
        else:
            forum = Forum(name=forum_name, posts=1)
        forum.put()

        author = author[3:-2]
        post.text = text
        post.author = author
        post.forum_name = forum_name
        post.forumnyn_aty = forum.aty
        post.title = title
        post.time = datetime.datetime.now() - datetime.timedelta(
            hours=8)  #For PST
        post.url = url
        post.url_host = urlparse(url).hostname
        post.reference = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for _ in range(8))
        post.put()
        self.redirect('/forum/{}'.format(forum_name))
Beispiel #13
0
def validate_post_id(handler, post_id):
    post = ForumPost.get_by_id(post_id)
    if post:
        return post
    else:
        handler.redirect(sc_create_error("Unidentified Post ID."))