示例#1
0
def profile():
    if request.vars.userId == None:
        redirect(URL("default", "index"))

    userId = request.vars.userId
    response.view = "users/profile.html"

    isFollowing = databaseQueries.checkIfFollowing(db, userId, auth.user.id)

    userInfo = databaseQueries.getUserInfo(db, userId)

    if userInfo == None:
        redirect(URL("default", "index"))

    response.title = userInfo.first_name + " " + userInfo.last_name
    response.subtitle = (
        "Joined " + utilityFunctions.getMonthName(userInfo.timeOfJoining.month) + "-" + str(userInfo.timeOfJoining.year)
    )

    followURL = ""
    if int(auth.user.id) != int(userId):
        followURL = URL("ajax", "changeFollowStatus", vars=dict(userId=userId))

    profilePicLink = databaseQueries.getUserProfilePicture(db, userId, None)
    numberOfFollowers = databaseQueries.getNumberOfFollowers(db, userId)

    return dict(
        profilePicLink=profilePicLink,
        userInfo=userInfo,
        followURL=followURL,
        numberOfFollowers=numberOfFollowers,
        isFollowing=isFollowing,
    )
示例#2
0
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)
示例#3
0
def changeFollowStatus():
    if(request.vars.userId==None):
        return "Invalid"
        
    userId = request.vars.userId
    followerId = auth.user.id
    if (databaseQueries.checkIfUserExists(db,userId)):
        if(databaseQueries.checkIfFollowing(db, userId, followerId)):
            databaseQueries.removeFollowRelation(db, userId, followerId)
        else:
            databaseQueries.addFollowRelation(db, userId, followerId)
        numberOfFollowers = databaseQueries.getNumberOfFollowers(db, userId)
        returnString = str(numberOfFollowers) + " Follower" + ("s" if (numberOfFollowers!=1) else "")
        return returnString
    return "Invalid"
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