Beispiel #1
0
def xFollow(id: str, status: str):
    """
    @param id = the followee user who the currently-logged-in user
        is following or unfollowing
    @param status = following status, 0=unfollow, 1=follow
    """
    makeFollowing = (status == "1")
    cun = currentUserName()
    dpr("id=%r status=%r cun=%r", id, status, cun)
    if not cun: return "{}"

    cu = User.getDoc(cun)
    if not cu: return "{}"
    followee = User.getDoc(id)
    if not followee: return "{}"

    ai = models.getAccountInfo(cun)
    followingSet = set(ai.following_ids)
    if makeFollowing:
        followingSet2 = followingSet | set([id])
    else:
        followingSet2 = followingSet - set([id])
    if followingSet2 != followingSet:
        ai.following_ids = list(followingSet2)
        ai.save()
    return "{}"
Beispiel #2
0
def followerMess(id):
    user = User.getDoc(id)
    lf = FollowerFormatter(id)
    tem = jinjaEnv.get_template("followerMess.html")

    h = tem.render(
        id=id,
        user=user,
        lf=lf,
    )
    return h
Beispiel #3
0
def listFollowers(id):
    """ list of people who follow (id) """
    user = User.getDoc(id)
    count = models.AccountInfo.count({'following_ids': id})
    pag = paginate.Paginator(count)

    tem = jinjaEnv.get_template("listFollowers.html")
    h = tem.render(
        id=id,
        user=user,
        count=count,
        pag=pag,
        table=followersTableH(id, pag),
    )
    return h
Beispiel #4
0
def listFollowing(id):
    """ list of people who follow (id) """
    user = User.getDoc(id)
    ai = models.getAccountInfo(id)
    count = len(ai.following_ids)
    pag = paginate.Paginator(count)

    tem = jinjaEnv.get_template("listFollowing.html")
    h = tem.render(
        id=id,
        user=user,
        ai=ai,
        count=count,
        pag=pag,
        table=followingTableH(ai, pag),
    )
    return h
Beispiel #5
0
def blog(id):
    user = User.getDoc(id)
    ai = models.getAccountInfo(id)
    lf = BlogFormatter(id)
    numPosts = models.Message.count({'author_id': id})
    numHeadPosts = models.Message.count({
        'author_id': id,
        'replyTo_id': {
            '$in': [None, '']
        },
    })
    numFollowing = len(ai.following_ids)
    numFollowers = models.AccountInfo.count({'following_ids': id})

    cun = currentUserName()
    if not cun:
        # not logged in, so no follow button
        followButton = ""
    else:
        if models.follows(cun, id):
            # follows, so unfollow button
            followButton = "unfollow"
        else:
            # doesn't currently follow, so follow button
            followButton = "follow"
    dpr("followButton=%r", followButton)

    tem = jinjaEnv.get_template("blog.html")
    h = tem.render(
        id=id,
        idJson=json.dumps(id),
        user=user,
        ai=ai,
        blogTitle=ai.asReadableH('title'),
        name=ai.asReadableH('realName'),
        bio=ai.bioHtml,
        numPosts=numPosts,
        numHeadPosts=numHeadPosts,
        numFollowing=numFollowing,
        numFollowers=numFollowers,
        followButton=followButton,
        lf=lf,
    )
    return h
Beispiel #6
0
def accountSettings():
    cun = currentUserName()
    dpr("id=%r cun=%r", id, cun)
    #if id != cun:
    #    return http403()
    user = User.getDoc(cun)
    ai = models.getAccountInfo(cun)
    msg = ""
        
    if request.method=='POST':
        ai = ai.populateFromRequest(request)
        ai.save()
        msg = "Saved account settings"
    #//if    
    
    tem = jinjaEnv.get_template("accountSettings.html")
    h = tem.render(
        user = user,
        ai = ai,
        msg = ht.goodMessageBox(msg),
    )
    return h