added the functionality to publish a task.
authornishanth
Fri, 26 Feb 2010 02:52:32 +0530
changeset 111 c272d4c601cd
parent 110 3685c2333448
child 112 eadff01e395e
added the functionality to publish a task.
taskapp/events/task.py
taskapp/management/commands/seed_db.py
taskapp/views/task.py
taskapp/views/user.py
templates/show_msg.html
templates/task/publish.html
templates/task/view.html
urls.py
--- a/taskapp/events/task.py	Fri Feb 26 01:51:55 2010 +0530
+++ b/taskapp/events/task.py	Fri Feb 26 02:52:32 2010 +0530
@@ -14,6 +14,9 @@
         task.status = "LO"
     else:
         task.status = "OP"
+
+    task.mentors.clear()
+    task.mentors.add(task.created_by)
     task.save()
     return task
 
--- a/taskapp/management/commands/seed_db.py	Fri Feb 26 01:51:55 2010 +0530
+++ b/taskapp/management/commands/seed_db.py	Fri Feb 26 02:52:32 2010 +0530
@@ -32,7 +32,7 @@
         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):
     
--- a/taskapp/views/task.py	Fri Feb 26 01:51:55 2010 +0530
+++ b/taskapp/views/task.py	Fri Feb 26 02:52:32 2010 +0530
@@ -22,6 +22,33 @@
                }
     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 @@
                '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
 
--- a/taskapp/views/user.py	Fri Feb 26 01:51:55 2010 +0530
+++ b/taskapp/views/user.py	Fri Feb 26 02:52:32 2010 +0530
@@ -13,7 +13,7 @@
 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. """
--- a/templates/show_msg.html	Fri Feb 26 01:51:55 2010 +0530
+++ b/templates/show_msg.html	Fri Feb 26 02:52:32 2010 +0530
@@ -4,7 +4,7 @@
         {{message}}<br />
     {% endif %}
     {% if redirect_url %}
-        <a href={{redirect_url}}>click here</a> to return to {{url_desc}}
+        <a href="{{redirect_url}}">click here</a> to return to {{url_desc}}
     {% else %}
         <a href="/">click here</a> to return to Homepage
     {% endif %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/task/publish.html	Fri Feb 26 02:52:32 2010 +0530
@@ -0,0 +1,14 @@
+{% extends 'base.html' %}
+{% block title %}
+    {{task.title}}
+{% endblock %}
+{% block content %}
+    <b>Disclaimer:</b><br />
+    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.<br /><br />
+    Please confirm if you want to publish.
+    <form action="" method="post">
+        <input value="Publish" type="submit">
+    </form>
+{% endblock %}
--- a/templates/task/view.html	Fri Feb 26 01:51:55 2010 +0530
+++ b/templates/task/view.html	Fri Feb 26 02:52:32 2010 +0530
@@ -4,20 +4,30 @@
 {% endblock %}
 {% block content %}
     {% if task_viewable %}
-        {% if is_mentor %}
-            <a href="/task/edit/tid={{task.id}}">Edit task</a>
-        {% endif %}
         <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:
+        {% if is_mentor %}
+            <a href="/task/edit/tid={{task.id}}">Edit task</a>
+            {% if can_publish %}|<a href="/task/publish/tid={{task.id}}">Publish task</a>{% endif %}
+            <br />
+        {% endif %}
+        
+        {% ifequal task.status "UP" %}
+            Task can be viewed by:
+        {% else %}
+            Mentors:
+        {% endifequal %}
         {% for mentor in mentors %}
             <a href="/user/view/uid={{mentor.id}}">{{mentor.username}}|</a>
         {% endfor %}
         {% if can_mod_mentors %}
-            <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 />
+            <a href="/task/addmentor/tid={{task.id}}">
+            {% ifequal task.status "UP" %}
+                Request others to view/edit the task
+            {% else %}
+                Add another Mentor to this task
+            {% endifequal %}</a><br />
         {% endif %}
 
         {% if deps %}
--- a/urls.py	Fri Feb 26 01:51:55 2010 +0530
+++ b/urls.py	Fri Feb 26 02:52:32 2010 +0530
@@ -26,6 +26,7 @@
     (r'^task/browse/$', taskViews.browse_tasks),
     (r'^task/view/tid=(\d+)$', taskViews.view_task),
     (r'^task/create/$', taskViews.create_task),
+    (r'task/publish/tid=(\d+)/$', taskViews.publish_task),
     (r'^task/addmentor/tid=(\d+)$', taskViews.add_mentor),
     #(r'^task/addtasks/tid=(\d+)', taskViews.add_tasks),
     (r'^task/edit/tid=(\d+)$', taskViews.edit_task),