summaryrefslogtreecommitdiff
path: root/taskapp/views
diff options
context:
space:
mode:
authornishanth2010-02-04 22:27:47 +0530
committernishanth2010-02-04 22:27:47 +0530
commita7eb099e1c73545217babeef9dc52e6abb2ba912 (patch)
tree68925ef127a8a8a08ccdc9c322e035f8f74cfd15 /taskapp/views
parent21f2d7770f5960cf7bf4b0c22a7e8bcfb8f65d78 (diff)
downloadpytask-a7eb099e1c73545217babeef9dc52e6abb2ba912.tar.gz
pytask-a7eb099e1c73545217babeef9dc52e6abb2ba912.tar.bz2
pytask-a7eb099e1c73545217babeef9dc52e6abb2ba912.zip
implemented create task view which needed task.py in events. added a method show_msg to views/user.py and used it in logoff view.
Diffstat (limited to 'taskapp/views')
-rw-r--r--taskapp/views/task.py58
-rw-r--r--taskapp/views/user.py8
2 files changed, 62 insertions, 4 deletions
diff --git a/taskapp/views/task.py b/taskapp/views/task.py
index a8fec95..67fda8c 100644
--- a/taskapp/views/task.py
+++ b/taskapp/views/task.py
@@ -2,7 +2,11 @@ from datetime import datetime
from django.http import HttpResponse
from django.shortcuts import render_to_response, redirect
+
from pytask.taskapp.models import Task, Comment
+from pytask.taskapp.forms.task import TaskCreateForm
+from pytask.taskapp.events.task import createTask, addMentor, publishTask
+from pytask.taskapp.views.user import show_msg
def browse_tasks(request):
""" display all the tasks """
@@ -50,3 +54,57 @@ def view_task(request, tid):
return render_to_response('task/view.html', context)
else:
return render_to_response('task/view.html', context)
+
+def create_task(request):
+ """ check for rights and create a task if applicable.
+ if user cannot create a task, redirect to homepage.
+ """
+
+ user = request.user
+ is_guest = True if not user.is_authenticated() else False
+
+ if not is_guest:
+ user_profile = user.get_profile()
+ can_create_task = False if user_profile.rights == "CT" else True
+ if can_create_task:
+ if request.method == "POST":
+ form = TaskCreateForm(request.POST)
+ if form.is_valid():
+ data = form.cleaned_data
+ title = data['title']
+ desc = data['desc']
+ credits = data['credits']
+ publish = data['publish']
+ task = createTask(title,desc,user,credits)
+
+ if not task:
+ error_msg = "Another task with the same title exists"
+ return render_to_response('task/create.html',{'form':form, 'error_msg':error_msg})
+
+ addMentor(task, user)
+ if publish: publishTask(task)
+ task_url = '/task/view/tid=%s'%task.id
+ return redirect(task_url)
+ else:
+ return render_to_response('task/create.html',{'form':form})
+ else:
+ form = TaskCreateForm()
+ return render_to_response('task/create.html',{'form':form})
+ else:
+ return show_msg('You are not authorised to create a task.')
+ else:
+ return show_msg('You are not authorised to create a task.')
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/taskapp/views/user.py b/taskapp/views/user.py
index 5d07f76..6013fe9 100644
--- a/taskapp/views/user.py
+++ b/taskapp/views/user.py
@@ -6,10 +6,10 @@ 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):
+def show_msg(error_msg):
""" simply redirect to homepage """
- return redirect('/')
+ return render_to_response('error.html',{'error_msg':error_msg})
def homepage(request):
""" check for authentication and display accordingly. """
@@ -81,7 +81,7 @@ def user_login(request):
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
+ return show_msg('username is not active, please contact the administrator')# Return a 'disabled account' error message
else:
errors = ['Please check your username and password']
form = LoginForm()
@@ -93,4 +93,4 @@ def user_login(request):
def user_logout(request):
logout(request)
- return HttpResponse('You have logged off successfully!!!')
+ return show_msg('You have logged off successfully!!!')