implemented add another mentor functionality to a task.
--- a/pytask/taskapp/events/task.py Sat Jan 30 13:10:11 2010 +0530
+++ b/pytask/taskapp/events/task.py Mon Feb 01 11:10:29 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
--- a/pytask/taskapp/forms/task.py Sat Jan 30 13:10:11 2010 +0530
+++ b/pytask/taskapp/forms/task.py Mon Feb 01 11:10:29 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']
--- a/pytask/taskapp/models.py Sat Jan 30 13:10:11 2010 +0530
+++ b/pytask/taskapp/models.py Mon Feb 01 11:10:29 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()
+
--- a/pytask/taskapp/views/task.py Sat Jan 30 13:10:11 2010 +0530
+++ b/pytask/taskapp/views/task.py Mon Feb 01 11:10:29 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 @@
-
-
-
-
-
-
-
--- a/pytask/taskapp/views/user.py Sat Jan 30 13:10:11 2010 +0530
+++ b/pytask/taskapp/views/user.py Mon Feb 01 11:10:29 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):
--- a/pytask/templates/show_msg.html Sat Jan 30 13:10:11 2010 +0530
+++ b/pytask/templates/show_msg.html Mon Feb 01 11:10:29 2010 +0530
@@ -1,7 +1,11 @@
{% extends 'base.html' %}
{% block content %}
{% if message %}
- {{message}}<br />
- <a href="/">click here</a> to return to Homepage
+ {{message}}<br />
+ {% endif %}
+ {% if redirect_url %}
+ <a href={{redirect_url}}>click here</a> to return to {{url_desc}}
+ {% else %}
+ <a href="/">click here</a> to return to Homepage
{% endif %}
{% endblock %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pytask/templates/task/addmentor.html Mon Feb 01 11:10:29 2010 +0530
@@ -0,0 +1,8 @@
+{% extends 'base.html' %}
+{% block content %}
+ Form here
+ <form action="" method="post">
+ {{form.as_table}}
+ <input type="submit" value="submit">
+ </form>
+{% endblock %}
--- a/pytask/templates/task/view.html Sat Jan 30 13:10:11 2010 +0530
+++ b/pytask/templates/task/view.html Mon Feb 01 11:10:29 2010 +0530
@@ -7,8 +7,20 @@
<h3>{{ task.title }}</h3><br />
<!-- we have to write our own datetime.strftime filter and use in the next line -->
created by <a href="/user/view/uid={{ task.created_by.id }}">{{ task.created_by.username }}</a> on {{ task.creation_datetime.ctime }}<br />
+ Mentors:
+ {% for mentor in mentors %}
+ <a href="/user/view/uid={{mentor.id}}">{{mentor.username}}|</a>
+ {% endfor %}
+ {% if is_mentor %}
+ <br /><a href="/task/addmentor/tid={{task.id}}">Add another Mentor to this task</a><br />
+ edit task goes here and it should contain all those add subs and add deps depending on availability<br />
+ {% endif %}
+ <hr>
<br />Description:<br />
<br />{{ task.desc }}<br />
+ <hr>
+ status of task is {{task.status}}<br />
+ view claims goes here depending on availability of claim<br />
{% if comments %}
<br/>comments:<br />
{% for comment in comments %}
@@ -16,7 +28,7 @@
{{ comment.data }}<br />
{% endfor %}
{% endif %}
-
+
{% if not is_guest %}
<br />Add comment:<br />
<form action="" method="post">
--- a/pytask/urls.py Sat Jan 30 13:10:11 2010 +0530
+++ b/pytask/urls.py Mon Feb 01 11:10:29 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)),