Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #6 from David-Logsdon/refinemodel

Added some functionality to comments
  • Loading branch information...
commit 69703e85caf5f3119686ab6a7936c5f2725132f5 2 parents 43deca9 + ebe10f4
@mark-up mark-up authored
Showing with 35 additions and 7 deletions.
  1. +35 −7 udacious/apps/comments/handlers.py
View
42 udacious/apps/comments/handlers.py
@@ -1,22 +1,50 @@
import json
-
from google.appengine.ext import ndb
-
from lib.utils import login_required, slugify, valid_slug
from lib.basehandler import BaseHandler
-from models import import Comment
+import models
+
def get_comments_by_url(url, limit=10, json=False):
''' returns an array of comments (or None) related to url '''
- # How to deal with nested comments?
- return
+ comments = Comment.comments_by_url(url, limit)
+ # TBD re-factor this functionality.
+ nested_comments = []
+ if comments:
+ for comment in comments:
+ nested_comments.append(comment)
+ child_comments = get_child_comments(int(comment.key.id()))
+ if child_comments:
+ nested_comments.append(child_comments)
+ if not json:
+ return nested_comments
+ return json.dumps(nested_comments)
+
def add_comment(url, user_id, content, parent=None):
''' add a comment to the url '''
return
+
def get_comments_by_user(user_id, limit=10, json=False):
- return
+ ''' Returns a list or json array of comments by the user '''
+ user_comments = Comment.user_comments(user_id, limit)
+ nested_comments = []
+ if comments:
+ for comment in user_comments:
+ nested_comments.append(comment)
+ child_comments = get_child_comments(int(comment.key.id()))
+ if child_comments:
+ nested_comments.append(child_comments)
+ if not json:
+ return nested_comments
+ return json.dumps(nested_comments)
+
def get_child_comments(parent_id, limit=10, json=False):
- return
+ children = Comment.child_comments(parent_id)
+ if children:
+ return children
+ else:
+ return
Please sign in to comment.
Something went wrong with that request. Please try again.