Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
def guest_index(request):
    return instance(request, "codebook/guest_index.html")
Ejemplo n.º 5
0
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")