Esempio n. 1
0
def post_page(request,post_id):
    base_vars = get_base_vars(request)
    
    if request.user.is_authenticated():
        email = base_vars['user']
        user = User.objects.get( email = email )
        user_name = "%s %s" %(user.first_name , user.last_name )
        post = post_model.objects.get( id=post_id )
        comment_post = comment_model.objects.filter( parent_post_id = post_id ).order_by( 'date' )
        if request.method == "POST":
            new_comment = CommentForm(request.POST)
            if new_comment.is_valid():
                comment = comment_model()
                comment.posted_by = user_name
                comment.date = datetime.datetime.now()
                comment.parent_post_id = post_id
                comment.message = request.POST['message']
                comment.save()
                
                url = '/forum/post/%s' %post_id
                return HttpResponseRedirect(url )            
            else:
                base_vars.update({"post":post,"commentform":CommentForm ,"comments":comment_post})
                render_to_response('post.html',base_vars)
        else:        
            base_vars.update({"post":post,"commentform":CommentForm,"comments":comment_post})
            return render_to_response('post.html',base_vars)

    else:
        base_vars.update({"message":"You are not authorised to be here"})
        return render_to_response("message.html",base_vars)
Esempio n. 2
0
def newpost(request):
    base_vars = get_base_vars(request)
    
    if request.user.is_authenticated():
        email = base_vars['user']
        user_name = base_vars['user_name']
        if request.method=="POST":
            new_post = PostForm(request.POST)
            if new_post.is_valid():
                post = post_model()
                post.posted_by = user_name
                post.title = request.POST['title']
                post.message = request.POST['message']
                post.date = datetime.datetime.now()
                post.save()
                
                return HttpResponseRedirect('/forum/')
            
            else:
                base_vars.update({"post_form":PostForm})
                return render_to_response("new_post.html",base_vars)
        
        else:
            base_vars.update({"post_form":PostForm})
            return render_to_response("new_post.html",base_vars)
    else:
        base_vars.update({"message":"Please login to view this page"})
        return render_to_response("message.html", base_vars)
Esempio n. 3
0
def signup(request):
    base_vars=get_base_vars(request)
    
    if request.user.is_authenticated():
        base_vars.update({"message":"You are logged in."})
        return render_to_response("message.html", base_vars)
    else:
        if request.method=="POST":
            suForm=SignupForm(request.POST, request.FILES)
            if suForm.is_valid():
                pk=len(User.objects.all()).__str__()
                username=pk.join([request.POST['first_name'],request.POST['last_name']])
                user=User.objects.create_user( username=username,email=request.POST['email'],password=request.POST['password1'])
                user.first_name=request.POST['first_name']
                user.last_name=request.POST['last_name']
                user.save()
                
                person = account_models.person()
                person.user_id = user
                person.sex = request.POST['sex']
                person.phno = request.POST['phno']
                person.pin = request.POST['pin']
                person.website = request.POST['website']
                person.save()
                
                logged_in_user = authenticate(username=username, password=request.POST['password1'])
                if logged_in_user is not None:
                    login(request, logged_in_user)
                    return HttpResponseRedirect("/account/home")
            else:
                base_vars.update({"reg_form":suForm,})
                return render_to_response("account_signup.html", base_vars)
        else:
            base_vars.update({"reg_form":SignupForm()})
            return render_to_response("account_signup.html", base_vars)
Esempio n. 4
0
def index(request):
    base_vars = get_base_vars(request)

    if request.user.is_authenticated(): #doesnt need to signup because already authenticated
        return HttpResponseRedirect("/account/home/")
    if request.method=="POST":
        # verify fields and login
        login_form=LoginForm( request.POST )
        if login_form.is_valid():
            email = request.POST['email']
            username = User.objects.get(email=email)
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                #authenticated so returning as authenticated
                login(request, user)
                return HttpResponseRedirect("/account/home")
            else:
                login_form._errors['email'] = ErrorList(['Wrong email or password'])
                base_vars.update({"login_form":login_form})
                return render_to_response("account_login.html", base_vars)
        else:
            base_vars.update({"login_form":login_form})
            return render_to_response("account_login.html", base_vars)
    else:
        base_vars.update({"login_form":LoginForm()})
        return render_to_response("account_login.html",base_vars)
