renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
authornishanth
Fri, 29 Jan 2010 23:34:19 +0530
changeset 10 c2001db39937
parent 9 554581fa3253
child 11 d28fcc644fbb
renamed users.py to user.py and tasks to task in views folder and updated urls.py accordingly .
pytask/taskapp/views/task.py
pytask/taskapp/views/tasks.py
pytask/taskapp/views/user.py
pytask/taskapp/views/users.py
pytask/urls.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pytask/taskapp/views/task.py	Fri Jan 29 23:34:19 2010 +0530
@@ -0,0 +1,52 @@
+from datetime import datetime
+
+from django.http import HttpResponse
+from django.shortcuts import render_to_response, redirect
+from pytask.taskapp.models import Task, Comment
+
+def browse_tasks(request):
+    """ display all the tasks """
+    
+    user = request.user
+    task_list = Task.objects.order_by('id').reverse()
+    
+    context = {'user':user,
+               'task_list':task_list,
+               }
+    return render_to_response('task/browse.html', context)
+
+def view_task(request, tid):
+    """ get the task depending on its tid and display accordingly if it is a get.
+    check for authentication and add a comment if it is a post request.
+    """
+    
+    task_url = "/task/view/tid=%s"%tid
+    
+    user = request.user
+    task = Task.objects.get(id=tid)
+    comments = Comment.objects.filter(task=task)
+    errors = []
+    
+    is_guest = True if not user.is_authenticated() else False
+    is_mentor = True if user in task.mentors.all() else False
+    
+    context = {'user':user,
+               'task':task,
+               'comments':comments,
+               'is_guest':is_guest,
+               'is_mentor':is_mentor,
+               'errors':errors,
+               }
+    
+    if request.method == 'POST':
+        if not is_guest:
+            data = request.POST["data"]
+            task = Task.objects.get(id=tid)
+            new_comment = Comment(task=task, data=data, created_by=user, creation_datetime=datetime.now())
+            new_comment.save()
+            return redirect(task_url)
+        else:
+            errors.append("You must be logged in to post a comment")
+            return render_to_response('task/view.html', context)
+    else:
+        return render_to_response('task/view.html', context)
--- a/pytask/taskapp/views/tasks.py	Fri Jan 29 23:23:33 2010 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-from datetime import datetime
-
-from django.http import HttpResponse
-from django.shortcuts import render_to_response, redirect
-from pytask.taskapp.models import Task, Comment
-
-def browse_tasks(request):
-    """ display all the tasks """
-    
-    user = request.user
-    task_list = Task.objects.order_by('id').reverse()
-    
-    context = {'user':user,
-               'task_list':task_list,
-               }
-    return render_to_response('task/browse.html', context)
-
-def view_task(request, tid):
-    """ get the task depending on its tid and display accordingly if it is a get.
-    check for authentication and add a comment if it is a post request.
-    """
-    
-    task_url = "/task/view/tid=%s"%tid
-    
-    user = request.user
-    task = Task.objects.get(id=tid)
-    comments = Comment.objects.filter(task=task)
-    errors = []
-    
-    is_guest = True if not user.is_authenticated() else False
-    is_mentor = True if user in task.mentors.all() else False
-    
-    context = {'user':user,
-               'task':task,
-               'comments':comments,
-               'is_guest':is_guest,
-               'is_mentor':is_mentor,
-               'errors':errors,
-               }
-    
-    if request.method == 'POST':
-        if not is_guest:
-            data = request.POST["data"]
-            task = Task.objects.get(id=tid)
-            new_comment = Comment(task=task, data=data, created_by=user, creation_datetime=datetime.now())
-            new_comment.save()
-            return redirect(task_url)
-        else:
-            errors.append("You must be logged in to post a comment")
-            return render_to_response('task/view.html', context)
-    else:
-        return render_to_response('task/view.html', context)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pytask/taskapp/views/user.py	Fri Jan 29 23:34:19 2010 +0530
@@ -0,0 +1,96 @@
+from django.http import HttpResponse
+from django.shortcuts import redirect, render_to_response
+from pytask.taskapp.models import Task
+from pytask.taskapp.forms.user import RegistrationForm, LoginForm
+from pytask.taskapp.events.user import createUser
+from django.contrib.auth import login, logout, authenticate
+from django.contrib.auth.models import User
+
+def redirect_to_homepage(request):
+    """ simply redirect to homepage """
+    
+    return redirect('/')
+
+def homepage(request):
+    """ check for authentication and display accordingly. """
+    
+    user = request.user
+    is_guest = False
+    is_mentor = False
+    can_create_task = False
+    task_list = []
+    
+    if not user.is_authenticated():
+        is_guest = True
+        disp_num = 10
+        tasks_count = Task.objects.count()
+        if tasks_count <= disp_num:
+            task_list = Task.objects.order_by('id').reverse()
+        else:
+            task_list = Task.objects.order_by('id').reverse()[:10]
+    else:
+        user_profile = user.get_profile()
+        is_mentor = True if user.task_mentors.all() else False
+        can_create_task = False if user_profile.rights == u"CT" else True
+        
+    context = {'user':user,
+               'is_guest':is_guest,
+               'is_mentor':is_mentor,
+               'task_list':task_list,
+               'can_create_task':can_create_task,
+               }
+               
+    return render_to_response('index.html', context)
+
+
+def register(request):
+    """ user registration: gets the user details and create the user and userprofile if data entered is valid"""
+    if request.method == 'POST':
+        form = RegistrationForm(request.POST)
+        if form.is_valid():
+            data = form.cleaned_data
+            if data['password'] == data['repeat_password']:
+                if data['username'].isalnum():
+                    try:
+                        if User.objects.get(username__exact = data['username']):
+                            errors=['Choose some other username']
+                            return render_to_response('user/register.html',{'form':form,'errors':errors})
+                    except:
+                         u = createUser(username=data['username'], email=data['email'], password=data['password'],dob = data['dob'],gender = data['gender'])
+                    return redirect('/accounts/login/')
+                else:
+                    errors = ['Username can contain only alphabets and numbers!']
+                    return render_to_response('user/register.html',{'form':form,'errors':errors})
+            else:
+                errors=['Password do not match']
+                form = RegistrationForm(request.POST)
+                return render_to_response('user/register.html',{'form':form,'errors':errors})#HttpResponse('Password did not match')
+        else:
+            form = RegistrationForm(request.POST)
+    else:
+        form = RegistrationForm()
+    return render_to_response('user/register.html', {'form': form})
+
+def user_login(request):
+    if request.method == 'POST':
+        username = request.POST['username']
+        password = request.POST['password']
+        user = authenticate(username=username, password=password)
+        if user is not None:
+            if user.is_active:
+                login(request, user)
+                return redirect('/')# Redirect to a success page.
+            else:
+                return HttpResponse('username is not active, please contact the administrator')# Return a 'disabled account' error message
+        else:
+            errors = ['Please check your username and password']
+            form = LoginForm()
+            return render_to_response('user/login.html',{'form':form,'errors':errors})# Return an 'invalid login' error message.
+        return redirect('/')
+    else:
+        form = LoginForm()
+        return render_to_response('user/login.html',{'form': form})
+
+def user_logout(request):
+    logout(request)
+    return HttpResponse('You have logged off successfully!!!')
--- a/pytask/taskapp/views/users.py	Fri Jan 29 23:23:33 2010 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-from django.http import HttpResponse
-from django.shortcuts import redirect, render_to_response
-from pytask.taskapp.models import Task
-from pytask.taskapp.forms.user import RegistrationForm, LoginForm
-from pytask.taskapp.events.user import createUser
-from django.contrib.auth import login, logout, authenticate
-from django.contrib.auth.models import User
-
-def redirect_to_homepage(request):
-    """ simply redirect to homepage """
-    
-    return redirect('/')
-
-def homepage(request):
-    """ check for authentication and display accordingly. """
-    
-    user = request.user
-    is_guest = False
-    is_mentor = False
-    can_create_task = False
-    task_list = []
-    
-    if not user.is_authenticated():
-        is_guest = True
-        disp_num = 10
-        tasks_count = Task.objects.count()
-        if tasks_count <= disp_num:
-            task_list = Task.objects.order_by('id').reverse()
-        else:
-            task_list = Task.objects.order_by('id').reverse()[:10]
-    else:
-        user_profile = user.get_profile()
-        is_mentor = True if user.task_mentors.all() else False
-        can_create_task = False if user_profile.rights == u"CT" else True
-        
-    context = {'user':user,
-               'is_guest':is_guest,
-               'is_mentor':is_mentor,
-               'task_list':task_list,
-               'can_create_task':can_create_task,
-               }
-               
-    return render_to_response('index.html', context)
-
-
-def register(request):
-    """ user registration: gets the user details and create the user and userprofile if data entered is valid"""
-    if request.method == 'POST':
-        form = RegistrationForm(request.POST)
-        if form.is_valid():
-            data = form.cleaned_data
-            if data['password'] == data['repeat_password']:
-                if data['username'].isalnum():
-                    try:
-                        if User.objects.get(username__exact = data['username']):
-                            errors=['Choose some other username']
-                            return render_to_response('user/register.html',{'form':form,'errors':errors})
-                    except:
-                         u = createUser(username=data['username'], email=data['email'], password=data['password'],dob = data['dob'],gender = data['gender'])
-                    return redirect('/accounts/login/')
-                else:
-                    errors = ['Username can contain only alphabets and numbers!']
-                    return render_to_response('user/register.html',{'form':form,'errors':errors})
-            else:
-                errors=['Password do not match']
-                form = RegistrationForm(request.POST)
-                return render_to_response('user/register.html',{'form':form,'errors':errors})#HttpResponse('Password did not match')
-        else:
-            form = RegistrationForm(request.POST)
-    else:
-        form = RegistrationForm()
-    return render_to_response('user/register.html', {'form': form})
-
-def user_login(request):
-    if request.method == 'POST':
-        username = request.POST['username']
-        password = request.POST['password']
-        user = authenticate(username=username, password=password)
-        if user is not None:
-            if user.is_active:
-                login(request, user)
-                return redirect('/')# Redirect to a success page.
-            else:
-                return HttpResponse('username is not active, please contact the administrator')# Return a 'disabled account' error message
-        else:
-            errors = ['Please check your username and password']
-            form = LoginForm()
-            return render_to_response('user/login.html',{'form':form,'errors':errors})# Return an 'invalid login' error message.
-        return redirect('/')
-    else:
-        form = LoginForm()
-        return render_to_response('user/login.html',{'form': form})
-
-def user_logout(request):
-    logout(request)
-    return HttpResponse('You have logged off successfully!!!')
--- a/pytask/urls.py	Fri Jan 29 23:23:33 2010 +0530
+++ b/pytask/urls.py	Fri Jan 29 23:34:19 2010 +0530
@@ -4,8 +4,8 @@
 from django.contrib import admin
 admin.autodiscover()
 
-from pytask.taskapp.views.users import redirect_to_homepage, homepage, register, user_login, user_logout
-from pytask.taskapp.views.tasks import browse_tasks, view_task
+from pytask.taskapp.views.user import redirect_to_homepage, homepage, register, user_login, user_logout
+from pytask.taskapp.views.task import browse_tasks, view_task
 
 urlpatterns = patterns('',
     # Example: