summaryrefslogtreecommitdiff
path: root/taskapp
diff options
context:
space:
mode:
authornishanth2010-02-04 22:37:15 +0530
committernishanth2010-02-04 22:37:15 +0530
commit9dbedfce8120701cddfae38135c0ddd9dc57835c (patch)
tree42ef86962f59be0e3986e9bc80f3d2a14d61e5f6 /taskapp
parenta54b93b827fa681b85380824d4f30cb8286a9d92 (diff)
downloadpytask-9dbedfce8120701cddfae38135c0ddd9dc57835c.tar.gz
pytask-9dbedfce8120701cddfae38135c0ddd9dc57835c.tar.bz2
pytask-9dbedfce8120701cddfae38135c0ddd9dc57835c.zip
implemented "add another mentor" functionality to a task.
Diffstat (limited to 'taskapp')
-rw-r--r--taskapp/events/task.py9
-rw-r--r--taskapp/forms/task.py13
-rw-r--r--taskapp/models.py7
-rw-r--r--taskapp/views/task.py76
-rw-r--r--taskapp/views/user.py23
5 files changed, 114 insertions, 14 deletions
diff --git a/taskapp/events/task.py b/taskapp/events/task.py
index c887a3c..85845b7 100644
--- a/taskapp/events/task.py
+++ b/taskapp/events/task.py
@@ -21,7 +21,7 @@ def createTask(title,desc,created_by,credits):
"""
try:
- task = Task.objects.get(title=title)
+ task = Task.objects.get(title__iexact=title)
return None
except Task.DoesNotExist:
task = Task(title=title)
@@ -32,3 +32,10 @@ def createTask(title,desc,created_by,credits):
task.save()
return task
+def addSubTask(main_task, sub_task):
+ """ add sub_task to subs list of main_task """
+
+ main_task.subs.add(sub_task)
+ main_task.status = "LO"
+ main_task.save()
+ return main_task
diff --git a/taskapp/forms/task.py b/taskapp/forms/task.py
index c185164..852109a 100644
--- a/taskapp/forms/task.py
+++ b/taskapp/forms/task.py
@@ -6,3 +6,16 @@ class TaskCreateForm(forms.ModelForm):
model = Task
fields = ['title', 'desc', 'tags', 'credits']
publish = forms.BooleanField(required=False)
+
+def AddMentorForm(choices,instance=None):
+ """ return a form object with appropriate choices """
+
+ class myform(forms.Form):
+ mentor = forms.ChoiceField(choices=choices, required=True)
+ form = myform(instance=instance) if instance else myform()
+ return form
+
+def ClaimTaskForm(models.ModelForm):
+ class Meta:
+ model = Claim
+ fields = ['message']
diff --git a/taskapp/models.py b/taskapp/models.py
index 2b64e8d..0aa61f3 100644
--- a/taskapp/models.py
+++ b/taskapp/models.py
@@ -96,4 +96,11 @@ class Credit(models.Model):
def __unicode__(self):
return unicode(self.task.title)
+
+class Claim(models.Model):
+
+ task = models.ForeignKey('Task')
+ user = models.ForeignKey(User)
+ message = models.TextField()
+ creation_datetime = models.DateTimeField()
diff --git a/taskapp/views/task.py b/taskapp/views/task.py
index 67fda8c..99c02d2 100644
--- a/taskapp/views/task.py
+++ b/taskapp/views/task.py
@@ -3,11 +3,14 @@ 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.models import User, Task, Comment
+from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm
+from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask
from pytask.taskapp.views.user import show_msg
+## everywhere if there is no task, django should display 500 message.. but take care of that in sensitive views like add mentor and all
+## do not create su user thro syncdb
+
def browse_tasks(request):
""" display all the tasks """
@@ -29,6 +32,7 @@ def view_task(request, tid):
user = request.user
task = Task.objects.get(id=tid)
comments = Comment.objects.filter(task=task)
+ mentors = task.mentors.all()
errors = []
is_guest = True if not user.is_authenticated() else False
@@ -37,6 +41,7 @@ def view_task(request, tid):
context = {'user':user,
'task':task,
'comments':comments,
+ 'mentors':mentors,
'is_guest':is_guest,
'is_mentor':is_mentor,
'errors':errors,
@@ -94,13 +99,78 @@ def create_task(request):
return show_msg('You are not authorised to create a task.')
else:
return show_msg('You are not authorised to create a task.')
+
+def add_mentor(request, tid):
+ """ check if the current user has the rights to edit the task and add him.
+ if user is not authenticated, redirect him to concerned page. """
+ task_url = "/task/view/tid=%s"%tid
+ user = request.user
+ task = Task.objects.get(id=tid)
+ errors = []
+ is_guest = True if not user.is_authenticated() else False
+ if (not is_guest) and user in task.mentors.all():
+
+ ## now iam going for a brute force method
+ user_list = list(User.objects.all())
+ for mentor in task.mentors.all():
+ user_list.remove(mentor)
+ non_mentors = ((_.id,_.username) for _ in user_list)
+
+ form = AddMentorForm(non_mentors)
+ if request.method == "POST":
+ uid = request.POST['mentor']
+ new_mentor = User.objects.get(id=uid)
+ addMentor(task, new_mentor)
+ return redirect(task_url)
+ else:
+ return render_to_response('task/addmentor.html', {'form':form, 'errors':errors})
+
+ else:
+ return show_msg('You are not authorised to add mentors for this task', task_url, 'view the task')
+def add_tasks(request, tid):
+ """ first display tasks which can be subtasks for the task and do the rest.
+ """
+ task_url = "/task/view/tid=%s"%tid
+ user = request.user
+ task = Task.objects.get(id=tid)
+ errors = []
+
+ is_guest = True if not user.is_authenticated() else False
+
+ if (not is_guest) and user in task.mentors.all():
+ if task.status in ["OP", "LO"]:
+ if request.method == "POST":
+ ## first decide if adding subs and deps can be in same page
+ ## only exclude tasks with status deleted
+ pass
+ else:
+ ## write a form just like add mentor and get the form here
+ pass
+ else:
+ errors = ["The task cannot be added subtasks or dependencies in this state"]
+# return render_to_response('task/add.html', {'form':form, 'errors':errors})
+ return show_msg('The task cannot be added subtasks or dependencies now', task_url, 'view the task')
+ else:
+ return show_msg('You are not authorised to add subtasks or dependencies for this task', task_url, 'view the task')
+
+
+def claim_task(request, tid):
+ """ display a list of claims for get and display submit only if claimable """
+
+ ## create claims model and create a new database with required tables for it
+ ## see if that "one to n" or "n to one" relationship has a special field
+
+ task_url = "/task/view/tid=%s"%tid
+
+ user = request.user
+ task = Task.objects.get(id=tid)
diff --git a/taskapp/views/user.py b/taskapp/views/user.py
index ee174d1..92d8ee8 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 show_msg(message):
+def show_msg(message, redirect_url=None, url_desc=None):
""" simply redirect to homepage """
- return render_to_response('show_msg.html',{'message':message})
+ return render_to_response('show_msg.html',{'message':message, 'redirect_url':redirect_url, 'url_desc':url_desc})
def homepage(request):
""" check for authentication and display accordingly. """
@@ -28,19 +28,22 @@ def homepage(request):
task_list = Task.objects.order_by('id').reverse()
else:
task_list = Task.objects.order_by('id').reverse()[:10]
+
+ return render_to_response('index.html', {'is_guest':is_guest, 'task_list':task_list})
+
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)
+ 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):