예제 #1
0
파일: views.py 프로젝트: Mixton/CodeBook
def user(request, username):
    ctx = {'username': username}

    try:
        user = getUser(username)
    except:
        raise Http404("{} is not a registered user".format(username))

    ctx['posts'] = user.post_set.filter().order_by('-created')

    return instance(request, "users/view.html", ctx)
예제 #2
0
파일: views.py 프로젝트: Mixton/CodeBook
def post(request, username, pid):
    ctx = {'username': username}
    user = getUser(username)

    userMismatch = username != request.user.username
    try:
        f = Follow.objects.get(uid=user.id, fid=request.user.id)
    except:
        f = None

    if userMismatch and not f:
        return redirect("codebook:user", {'username': username})

    ctx['post'] = user.post_set.get(pk=pid)
    return instance(request, "users/post.html", ctx)
예제 #3
0
파일: views.py 프로젝트: Mixton/CodeBook
def index(request):
    if not request.user.is_authenticated():
        return guest_index(request)

    follows = Follow.objects.filter(fid=request.user.id)

    uPosts = request.user.post_set.filter().order_by('-created')

    uPosts = [post for post in uPosts]
    for follow in follows:
        follow = getUserByID(follow.uid)
        fPosts = follow.post_set.filter().order_by('-created')
        uPosts += [post for post in fPosts]

    uPosts.sort(key=lambda x: str(x.created), reverse=True)

    ctx = {'posts': uPosts, 'followers': follows}

    return instance(request, "codebook/index.html", ctx)
예제 #4
0
파일: views.py 프로젝트: Mixton/CodeBook
def guest_index(request):
    return instance(request, "codebook/guest_index.html")
예제 #5
0
파일: views.py 프로젝트: Mixton/CodeBook
def deactivate(request):
    if request.user.is_authenticated():
        request.user.is_active = False
        request.user.save()
        request = deauthUser(request)
    return instance(request, "users/deactivate.html")