diff options
author | nishanth | 2010-02-04 23:15:37 +0530 |
---|---|---|
committer | nishanth | 2010-02-04 23:15:37 +0530 |
commit | 9f940aa6a9e67241d1c680b35b8f280f7210c514 (patch) | |
tree | d9e9e6db6529817e7c1e68cfb94df839867fe723 | |
parent | 54f307faa17ac411336c261a7acc57edb6df7d1a (diff) | |
download | pytask-9f940aa6a9e67241d1c680b35b8f280f7210c514.tar.gz pytask-9f940aa6a9e67241d1c680b35b8f280f7210c514.tar.bz2 pytask-9f940aa6a9e67241d1c680b35b8f280f7210c514.zip |
added the functionality to assign a task to one of the claimed users.
-rw-r--r-- | taskapp/events/task.py | 24 | ||||
-rw-r--r-- | taskapp/forms/task.py | 8 | ||||
-rw-r--r-- | taskapp/views/task.py | 69 | ||||
-rw-r--r-- | templates/task/assign.html | 8 | ||||
-rw-r--r-- | templates/task/claim.html | 25 | ||||
-rw-r--r-- | templates/task/view.html | 7 | ||||
-rw-r--r-- | urls.py | 5 |
7 files changed, 132 insertions, 14 deletions
diff --git a/taskapp/events/task.py b/taskapp/events/task.py index 85845b7..c9d3a21 100644 --- a/taskapp/events/task.py +++ b/taskapp/events/task.py @@ -1,5 +1,5 @@ from datetime import datetime -from pytask.taskapp.models import Profile, Task, Comment, Credit +from pytask.taskapp.models import Profile, Task, Comment, Credit, Claim def publishTask(task): """ set the task status to open """ @@ -39,3 +39,25 @@ def addSubTask(main_task, sub_task): main_task.status = "LO" main_task.save() return main_task + +def addClaim(task, message, user): + """ add claim data to the database if it does not exist + and also update the claimed users field of the task. + """ + + task.claimed_users.add(user) + task.status = "CL" + task.save() + claim = Claim() + claim.message = message + claim.task = task + claim.user = user + claim.creation_datetime = datetime.now() + claim.save() + +def assignTask(task, user): + """ check for the status of task and assign it to the particular user """ + + task.assigned_users.add(user) + task.status = "AS" + task.save() diff --git a/taskapp/forms/task.py b/taskapp/forms/task.py index b4303e3..953f615 100644 --- a/taskapp/forms/task.py +++ b/taskapp/forms/task.py @@ -19,3 +19,11 @@ class ClaimTaskForm(forms.ModelForm): class Meta: model = Claim fields = ['message'] + +def AssignTaskForm(choices, instance=None): + """ return a form object with appropriate choices """ + + class myform(forms.Form): + user = forms.ChoiceField(choices=choices, required=True) + form = myform() + return form diff --git a/taskapp/views/task.py b/taskapp/views/task.py index f08a82f..0fbc6aa 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 -from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm -from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask +from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AssignTaskForm +from pytask.taskapp.events.task import createTask, addMentor, publishTask, addSubTask, addClaim, assignTask 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 @@ -39,7 +39,6 @@ def view_task(request, tid): is_mentor = True if user in task.mentors.all() else False task_claimable = True if task.status in ["OP", "RE"] else False - user_can_view_claim = True if ( task_claimable and not ( is_guest or is_mentor ) ) else False context = {'user':user, 'task':task, @@ -47,9 +46,11 @@ def view_task(request, tid): 'mentors':mentors, 'is_guest':is_guest, 'is_mentor':is_mentor, - 'user_can_view_claim':user_can_view_claim, 'errors':errors, } + + if task.status == "AS": + context['assigned_user'] = task.assigned_users.all()[0] if request.method == 'POST': if not is_guest: @@ -172,25 +173,75 @@ def claim_task(request, tid): ## see if that "one to n" or "n to one" relationship has a special field task_url = "/task/view/tid=%s"%tid + claim_url = "/task/claim/tid=%s"%tid + + errors = [] user = request.user task = Task.objects.get(id=tid) claims = Claim.objects.filter(task=task) is_guest = True if not user.is_authenticated() else False + if user in task.mentors.all(): + is_mentor = True + else: + is_mentor = False - task_claimable = True if task.status in ["OP", "RE"] else False - user_can_claim = True if ( task_claimable and not ( is_guest or is_mentor ) and ( user not in task.claimed_users.all() ) ) else False + task_claimable = True if task.status in ["OP", "RE", "CL"] else False + user_can_claim = True if task_claimable and not ( is_guest or is_mentor ) and ( user not in task.claimed_users.all() ) else False + + context = {'is_mentor':is_mentor, + 'task':task, + 'claims':claims, + 'user_can_claim':user_can_claim, + 'task_claimable':task_claimable, + 'errors':errors} if not is_guest: - if task_claimable: - pass + if request.method == "POST": + claim_proposal = request.POST['message'] + if claim_proposal: + addClaim(task, claim_proposal, user) + return redirect(claim_url) + else: + errors.append('Please fill up proposal in the field below') + return render_to_response('task/claim.html', context) else: - return show_msg('You are not logged in to view claims for this task', task_url, 'view the task') + return render_to_response('task/claim.html', context) else: return show_msg('You are not logged in to view claims for this task', 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. + """ + task_url = "/task/view/tid=%s"%tid + user = request.user + task = Task.objects.get(id=tid) + + is_guest = True if not user.is_authenticated() else False + is_mentor = True if user in task.mentors.all() else False + + task_claimed = True if task.status == "CL" else False + + if (not is_guest) and is_mentor: + if task_claimed: + user_list = ((user.id,user.username) for user in task.claimed_users.all()) + form = AssignTaskForm(user_list) + + if request.method == "POST": + uid = request.POST['user'] + assigned_user = User.objects.get(id=uid) + assignTask(task, assigned_user) + return redirect(task_url) + else: + return render_to_response('task/assign.html',{'form':form}) + else: + return show_msg('The task is already assigned', task_url, 'view the task') + else: + return show_msg('You are not authorised to perform this action', task_url, 'view the task') + diff --git a/templates/task/assign.html b/templates/task/assign.html new file mode 100644 index 0000000..232b56d --- /dev/null +++ b/templates/task/assign.html @@ -0,0 +1,8 @@ +{% extends 'base.html' %} +{% block content %} + Select a user to assign this task.<br /> + <form action="" method="POST"> + {{form.as_table}} + <input type="submit" value="Assign Task"> + </form> +{% endblock %} diff --git a/templates/task/claim.html b/templates/task/claim.html new file mode 100644 index 0000000..e758f42 --- /dev/null +++ b/templates/task/claim.html @@ -0,0 +1,25 @@ +{% extends 'base.html' %} +{% block content %} + List of all the claims for the task <a href="/task/view/tid={{task.id}}">{{task.title}}</a><br /> + {% for claim in claims %} + <hr /> + <a href="/user/view/uid={{claim.user.id}}">{{claim.user.username}}</a> at {{claim.creation_datetime.ctime}} wrote:<br /> + {{claim.message}}<br /> + {% endfor %} + {% if task_claimable and is_mentor %} + <a href="/task/assign/tid={{task.id}}">Assign task</a> + {% endif %} + {% if user_can_claim %} + <hr /> + {% if errors %} + {% for error in errors %} + {{error}}<br /> + {% endfor %} + {% endif %} + Claim the task:<br /> + <form action="" method="post"> + <textarea name="message"></textarea><br /> + <input type="submit" value="Submit Claim"> + </form> + {% endif %} +{% endblock %} diff --git a/templates/task/view.html b/templates/task/view.html index b20356b..ebeacca 100644 --- a/templates/task/view.html +++ b/templates/task/view.html @@ -20,12 +20,15 @@ <br />{{ task.desc }}<br /> <hr> status of task is {{task.status}}<br /> - {% if user_can_view_claim %} + {% if assigned_user %} + Task has been assigned to <a href="/user/view/uid={{assigned_user.id}}">{{assigned_user.username}}</a><br /> + {% endif %} + {% if not is_guest %} <a href="/task/claim/tid={{task.id}}">View claims</a><br /> - view claims goes here depending on availability of claim<br /> {% endif %} {% if comments %} + <hr /> <br/>comments:<br /> {% for comment in comments %} <br /><a href="/user/view/uid={{comment.created_by.id}}">{{ comment.created_by.username }}</a> at {{ comment.creation_datetime.ctime }} wrote:<br /> @@ -4,8 +4,8 @@ from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() -from pytask.taskapp.views.user import homepage, register, user_login, user_logout, view_my_profile, edit_my_profile -from pytask.taskapp.views.task import browse_tasks, view_task, create_task, add_mentor, add_tasks, claim_task +from pytask.taskapp.views.user import homepage, register, user_login, user_logout +from pytask.taskapp.views.task import browse_tasks, view_task, create_task, add_mentor, add_tasks, claim_task, assign_task urlpatterns = patterns('', # Example: @@ -23,6 +23,7 @@ urlpatterns = patterns('', (r'^task/addmentor/tid=(\d+)', add_mentor), (r'^task/addtasks/tid=(\d+)', add_tasks), (r'^task/claim/tid=(\d+)', claim_task), + (r'^task/assign/tid=(\d+)', assign_task), (r'^admin/', include(admin.site.urls)), |