Esempio n. 5
0
def settings(request):
    base_vars = get_base_vars(request)
    
    try:
        pwdChng = request.GET['pwdChng']
        if(pwdChng == 'Sucess'):
            base_vars.update({'pwdMsg':"<span color=#008800>Password Changed</span><br>"})
        elif(pwdChng == 'Fail'):
            base_vars.update({'pwdMsg':"<span color=#008800>Password Change failed</span><br>"})
    
    except:
        pass

    if request.user.is_authenticated():
        user_current = User.objects.get(email=request.user.email)
        person_current = account_models.person.objects.get(user_id = user_current.pk)
        user_data = {}
        user_data['first_name'] = user_current.first_name
        user_data['last_name'] = user_current.last_name
        user_data['sex'] = person_current.sex
        user_data['phno'] = person_current.phno
        user_data['pin'] = person_current.pin
        user_data['website'] = person_current.website

        pool=AccountSettingsForm(user_data)
        base_vars.update({'pool': pool})
        return render_to_response("account_settings.html",base_vars)
    else:
        base_vars.update({"login_form":LoginForm()})
        return render_to_response("account_login.html",base_vars)
Esempio n. 6
0
def signupform(request):
    base_vars=get_base_vars(request)

    if request.user.is_authenticated():
        return HttpResponseRedirect("/account/home")
    else:
        base_vars.update({"reg_form":SignupForm()})
        return render_to_response("account_signup.html", base_vars)
Esempio n. 7
0
def logout(request):
    if request.user.is_authenticated():
        auth_logout(request)
        return HttpResponseRedirect("/account/")
    else:
        base_vars=get_base_vars(request)

        base_vars.update({"message":"You are not authorised to be here"})
        return render_to_response("message.html",base_vars)
Esempio n. 8
0
def home(request):
    base_vars = get_base_vars(request)
    
    if request.user.is_authenticated():
        email=base_vars['user']
        user = User.objects.get( email = email )
        _id = user.id
        person = account_models.person()
        person = account_models.person.objects.get( user_id = _id )
        base_vars.update({"email": email,"fname":user.first_name,"lname":user.last_name,"sex":person.sex, "phno":person.phno })
        return render_to_response("home.html",base_vars)
    else:
        HttpResponseRedirect("/account/")
Esempio n. 9
0
def forum_index(request):
    base_vars = get_base_vars(request)
    count_comment = {}
    if request.user.is_authenticated():
        posts = post_model.objects.all()

        for post in posts:
            comments = comment_model.objects.filter( parent_post_id = post.id ).count()
            count_comment[ post.id ] = comments

        base_vars.update({"posts" : posts ,"count": count_comment})
        return render_to_response('forum.html',base_vars)
    
    else:
        base_vars.update({"message":"You are not authorised to be here"})
        return render_to_response("message.html", base_vars)
Esempio n. 10
0
def change(request):
    if request.user.is_authenticated() and request.method == "POST":
        user = request.user
        person = account_models.person.objects.get(user_id = user)
        #assign values from form
        user.first_name = request.POST['first_name']
        user.last_name = request.POST['last_name']
        user.save()
        
        person.sex = request.POST['sex']
        person.phno = request.POST['phno']
        person.website = request.POST['website']
        person.pin = request.POST['pin']
        person.save()

        return HttpResponseRedirect('/account/settings/')

    else:
        base_vars = get_base_vars(request)
        
        base_vars.update({"message":"You are not authorised to be here"})
        return render_to_response("message.html",message)