From 8dff30125e4a169b28cdc8242041e4e92b5b0718 Mon Sep 17 00:00:00 2001
From: nishanth
Date: Fri, 26 Feb 2010 02:52:32 +0530
Subject: added the functionality to publish a task.
---
taskapp/events/task.py | 3 +++
taskapp/management/commands/seed_db.py | 2 +-
taskapp/views/task.py | 28 ++++++++++++++++++++++++++++
taskapp/views/user.py | 2 +-
templates/show_msg.html | 2 +-
templates/task/publish.html | 14 ++++++++++++++
templates/task/view.html | 24 +++++++++++++++++-------
urls.py | 1 +
8 files changed, 66 insertions(+), 10 deletions(-)
create mode 100644 templates/task/publish.html
diff --git a/taskapp/events/task.py b/taskapp/events/task.py
index 323c8cf..86f8a47 100644
--- a/taskapp/events/task.py
+++ b/taskapp/events/task.py
@@ -14,6 +14,9 @@ def publishTask(task):
task.status = "LO"
else:
task.status = "OP"
+
+ task.mentors.clear()
+ task.mentors.add(task.created_by)
task.save()
return task
diff --git a/taskapp/management/commands/seed_db.py b/taskapp/management/commands/seed_db.py
index 60b2a56..4e65065 100644
--- a/taskapp/management/commands/seed_db.py
+++ b/taskapp/management/commands/seed_db.py
@@ -32,7 +32,7 @@ def seed_db():
task = taskEvents.createTask(title,desc,created_by,credits)
if task:
taskEvents.addMentor(task, defaultMentor)
- taskEvents.publishTask(task)
+ if i%2==0:taskEvents.publishTask(task)
class Command(NoArgsCommand):
diff --git a/taskapp/views/task.py b/taskapp/views/task.py
index 93e4722..443d84e 100644
--- a/taskapp/views/task.py
+++ b/taskapp/views/task.py
@@ -22,6 +22,33 @@ def browse_tasks(request):
}
return render_to_response('task/browse.html', context)
+def publish_task(request, tid):
+ """ check if user is the mentor and also if the task status is UP.
+ """
+
+ 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 user in task.mentors.all() else False
+
+ if user==task.created_by:
+ context = {
+ 'user':user,
+ }
+
+ if request.method == "POST":
+ publishTask(task)
+ return show_msg(user, "The task has been published", task_url, "view the task")
+ else:
+ return render_to_response('task/publish.html', context)
+ else:
+ return show_msg(user, "You are not authorised to do this", '/task/browse/', "browse tasks")
+
+
+
def view_task(request, tid):
""" get the task depending on its tid and display accordingly if it is a get.
check for authentication and add a comment if it is a post request.
@@ -54,6 +81,7 @@ def view_task(request, tid):
'errors':errors,
}
+ context['can_publish'] = True if task.status == "UP" and user == task.created_by else False
context['task_viewable'] = True if ( task.status not in ["UP", "DL"] ) or is_mentor else False
context['task_claimable'] = True if task.status in ["OP", "WR"] else False
diff --git a/taskapp/views/user.py b/taskapp/views/user.py
index 5b3bf17..27dbc81 100644
--- a/taskapp/views/user.py
+++ b/taskapp/views/user.py
@@ -13,7 +13,7 @@ from pytask.taskapp.events.request import reply_to_request
def show_msg(user, message, redirect_url=None, url_desc=None):
""" simply redirect to homepage """
- return render_to_response('show_msg.html',{'message':message, 'redirect_url':redirect_url, 'url_desc':url_desc})
+ return render_to_response('show_msg.html',{'user':user, 'message':message, 'redirect_url':redirect_url, 'url_desc':url_desc})
def homepage(request):
""" check for authentication and display accordingly. """
diff --git a/templates/show_msg.html b/templates/show_msg.html
index 68bed9a..a05c5ac 100644
--- a/templates/show_msg.html
+++ b/templates/show_msg.html
@@ -4,7 +4,7 @@
{{message}}
{% endif %}
{% if redirect_url %}
- click here to return to {{url_desc}}
+ click here to return to {{url_desc}}
{% else %}
click here to return to Homepage
{% endif %}
diff --git a/templates/task/publish.html b/templates/task/publish.html
new file mode 100644
index 0000000..f232767
--- /dev/null
+++ b/templates/task/publish.html
@@ -0,0 +1,14 @@
+{% extends 'base.html' %}
+{% block title %}
+ {{task.title}}
+{% endblock %}
+{% block content %}
+ Disclaimer:
+ Publishing a task will make the task visible to every one.
+ All the existing mentors will be removed from the list of mentors and only you will have the rights to edit and mentor the task.
+ But mentors can be added by sending them a request later on.
+ Please confirm if you want to publish.
+