Tasks may be deleted by pressing 'Delete' button on the edit view.
authorDaniel Hans <Daniel.M.Hans@gmail.com>
Sat, 14 Nov 2009 23:27:03 +0100
changeset 3091 a48f4e860f7b
parent 3090 cdbbe9ca465e
child 3092 beeb5d111318
Tasks may be deleted by pressing 'Delete' button on the edit view. An organization admin may delete a task entity, if the task is not claimed by anyone. Issue 695 fixed.
app/soc/modules/ghop/logic/models/task.py
app/soc/modules/ghop/views/models/task.py
app/taggable/taggable.py
--- a/app/soc/modules/ghop/logic/models/task.py	Sat Nov 14 18:24:36 2009 +0100
+++ b/app/soc/modules/ghop/logic/models/task.py	Sat Nov 14 23:27:03 2009 +0100
@@ -19,6 +19,7 @@
 
 __authors__ = [
     '"Madhusudan.C.S" <madhusudancs@gmail.com>',
+    '"Daniel Hans" <daniel.m.hans@gmail.com>',
     '"Lennard de Rijk" <ljvderijk@gmail.com>',
   ]
 
@@ -31,6 +32,9 @@
 from django.utils.translation import ugettext
 
 from soc.logic.models import base
+from soc.logic import tags
+
+from soc.modules.ghop.logic.models import comment as ghop_comment_logic
 
 import soc.models.linkable
 
@@ -45,6 +49,7 @@
     'NeedsWork': 'transitFromNeedsWork',
     }
 
+TAG_NAMES = ['arbit_tag', 'difficulty', 'task_type']
 
 class Logic(base.Logic):
   """Logic methods for the GHOPTask model.
@@ -70,6 +75,8 @@
     """Defines the name, key_name and model for this entity.
     """
 
+    self.tags_service = tags.TagsService(TAG_NAMES)
+
     super(Logic, self).__init__(model, base_model=base_model,
                                 scope_logic=scope_logic)
 
@@ -431,5 +438,23 @@
 
     return update_dict
 
+  def delete(self, entity):
+    """Delete existing entity from datastore.
+    """
+    
+    def task_delete_txn(entity):
+      """Performs all necessary operations in a single transaction when a task
+      is deleted.
+      """
+
+      to_delete = []    
+      to_delete += ghop_comment_logic.logic.getForFields(ancestors=[entity])
+      to_delete += [entity]
+    
+      db.delete(to_delete)
+  
+    self.tags_service.removeAllTagsForEntity(entity)
+    db.run_in_transaction(task_delete_txn, entity)
+
 
 logic = Logic()
--- a/app/soc/modules/ghop/views/models/task.py	Sat Nov 14 18:24:36 2009 +0100
+++ b/app/soc/modules/ghop/views/models/task.py	Sat Nov 14 23:27:03 2009 +0100
@@ -19,6 +19,7 @@
 
 __authors__ = [
     '"Madhusudan.C.S" <madhusudancs@gmail.com>',
+    '"Daniel Hans" <daniel.m.hans@gmail.com>',
     '"Lennard de Rijk" <ljvderijk@gmail.com>',
   ]
 
@@ -157,7 +158,10 @@
         ('checkRoleAndStatusForTask',
             [['ghop/org_admin'], ['active'],
             ['Unapproved', 'Unpublished', 'Open']])]
-    rights['delete'] = ['checkIsDeveloper']
+    rights['delete'] = [
+        ('checkRoleAndStatusForTask', 
+            [['ghop/org_admin'], ['active'],
+            ['Unapproved', 'Unpublished', 'Open']])]
     rights['show'] = ['checkStatusForTask']
     rights['list_org_tasks'] = [
         ('checkCanOrgAdminOrMentorEdit', ['scope_path', False])]
@@ -1442,6 +1446,28 @@
     # call the _list method from base to display the list
     return self._list(request, task_params, contents, page_name, context)
 
+  @decorators.merge_params
+  @decorators.check_access
+  def delete(self, request, access_type,
+             page_name=None, params=None, **kwargs):
+    """Shows the delete page for the entity specified by **kwargs.
+
+    Args:
+      request: the standard Django HTTP request object
+      access_type : the name of the access type which should be checked
+      page_name: the page name displayed in templates as page and header title
+      params: a dict with params for this View
+      kwargs: the Key Fields for the specified entity
+    """
+
+    params = params.copy()
+
+    params['delete_redirect'] = '/%s/list_org_tasks/%s' % (
+        params['url_name'], kwargs['scope_path'])
+
+    return super(View, self).delete(request, access_type, page_name=page_name,
+        params=params, **kwargs)
+
 
 view = View()
 
--- a/app/taggable/taggable.py	Sat Nov 14 18:24:36 2009 +0100
+++ b/app/taggable/taggable.py	Sat Nov 14 23:27:03 2009 +0100
@@ -323,3 +323,9 @@
       return tag_list
     else:
       return self.tag_separator.join(tag_list)
+
+  def tags_class(self, tag_name):
+    """Return a class instance object for a given tag name.
+    """
+
+    return self._tag_model[tag_name]