# HG changeset patch # User nishanth # Date 1267058275 -19800 # Node ID 1a1e712e60fd56e6d71d9b2d774b464c72e8daae # Parent c99f09bebe5633f7c31d929a552858fcd567c9eb finished assign_credits view. hav to integrate it with requests now. diff -r c99f09bebe56 -r 1a1e712e60fd taskapp/forms/task.py --- a/taskapp/forms/task.py Thu Feb 25 04:38:50 2010 +0530 +++ b/taskapp/forms/task.py Thu Feb 25 06:07:55 2010 +0530 @@ -41,3 +41,10 @@ task = forms.ChoiceField(choices=task_choices) return myForm() + +def AssignCreditForm(choices, instance=None): + + class myForm(forms.Form): + user = forms.ChoiceField(choices=choices, required=True) + points = forms.IntegerField(min_value=0,required=True) + return myForm(instance) if instance else myForm() diff -r c99f09bebe56 -r 1a1e712e60fd taskapp/views/task.py --- a/taskapp/views/task.py Thu Feb 25 04:38:50 2010 +0530 +++ b/taskapp/views/task.py Thu Feb 25 06:07:55 2010 +0530 @@ -3,8 +3,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, AddTaskForm, ChoiceForm +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.views.user import show_msg @@ -338,7 +338,60 @@ return show_msg('Wait for ppl to claim dude... slow and steady wins the race :)', task_url, 'view the task') else: return show_msg('You are not authorised to perform this action', task_url, 'view the task') - + +def assign_credits(request, tid): + """ Check if the user is a mentor and credits can be assigned. + Then display all the approved credits. + Then see if mentor can assign credits to users also or only mentors. + Then put up a form for mentor to assign credits accordingly. + """ + + 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 (not is_guest) and user in task.mentors.all() else False + + if is_mentor: + if task.status in ["OP", "WR"]: + choices = [(_.id,_.username) for _ in task.mentors.all()] + if task.status == "WR": + choices.extend([(_.id, _.username) for _ in task.assigned_users.all() ]) + prev_credits = task.credit_set.all() + ## here we can ditchax credits model and use the request model + form = AssignCreditForm(choices) + + context = { + 'user':user, + 'prev_credits':prev_credits, + 'form':form, + } + + if request.method == "POST": + data = request.POST + form = AssignCreditForm(choices, data) + if form.is_valid(): + data = form.cleaned_data + 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() + return redirect('/task/assigncredits/tid=%s'%task.id) + else: + context['form'] = form + return render_to_response('task/assigncredits.html', context) + else: + return render_to_response('task/assigncredits.html', context) + else: + return show_msg("Credits cannot be assigned at this stage", task_url, "view the task") + else: + return show_msg("You are not authorised to perform this action", task_url, "view the task") + def edit_task(request, tid): """ see what are the attributes that can be edited depending on the current status and then give the user fields accordingly. diff -r c99f09bebe56 -r 1a1e712e60fd templates/task/assigncredits.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/task/assigncredits.html Thu Feb 25 06:07:55 2010 +0530 @@ -0,0 +1,20 @@ +{% extends 'base.html' %} +{% block title %} + {{task.title}} +{% endblock %} +{% block content %} + + {% if prev_credits %} +
+
Previous credits:
+ {% for credit in prev_credits %} + {{credit.points}} pynts were given by {{credit.given_by.username}} to + {{credit.given_to.username}} at {{credit.given_time.ctime}}
+ {% endfor %} + {% endif %} + +
+ {{form.as_p}} + +
+{% endblock %} diff -r c99f09bebe56 -r 1a1e712e60fd urls.py --- a/urls.py Thu Feb 25 04:38:50 2010 +0530 +++ b/urls.py Thu Feb 25 06:07:55 2010 +0530 @@ -33,6 +33,7 @@ (r'^task/assign/tid=(\d+)$', taskViews.assign_task), (r'^task/addtask/tid=(\d+)$', taskViews.add_tasks), (r'^task/remtask/tid=(\d+)$', taskViews.remove_task), + (r'^task/assigncredits/tid=(\d+)$', taskViews.assign_credits), (r'^admin/', include(admin.site.urls)),