コード例 #1
0
ファイル: sorter.py プロジェクト: qdonnellan/speculess
def sortComments(lensID, sortMethod = None, forceRefresh = False, numToGet = 12):
	comments = getComments(lensID)
	commentList = []	

	if sortMethod == 'random':
		for comment in comments:
			commentList.append(comment)
		comments = random.sample(commentList,min(numToGet, len(commentList)))

	elif sortMethod == 'latest':
		comments = sorted(comments, key=operator.attrgetter('created'), reverse=True)

	else:		
		for comment in comments:
			objectKey = 'likesFor' + lensID + comment.userID
			commentList.append([getObjectLikes(objectKey),comment])
		commentList = sorted(commentList, key=operator.itemgetter(0), reverse=True)

		comments = []
		for item in commentList:
			comments.append(item[1])

	if numToGet is not None:
		comments = comments[0:numToGet]	
	return comments
コード例 #2
0
ファイル: renderClasses.py プロジェクト: qdonnellan/speculess
def formatComment(comment, localUser):
	comment.userNickname = getNickname(comment.userID)
	comment.userRating = getUserRating(comment.userID)	
	if comment.reviewLink is None or comment.reviewLink == '':
		comment.reviewDisplay = 'none'
	else:
		comment.reviewDisplay = 'visible'			
	objectKey = 'likesFor' + comment.lensID + comment.userID
	comment.count = getObjectLikes(objectKey)
	if userLikedObject(localUser, objectKey):
		comment.buttonStyle = 'btn-primary'
		comment.buttonTooltip = 'You found this impression useful. Click again to undo'					
	else:
		comment.buttonStyle = 'btn'
		comment.buttonTooltip = 'Is this impression useful? Click to recommend'
	if comment.created is not None:
		comment.time = comment.created.strftime('%d %B %Y')
	else:
		comment.time = '0'
	return comment