# HG changeset patch # User nishanth # Date 1265303235 -19800 # Node ID c28774fe7ffd926c1f2ee01dd6657243e73fdf8a # Parent ec7b1751c161c7876289b10a1dfba6a29e1938dc implemented "add another mentor" functionality to a task. diff -r ec7b1751c161 -r c28774fe7ffd taskapp/events/task.py --- a/taskapp/events/task.py Thu Feb 04 22:34:22 2010 +0530 +++ b/taskapp/events/task.py Thu Feb 04 22:37:15 2010 +0530 @@ -21,7 +21,7 @@ """ 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 @@ 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 -r ec7b1751c161 -r c28774fe7ffd taskapp/forms/task.py --- a/taskapp/forms/task.py Thu Feb 04 22:34:22 2010 +0530 +++ b/taskapp/forms/task.py Thu Feb 04 22:37:15 2010 +0530 @@ -6,3 +6,16 @@ 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 -r ec7b1751c161 -r c28774fe7ffd taskapp/models.py --- a/taskapp/models.py Thu Feb 04 22:34:22 2010 +0530 +++ b/taskapp/models.py Thu Feb 04 22:37:15 2010 +0530 @@ -96,4 +96,11 @@ 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 -r ec7b1751c161 -r c28774fe7ffd taskapp/views/task.py --- a/taskapp/views/task.py Thu Feb 04 22:34:22 2010 +0530 +++ b/taskapp/views/task.py Thu Feb 04 22:37:15 2010 +0530 @@ -3,11 +3,14 @@ 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 @@ 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 @@ context = {'user':user, 'task':task, 'comments':comments, + 'mentors':mentors, 'is_guest':is_guest, 'is_mentor':is_mentor, 'errors':errors, @@ -94,6 +99,78 @@ 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) @@ -101,10 +178,3 @@ - - - - - - - diff -r ec7b1751c161 -r c28774fe7ffd taskapp/views/user.py --- a/taskapp/views/user.py Thu Feb 04 22:34:22 2010 +0530 +++ b/taskapp/views/user.py Thu Feb 04 22:37:15 2010 +0530 @@ -6,10 +6,10 @@ 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 @@ 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): diff -r ec7b1751c161 -r c28774fe7ffd templates/show_msg.html --- a/templates/show_msg.html Thu Feb 04 22:34:22 2010 +0530 +++ b/templates/show_msg.html Thu Feb 04 22:37:15 2010 +0530 @@ -1,7 +1,11 @@ {% extends 'base.html' %} {% block content %} {% if message %} - {{message}}
- click here to return to Homepage + {{message}}
+ {% endif %} + {% if redirect_url %} + click here to return to {{url_desc}} + {% else %} + click here to return to Homepage {% endif %} {% endblock %} diff -r ec7b1751c161 -r c28774fe7ffd templates/task/addmentor.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/task/addmentor.html Thu Feb 04 22:37:15 2010 +0530 @@ -0,0 +1,8 @@ +{% extends 'base.html' %} +{% block content %} + Form here +
+ {{form.as_table}} + +
+{% endblock %} diff -r ec7b1751c161 -r c28774fe7ffd templates/task/view.html --- a/templates/task/view.html Thu Feb 04 22:34:22 2010 +0530 +++ b/templates/task/view.html Thu Feb 04 22:37:15 2010 +0530 @@ -7,8 +7,20 @@

{{ task.title }}


created by {{ task.created_by.username }} on {{ task.creation_datetime.ctime }}
+ Mentors: + {% for mentor in mentors %} + {{mentor.username}}| + {% endfor %} + {% if is_mentor %} +
Add another Mentor to this task
+ edit task goes here and it should contain all those add subs and add deps depending on availability
+ {% endif %} +

Description:

{{ task.desc }}
+
+ status of task is {{task.status}}
+ view claims goes here depending on availability of claim
{% if comments %}
comments:
{% for comment in comments %} @@ -16,7 +28,7 @@ {{ comment.data }}
{% endfor %} {% endif %} - + {% if not is_guest %}
Add comment:
diff -r ec7b1751c161 -r c28774fe7ffd urls.py --- a/urls.py Thu Feb 04 22:34:22 2010 +0530 +++ b/urls.py Thu Feb 04 22:37:15 2010 +0530 @@ -5,7 +5,7 @@ admin.autodiscover() from pytask.taskapp.views.user import homepage, register, user_login, user_logout -from pytask.taskapp.views.task import browse_tasks, view_task, create_task +from pytask.taskapp.views.task import browse_tasks, view_task, create_task, add_mentor, add_tasks urlpatterns = patterns('', # Example: @@ -19,6 +19,8 @@ (r'^task/browse/$', browse_tasks), (r'^task/view/tid=(\d+)$', view_task), (r'^task/create/$', create_task), + (r'^task/addmentor/tid=(\d+)', add_mentor), + (r'^task/addtasks/tid=(\d+)', add_tasks), (r'^admin/', include(admin.site.urls)),