def viewTake(): response.view = 'takes/viewTake.html' takeId = request.vars.takeId if not(utilityFunctions.isTakeIdValid(takeId,db)): redirect(URL('default','index')) userId = (auth.user.id) if (auth.is_logged_in()) else 0 preSelectedTags = databaseQueries.getTakeTags(db, takeId) existingTags = "" for row in preSelectedTags: existingTags = existingTags + "<a href='" + URL('takes','tagFeed',vars=dict(tagId = row.tags.id)) + "'>" + row.tags.tagName + "</a>, " existingTags = existingTags + "end[]" existingTags = existingTags.replace(", end[]",".") row = databaseQueries.getTakeInfo(db, takeId) authorUserId = row.userId numberOfLikes = databaseQueries.getNumberOfLikes(db, takeId, "Take") isTakeLiked = databaseQueries.hasUserLikedArticle(db, takeId, "Take", userId) response.title = row.takeTitle response.subtitle = "Posted on " + str(row.timeOfTake) fields = [Field("commentContent","text")] form = SQLFORM.factory(*fields, labels = {"commentContent":""}, submit_button = "Comment") if form.process().accepted: redirect(URL('takes','postComment',vars=dict(takeId = takeId, commentContent = form.vars.commentContent))) elif form.errors: response.flash = 'Errors found in the form.' commentRows = databaseQueries.getTakeComments(db, takeId) isCommentLiked = [] commentLikeCount = [] for commentRow in commentRows: commentId = commentRow.comments.id isCommentLiked.append(databaseQueries.hasUserLikedArticle(db, commentId, "Comment", userId)) commentLikeCount.append(databaseQueries.getNumberOfLikes(db, commentId, "Comment")) editLink = "" deleteLink = "" if(databaseQueries.checkIfUserTakePairExists(db, userId , takeId)): editLink = URL('takes','editTake',vars=dict(takeId = takeId)) deleteLink = URL('takes','deleteTake',vars=dict(takeId = takeId)) textarea = form.element('textarea') textarea['_cols'] = 1000 textarea['_rows'] = 2 authorNumberOfFollowers = databaseQueries.getNumberOfFollowers(db, authorUserId) authorName = databaseQueries.getUserName(db, authorUserId) profilePicLink = databaseQueries.getUserProfilePicture(db, authorUserId, None) return dict(takeId = takeId, takeContent = row.takeContent, numberOfLikes = numberOfLikes, editLink = editLink, deleteLink = deleteLink, isTakeLiked = isTakeLiked, form = form, comments = commentRows, isCommentLiked = isCommentLiked, existingTags = existingTags, commentLikeCount = commentLikeCount, profilePicLink = profilePicLink, authorUserId = authorUserId, authorNumberOfFollowers = authorNumberOfFollowers, authorName = authorName)
def changeLikeStatus(): userId = auth.user.id articleType = request.vars.articleType articleId = request.vars.articleId if (not(utilityFunctions.checkIfVariableIsInt(articleId))): return "Invalid" if not(databaseQueries.checkIfArticleExists(db, articleId, articleType)): return "Invalid" if(databaseQueries.hasUserLikedArticle(db, articleId, articleType, userId)) : databaseQueries.unlike(db, articleId, articleType, userId) else: databaseQueries.like(db, articleId, articleType) return databaseQueries.getNumberOfLikes(db, articleId, articleType)
def getRequiredTakesHTML( feedType, sortParameter, db, fromDate, toDate, rangeLowerLimit, rangeUpperLimit, ignoredTakesList, ignoredUserList, topicId, tagId, userIdList, ): rows = getRequiredTakes( feedType, sortParameter, db, fromDate, toDate, rangeLowerLimit, rangeUpperLimit, ignoredTakesList, ignoredUserList, topicId, tagId, userIdList, ) if rows == None: return "" htmlCode = "" for row in rows: numberOfFollowers = databaseQueries.getNumberOfFollowers(db, row.auth_user.id) displayPicture = "" if row.auth_user.displayPicture != None: displayPicture = row.auth_user.displayPicture htmlCode += "<table>\n" htmlCode += '<tr class="feedRow">\n' htmlCode += "<td>\n" htmlCode += ( '<a href="' + URL("users", "profile", vars=dict(userId=row.auth_user.id)) + '" class="userPopToolTip">\n' ) htmlCode += ( str( IMG( _src=databaseQueries.getUserProfilePicture(db, row.auth_user.id, displayPicture), _width="60px", _height="60px", ) ) + "\n" ) htmlCode += "<span>\n" htmlCode += row.auth_user.first_name + " " + row.auth_user.last_name + "<br/>\n" htmlCode += "<i>" + str(numberOfFollowers) + " Follower" + ("s" if (numberOfFollowers != 1) else "") + "</i>\n" htmlCode += "</span>\n" htmlCode += "</a>\n" htmlCode += "</td>\n" htmlCode += "<td>\n" htmlCode += ( '<a href="' + URL("takes", "viewTake", vars=dict(takeId=row.takes.id)) + '">' + row.takes.takeTitle + "</a>\n" ) htmlCode += "<div class='likeCount' id = 'takeLikeCount'>\n" htmlCode += ( str(IMG(_src=URL("static", "images/thumbsUpNegative.png"), _alt="thumbs", _width="25px", _height="25px")) + "\n" ) htmlCode += str(databaseQueries.getNumberOfLikes(db, row.takes.id, "Take")) + "\n" htmlCode += "</div>\n" htmlCode += "<br/>\n" htmlCode += XML(getArticlePreview(row.takes.takeContent)) + "\n" htmlCode += "</td>\n" htmlCode += "</tr>\n" htmlCode += "</table>\n" return htmlCode