def registerUser(request): if request.method == 'POST': formset = UserForm(request.POST, request.FILES) if formset.is_valid(): newUser = User.objects.create_user(formset.data['username'], formset.data['email'], formset.data['password']) custom = UserProfile(user = newUser) custom.user_id = newUser.id custom.save() newUser = authenticate(username=request.POST['username'],password=request.POST['password']) login(request, newUser) return render_to_response("registration/registerSuccess.html",{"userKarma": custom.karma}) else: return render_to_response("registration/register.html", {"formset": formset}) else: userForm = UserForm() return render_to_response("registration/register.html", {"formset": userForm})
def profileView(request): if request.method == "POST": author = request.POST["authorname"] author = author[0:len(author)-1] givenuser =User.objects.get( username = author) try: givenUserProfile = UserProfile.objects.get( pk = givenuser.id) except UserProfile.DoesNotExist: givenUserProfile = UserProfile(user = request.user) givenUserProfile.user_id = request.user.id givenUserProfile.save() else: try: givenUserProfile = UserProfile.objects.get( pk = request.user.id) except UserProfile.DoesNotExist: givenUserProfile = UserProfile(user = request.user) givenUserProfile.user_id = request.user.id givenUserProfile.save() posts = BlogPost.objects.filter(author = givenUserProfile ) posts = list(posts) comments = ThreadedComment.objects.filter(user_name = request.user.username) all_posts = BlogPost.objects.all() for comment in comments: for post in all_posts: baseT = ThreadedComment.objects.get(pk = post.baseThreadID) if comment.tree_path.__contains__('%010i' % int(baseT.comment_ptr_id)) and not posts.__contains__(post): posts.append(post) post_pages = posts paginator = Paginator(post_pages, 15) # Show 25 contacts per page try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 # If page request (9999) is out of range, deliver last page of results. try: post_pages = paginator.page(page) except (EmptyPage, InvalidPage): post_pages = paginator.page(paginator.num_pages) return render_to_response("profile.html",{"userInfo": givenUserProfile,"user": request.user,"post_pages":post_pages})
def profileViewName(request,uname): post_pages = list() try: givenuser = User.objects.get( username = uname) try: givenUserProfile = UserProfile.objects.get( pk = givenuser.id) except UserProfile.DoesNotExist: givenUserProfile = UserProfile(user = givenuser) givenUserProfile.user_id = givenuser.id givenUserProfile.save() posts = BlogPost.objects.filter(author = givenUserProfile ) posts = list(posts) comments = ThreadedComment.objects.filter(user_name = uname) all_posts = BlogPost.objects.all() for comment in comments: for post in all_posts: baseT = ThreadedComment.objects.get(pk = post.baseThreadID) if comment.tree_path.__contains__('%010i' % int(baseT.comment_ptr_id)) and not posts.__contains__(post): posts.append(post) post_pages = posts paginator = Paginator(post_pages, 15) # Show 25 contacts per page try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 try: post_pages = paginator.page(page) except (EmptyPage, InvalidPage): post_pages = paginator.page(paginator.num_pages) except User.DoesNotExist: error = "User Not Found!" return render_to_response("profile.html",{"error": error},context_instance = RequestContext(request) ) return render_to_response("profile.html",{"post" : posts, "userInfo" : givenUserProfile,"post_pages" : post_pages },context_instance = RequestContext(request) )