From 40adcbfc4a6eb40feb37a35db88ea2ed8a7845a7 Mon Sep 17 00:00:00 2001
From: nishanth
Date: Thu, 25 Feb 2010 16:17:56 +0530
Subject: added capability to remove an assigned user.
---
taskapp/events/task.py | 7 ++++++
taskapp/forms/task.py | 8 +++++++
taskapp/views/task.py | 47 +++++++++++++++++++++++++++++++++++++++--
templates/task/remove_user.html | 11 ++++++++++
templates/task/view.html | 4 +++-
urls.py | 1 +
6 files changed, 75 insertions(+), 3 deletions(-)
create mode 100644 templates/task/remove_user.html
diff --git a/taskapp/events/task.py b/taskapp/events/task.py
index a999dc7..ddd40d4 100644
--- a/taskapp/events/task.py
+++ b/taskapp/events/task.py
@@ -175,3 +175,10 @@ def removeTask(main_task, sub_task):
mapobj = Map.objects.get(main=main_task)
mapobj.subs.remove(sub_task)
mapobj.save()
+
+def removeUser(main_task, rem_user):
+ """ right now, just remove the user from the list of assigned_users.
+ """
+
+ main_task.assigned_users.remove(rem_user)
+ main_task.save()
diff --git a/taskapp/forms/task.py b/taskapp/forms/task.py
index 721110f..24749e0 100644
--- a/taskapp/forms/task.py
+++ b/taskapp/forms/task.py
@@ -48,3 +48,11 @@ def AssignCreditForm(choices, instance=None):
user = forms.ChoiceField(choices=choices, required=True)
points = forms.IntegerField(min_value=0,required=True)
return myForm(instance) if instance else myForm()
+
+def RemoveUserForm(choices, instance=None):
+
+ class myForm(forms.Form):
+ user = forms.ChoiceField(choices=choices, required=True)
+ reason = forms.CharField(min_length=1, required=True)
+ return myForm(instance) if instance else myForm()
+
diff --git a/taskapp/views/task.py b/taskapp/views/task.py
index 8857d9e..b05a8f6 100644
--- a/taskapp/views/task.py
+++ b/taskapp/views/task.py
@@ -4,8 +4,8 @@ from django.http import HttpResponse
from django.shortcuts import render_to_response, redirect
from pytask.taskapp.models import User, Task, Comment, Claim, Credit
-from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm
-from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask, removeTask
+from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm
+from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask, removeTask, removeUser
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
@@ -301,7 +301,50 @@ def claim_task(request, tid):
else:
return show_msg('You are not logged in to view claims for this task', task_url, 'view the task')
+def rem_user(request, tid):
+ """ show a list of working users and ask for a message/reason for removing user.
+ """
+
+ task_url = "/task/view/tid=%s"%tid
+ user = request.user
+ task = getTask(tid)
+
+ is_guest = True if not user.is_authenticated() else False
+ is_mentor = True if user in task.mentors.all() else False
+
+ if (not is_guest) and is_mentor:
+
+ assigned_users = task.assigned_users.all()
+ choices = [ (_.id,_.username) for _ in assigned_users ]
+ context = {
+ 'user':user,
+ 'task':task,
+ }
+
+ if assigned_users:
+ form = RemoveUserForm(choices)
+ context['form'] = form
+ if request.method == "POST":
+ data = request.POST
+ form = RemoveUserForm(choices, data)
+ if form.is_valid():
+ data = form.cleaned_data
+ uid = data['user']
+ rem_user = User.objects.get(id=uid)
+ removeUser(task, rem_user)
+ print data['reason']
+ return redirect(task_url)
+ else:
+ context['form'] = form
+ return render_to_response('task/remove_user.html', context)
+ else:
+ return render_to_response('task/remove_user.html',context)
+ else:
+ return show_msg("There is no one working on this task to be kicked off", task_url, "view the task")
+ else:
+ return show_msg("You are not authorised to do this", task_url, "view the task")
+
def assign_task(request, tid):
""" first get the status of the task and then assign it to one of claimed users
generate list of claimed users by passing it as an argument to a function.
diff --git a/templates/task/remove_user.html b/templates/task/remove_user.html
new file mode 100644
index 0000000..5ea2b19
--- /dev/null
+++ b/templates/task/remove_user.html
@@ -0,0 +1,11 @@
+{% extends 'base.html' %}
+{% block title %}
+ Remove users for {{task.title}}
+{% endblock %}
+{% block content %}
+ Click here to return to {{task.title}}
+
+{% endblock %}
diff --git a/templates/task/view.html b/templates/task/view.html
index 64e73c0..bee2def 100644
--- a/templates/task/view.html
+++ b/templates/task/view.html
@@ -66,9 +66,11 @@
{{user.username}}|
{% endfor %}
{% if is_mentor %}
- Remove an existing user
+ Remove an existing user
{% endif %}
+ {% else %}
+ There are no users currently working on this task.
{% endif %}
{% if can_assign_credits %}
Assign credits
diff --git a/urls.py b/urls.py
index 7dcc5df..24b944a 100644
--- a/urls.py
+++ b/urls.py
@@ -31,6 +31,7 @@ urlpatterns = patterns('',
(r'^task/edit/tid=(\d+)$', taskViews.edit_task),
(r'^task/claim/tid=(\d+)$', taskViews.claim_task),
(r'^task/assign/tid=(\d+)$', taskViews.assign_task),
+ (r'^task/remuser/tid=(\d+)$', taskViews.rem_user),
(r'^task/addtask/tid=(\d+)$', taskViews.add_tasks),
(r'^task/remtask/tid=(\d+)$', taskViews.remove_task),
(r'^task/assigncredits/tid=(\d+)$', taskViews.assign_credits),
--
cgit
From 20ef35279dcc5c1e5b9cfac5830739c9f7c221ef Mon Sep 17 00:00:00 2001
From: nishanth
Date: Thu, 25 Feb 2010 16:37:46 +0530
Subject: added the event completeTask.
---
taskapp/events/task.py | 7 +++++++
templates/task/view.html | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/taskapp/events/task.py b/taskapp/events/task.py
index ddd40d4..4f7f76f 100644
--- a/taskapp/events/task.py
+++ b/taskapp/events/task.py
@@ -182,3 +182,10 @@ def removeUser(main_task, rem_user):
main_task.assigned_users.remove(rem_user)
main_task.save()
+
+def completeTask(main_task):
+ """ set the status of task to CP.
+ """
+
+ main_task.status = "CP"
+ main_task.save()
diff --git a/templates/task/view.html b/templates/task/view.html
index bee2def..4ea4877 100644
--- a/templates/task/view.html
+++ b/templates/task/view.html
@@ -76,7 +76,7 @@
Assign credits
{% endif %}
{% if not is_guest and task_claimable %}
- View claims
+ View claims for this task.
{% endif %}
{% if comments %}
--
cgit
From b85600400bfff4f467b20e71db9cd5936c2056d4 Mon Sep 17 00:00:00 2001
From: nishanth
Date: Thu, 25 Feb 2010 17:00:18 +0530
Subject: added events addCredits and assignCredits and modified assign_credits
view accordingly.
---
taskapp/events/task.py | 18 ++++++++++++++++++
taskapp/views/task.py | 8 +++-----
templates/task/assigncredits.html | 2 +-
templates/task/view.html | 4 +++-
4 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/taskapp/events/task.py b/taskapp/events/task.py
index 4f7f76f..ce9c1d9 100644
--- a/taskapp/events/task.py
+++ b/taskapp/events/task.py
@@ -189,3 +189,21 @@ def completeTask(main_task):
main_task.status = "CP"
main_task.save()
+
+def assignCredits(task, given_by, given_to, points):
+ """ make a proper request object.
+ """
+
+ addCredits(task, given_by, given_to, points)
+
+def addCredits(task, given_by, given_to, points):
+ """ add credit to the credits model.
+ """
+
+ creditobj = Credit()
+ creditobj.task = task
+ creditobj.given_by = given_by
+ creditobj.given_to = given_to
+ creditobj.points = points
+ creditobj.given_time = datetime.now()
+ creditobj.save()
diff --git a/taskapp/views/task.py b/taskapp/views/task.py
index b05a8f6..37831cc 100644
--- a/taskapp/views/task.py
+++ b/taskapp/views/task.py
@@ -5,7 +5,7 @@ from django.shortcuts import render_to_response, redirect
from pytask.taskapp.models import User, Task, Comment, Claim, Credit
from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm
-from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask, removeTask, removeUser
+from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addDep, addClaim, assignTask, getTask, updateTask, removeTask, removeUser, assignCredits
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
@@ -408,6 +408,7 @@ def assign_credits(request, tid):
context = {
'user':user,
+ 'task':task,
'prev_credits':prev_credits,
'form':form,
}
@@ -420,10 +421,7 @@ def assign_credits(request, tid):
uid = data['user']
points = data['points']
given_to = User.objects.get(id=uid)
- given_time = datetime.now()
- creditobj = Credit(task=task, given_by=user, given_to=given_to,points=points,given_time=given_time)
- ## remove the next line and add a request here
- creditobj.save()
+ assignCredits(task=task, given_by=user, given_to=given_to, points=points)
return redirect('/task/assigncredits/tid=%s'%task.id)
else:
context['form'] = form
diff --git a/templates/task/assigncredits.html b/templates/task/assigncredits.html
index 1272367..21d8807 100644
--- a/templates/task/assigncredits.html
+++ b/templates/task/assigncredits.html
@@ -3,7 +3,7 @@
{{task.title}}
{% endblock %}
{% block content %}
-
+ Click here to return to the task.
{% if prev_credits %}
Previous credits:
diff --git a/templates/task/view.html b/templates/task/view.html
index 4ea4877..c22284c 100644
--- a/templates/task/view.html
+++ b/templates/task/view.html
@@ -4,7 +4,9 @@
{% endblock %}
{% block content %}
{% if task_viewable %}
- Edit task
+ {% if is_mentor %}
+ Edit task
+ {% endif %}
{{ task.title }}
created by {{ task.created_by.username }} on {{ task.creation_datetime.ctime }}
--
cgit