diff options
author | nishanth | 2010-03-02 03:21:20 +0530 |
---|---|---|
committer | nishanth | 2010-03-02 03:21:20 +0530 |
commit | 26c34400dcbf963086e3cc5d812dc7f1333d5cc5 (patch) | |
tree | b08ed2707efb73e54f073180a894e0814deaef1a | |
parent | c96afacd4dd27cbf092eb398862ac9dc120e9309 (diff) | |
download | pytask-26c34400dcbf963086e3cc5d812dc7f1333d5cc5.tar.gz pytask-26c34400dcbf963086e3cc5d812dc7f1333d5cc5.tar.bz2 pytask-26c34400dcbf963086e3cc5d812dc7f1333d5cc5.zip |
implemented deleting of a task.
-rw-r--r-- | taskapp/events/task.py | 14 | ||||
-rw-r--r-- | taskapp/models.py | 5 | ||||
-rw-r--r-- | taskapp/utilities/notification.py | 14 | ||||
-rw-r--r-- | taskapp/views/task.py | 32 | ||||
-rw-r--r-- | taskapp/views/user.py | 2 | ||||
-rw-r--r-- | templates/task/view.html | 10 | ||||
-rw-r--r-- | urls.py | 3 |
7 files changed, 66 insertions, 14 deletions
diff --git a/taskapp/events/task.py b/taskapp/events/task.py index 6fd3fef..04cdd2d 100644 --- a/taskapp/events/task.py +++ b/taskapp/events/task.py @@ -230,8 +230,6 @@ def completeTask(task, marked_by): for a_mentor in task.mentors.all(): create_notification(role="CM", sent_to=a_mentor, sent_from=marked_by, task=task) - - def closeTask(task, closed_by, reason=None): """ set the status of task as CD. generate notifications accordingly. @@ -254,4 +252,16 @@ def closeTask(task, closed_by, reason=None): for a_mentor in task.mentors.all(): create_notification(role="CD", sent_to=a_mentor, sent_from=closed_by, task=task, remarks=reason) +def deleteTask(task, deleted_by, reason=None): + """ set the task status as DL + notify all its other viewers about the deleting of task. + """ + + task.status = "DL" + task.save() + + pending_requests = task.request_task.filter(is_replied=False,is_valid=True) + pending_requests.update(is_valid=False) + for a_mentor in task.mentors.exclude(id=deleted_by.id): + create_notification("DL", sent_to=a_mentor, sent_from=deleted_by, task=task, remarks=reason) diff --git a/taskapp/models.py b/taskapp/models.py index 9a58603..64809c9 100644 --- a/taskapp/models.py +++ b/taskapp/models.py @@ -43,11 +43,9 @@ NOTIFY_CHOICES = ( ("RU", "Remove user"), ## remove from working users list in task ) - IMAGES_DIR = "./images" UPLOADS_DIR = "./uploads" - class CustomImageStorage(FileSystemStorage): def path(self, name): @@ -87,7 +85,6 @@ class Profile(models.Model): def __unicode__(self): return unicode(self.user.username) - class Task(models.Model): prim_key = models.AutoField(primary_key = True) @@ -117,7 +114,6 @@ class Map(models.Model): main = models.ForeignKey('Task', related_name = "%(class)s_main") subs = models.ManyToManyField('Task', blank = True, null = True, related_name = "%(class)s_subs") - class Comment(models.Model): task = models.ForeignKey('Task') @@ -169,7 +165,6 @@ class Notification(models.Model): sent_from = models.ForeignKey(User, related_name = "%(class)s_sent_from", null = True, blank = True) task = models.ForeignKey(Task, related_name = "%(class)s_sent_for", null = True, blank = True) - sub = models.CharField(max_length = 100) message = models.TextField() remarks = models.CharField(max_length = 100) diff --git a/taskapp/utilities/notification.py b/taskapp/utilities/notification.py index 887b82e..b79d091 100644 --- a/taskapp/utilities/notification.py +++ b/taskapp/utilities/notification.py @@ -169,6 +169,7 @@ def create_notification(role, sent_to, sent_from=None, reply=None, task=None, re elif role == "AU": notification.task = task + notification.sent_from = sent_from added_user = sent_to mentor = sent_from assigned_by_url = '<a href="/user/view/uid=%s">%s</a>'%(mentor.id, mentor.username) @@ -194,6 +195,7 @@ def create_notification(role, sent_to, sent_from=None, reply=None, task=None, re elif role == "RU": notification.task = task + notification.sent_from = sent_from removed_user = sent_to mentor = sent_from removed_by_url = '<a href="/user/view/uid=%s">%s</a>'%(mentor.id, mentor.username) @@ -207,6 +209,18 @@ def create_notification(role, sent_to, sent_from=None, reply=None, task=None, re notification.remarks = remarks notification.message += "<b>Reason: </b>%s"%(remarks) + elif role == "DL": + + notification.sent_from = sent_from + notification.task = task + deleted_by_url = '<a href="/user/view/uid=%s">%s</a>'%(sent_from.id, sent_from.username) + + notification.sub = "Task deleted" + notification.message = 'The unpublished task "%s" viewable by you has been deleted by its creator %s.<br />'%(task.title, deleted_by_url) + + if remarks: + notification.remarks = remarks + notification.message += "<b>Reason: </b>%s"%remarks notification.save() diff --git a/taskapp/views/task.py b/taskapp/views/task.py index 85041a0..4438401 100644 --- a/taskapp/views/task.py +++ b/taskapp/views/task.py @@ -6,7 +6,7 @@ from django.shortcuts import render_to_response, redirect from pytask.taskapp.models import User, Task, Comment, Claim, Request, Notification from pytask.taskapp.utilities.task import getTask from pytask.taskapp.forms.task import TaskCreateForm, AddMentorForm, AddTaskForm, ChoiceForm, AssignCreditForm, RemoveUserForm, EditTaskForm -from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask, closeTask, addMentor +from pytask.taskapp.events.task import createTask, reqMentor, publishTask, addSubTask, addDep, addClaim, assignTask, updateTask, removeTask, removeUser, assignCredits, completeTask, closeTask, addMentor, deleteTask from pytask.taskapp.views.user import show_msg from pytask.taskapp.utilities.user import get_user @@ -85,8 +85,9 @@ def view_task(request, tid): context['task_viewable'] = True if ( task.status != "UP" ) or is_mentor else False context['can_publish'] = True if task.status == "UP" and user == task.created_by else False - context['can_edit'] = True if ( not claimed_users ) and task.status in ["UP", "LO", "OP"] and is_mentor else False + context['can_edit'] = True if task.status == "UP" and is_mentor else False context['can_close'] = True if task.status not in ["UP", "CD", "CM"] and is_mentor else False + context['can_delete'] = True if task.status == "UP" and user == task.created_by else False context['can_mod_mentors'] = True if task.status in ["UP", "OP", "LO", "WR"] and is_mentor else False context['can_mod_tasks'] = True if task.status in ["UP", "OP", "LO"] and is_mentor else False @@ -632,3 +633,30 @@ def close_task(request, tid): return show_msg(user, "The task is either already closed or cannot be closed at this stage", task_url, "view the task") else: return show_msg(user, "You are not authorised to do this", task_url, "view the task") + + +def delete_task(request, tid): + """ mark the task status as DL. + take a reason from the user and pass on to all the other mentors. + """ + + task_url = "/task/view/tid=%s"%tid + + task = getTask(tid) + user = get_user(request.user) if request.user.is_authenticated() else request.user + + if task.status == "DL": + return show_msg(user, "This task no longer exists", '/task/browse/', "to browse other tasks") + + can_delete = True if task.status == "UP" and task.created_by == user else False + + if can_delete: + if request.method == "POST": + data = request.POST + reason = data.get('reason', None) + deleteTask(task, user, reason) + return show_msg(user, "The task is deleted", '/', "to return to home page") + else: + return render_to_response('task/delete.html',{'user':user,}) + else: + return show_msg(user, "You are not authorised to do this at this stage", task_url, "view the task") diff --git a/taskapp/views/user.py b/taskapp/views/user.py index 381efe1..e85b66a 100644 --- a/taskapp/views/user.py +++ b/taskapp/views/user.py @@ -18,7 +18,7 @@ from pytask.taskapp.utilities.user import get_user about = { "addmentors":"about/addmentors.html", - "mentor":"about/mentor.html", + "mentor":"about/mentor.html", ## - include role in different stages and merge with mentorrights ## "claimtask": ## "edittask": - contains both about up and pub states ## "mentorrights": diff --git a/templates/task/view.html b/templates/task/view.html index bae80c5..d565a13 100644 --- a/templates/task/view.html +++ b/templates/task/view.html @@ -10,12 +10,16 @@ <a href="/task/edit/tid={{task.id}}">Edit task</a> {% endif %} + {% if can_publish %} + <a href="/task/publish/tid={{task.id}}">Publish task</a> + {% endif %} + {% if can_close %} <a href="/task/close/tid={{task.id}}">Close this task</a> {% endif %} - - {% if can_publish %} - <a href="/task/publish/tid={{task.id}}">Publish task</a> + + {% if can_delete %} + <a href="/task/delete/tid={{task.id}}">Delete task</a> {% endif %} <hr />created by <a href="/user/view/uid={{ task.created_by.id }}">{{ task.created_by.username }}</a> @@ -26,7 +26,7 @@ urlpatterns = patterns('', (r'^task/browse/$', taskViews.browse_tasks), (r'^task/view/tid=(\w+)$', taskViews.view_task), (r'^task/create/$', taskViews.create_task), - (r'task/publish/tid=(\w+)/$', taskViews.publish_task), + (r'^task/publish/tid=(\w+)/$', taskViews.publish_task), (r'^task/addmentor/tid=(\w+)$', taskViews.add_mentor), (r'^task/edit/tid=(\w+)$', taskViews.edit_task), (r'^task/claim/tid=(\w+)$', taskViews.claim_task), @@ -37,6 +37,7 @@ urlpatterns = patterns('', (r'^task/assigncredits/tid=(\w+)$', taskViews.assign_credits), (r'^task/complete/tid=(\w+)$', taskViews.complete_task), (r'^task/close/tid=(\w+)$', taskViews.close_task), + (r'^task/delete/tid=(\w+)$', taskViews.delete_task), (r'^admin/', include(admin.site.urls)), |