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)
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)
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)
def guest_index(request): return instance(request, "codebook/guest_index.html")
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")