diff options
-rw-r--r-- | taskapp/events/task.py | 9 | ||||
-rw-r--r-- | taskapp/forms/task.py | 13 | ||||
-rw-r--r-- | taskapp/models.py | 7 | ||||
-rw-r--r-- | taskapp/views/task.py | 76 | ||||
-rw-r--r-- | taskapp/views/user.py | 23 | ||||
-rw-r--r-- | templates/show_msg.html | 8 | ||||
-rw-r--r-- | templates/task/addmentor.html | 8 | ||||
-rw-r--r-- | templates/task/view.html | 14 | ||||
-rw-r--r-- | urls.py | 4 |
9 files changed, 144 insertions, 18 deletions
diff --git a/taskapp/events/task.py b/taskapp/events/task.py index c887a3c..85845b7 100644 --- a/taskapp/events/task.py +++ b/taskapp/events/task.py @@ -21,7 +21,7 @@ def createTask(title,desc,created_by,credits): """ 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 @@ def createTask(title,desc,created_by,credits): 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 --git a/taskapp/forms/task.py b/taskapp/forms/task.py index c185164..852109a 100644 --- a/taskapp/forms/task.py +++ b/taskapp/forms/task.py @@ -6,3 +6,16 @@ class TaskCreateForm(forms.ModelForm): 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 --git a/taskapp/models.py b/taskapp/models.py index 2b64e8d..0aa61f3 100644 --- a/taskapp/models.py +++ b/taskapp/models.py @@ -96,4 +96,11 @@ class Credit(models.Model): 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 --git a/taskapp/views/task.py b/taskapp/views/task.py index 67fda8c..99c02d2 100644 --- a/taskapp/views/task.py +++ b/taskapp/views/task.py @@ -3,11 +3,14 @@ from datetime import datetime 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 @@ def view_task(request, tid): 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 @@ def view_task(request, tid): context = {'user':user, 'task':task, 'comments':comments, + 'mentors':mentors, 'is_guest':is_guest, 'is_mentor':is_mentor, 'errors':errors, @@ -94,13 +99,78 @@ def create_task(request): 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) diff --git a/taskapp/views/user.py b/taskapp/views/user.py index ee174d1..92d8ee8 100644 --- a/taskapp/views/user.py +++ b/taskapp/views/user.py @@ -6,10 +6,10 @@ from pytask.taskapp.events.user import createUser 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 @@ def homepage(request): 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 --git a/templates/show_msg.html b/templates/show_msg.html index 1b5719a..68bed9a 100644 --- a/templates/show_msg.html +++ b/templates/show_msg.html @@ -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 %} diff --git a/templates/task/addmentor.html b/templates/task/addmentor.html new file mode 100644 index 0000000..21e7fc7 --- /dev/null +++ b/templates/task/addmentor.html @@ -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 %} diff --git a/templates/task/view.html b/templates/task/view.html index ed96462..7f096ed 100644 --- a/templates/task/view.html +++ b/templates/task/view.html @@ -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"> @@ -5,7 +5,7 @@ from django.contrib import admin 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 @@ urlpatterns = patterns('', (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)), |