[ckan-changes] [okfn/ckan] 3eac54: [2347] Added activity for deleting related items

GitHub noreply at github.com
Thu May 3 14:30:22 UTC 2012


  Branch: refs/heads/feature-2347-related-dashboard
  Home:   https://github.com/okfn/ckan
  Commit: 3eac5416da57d42a4b5ee9ae48b30efffbfc9f6b
      https://github.com/okfn/ckan/commit/3eac5416da57d42a4b5ee9ae48b30efffbfc9f6b
  Author: Ross Jones <rossdjones at gmail.com>
  Date:   2012-05-03 (Thu, 03 May 2012)

  Changed paths:
    M ckan/logic/action/delete.py
    M ckan/logic/action/get.py
    M ckan/logic/validators.py
    A ckan/templates/activity_streams/deleted_related_item.html

  Log Message:
  -----------
  [2347] Added activity for deleting related items


diff --git a/ckan/logic/action/delete.py b/ckan/logic/action/delete.py
index c806a51..1084f47 100644
--- a/ckan/logic/action/delete.py
+++ b/ckan/logic/action/delete.py
@@ -3,11 +3,13 @@
 import ckan.logic
 import ckan.logic.action
 import ckan.plugins as plugins
+import ckan.lib.dictization.model_dictize as model_dictize
 
 # define some shortcuts
 ValidationError = ckan.logic.ValidationError
 NotFound = ckan.logic.NotFound
 check_access = ckan.logic.check_access
+get_action = ckan.logic.get_action
 
 def package_delete(context, data_dict):
 
@@ -65,8 +67,12 @@ def package_relationship_delete(context, data_dict):
     model.repo.commit()
 
 def related_delete(context, data_dict):
+    import ckan.logic.action as action
+
     model = context['model']
+    session = context['session']
     user = context['user']
+    userobj = model.User.get(user)
     id = data_dict['id']
 
     entity = model.Related.get(id)
@@ -76,6 +82,25 @@ def related_delete(context, data_dict):
 
     check_access('related_delete',context, data_dict)
 
+    related_dict = model_dictize.related_dictize(entity, context)
+    activity_dict = {
+        'user_id': userobj.id,
+        'object_id': entity.id,
+        'activity_type': 'deleted related item',
+    }
+    activity_dict['data'] = {
+        'related': related_dict
+    }
+    activity_create_context = {
+        'model': model,
+        'user': user,
+        'defer_commit':True,
+        'session': session
+    }
+
+    get_action('activity_create')(activity_create_context, activity_dict, ignore_auth=True)
+    session.commit()
+
     entity.delete()
     model.repo.commit()
 
diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py
index 0cc18d7..a45b90c 100644
--- a/ckan/logic/action/get.py
+++ b/ckan/logic/action/get.py
@@ -1262,6 +1262,10 @@ def render_changed_resource_activity(context, activity, detail):
     return render('activity_streams/changed_resource.html',
         extra_vars = {'activity': activity, 'detail': detail})
 
+def render_deleted_related_activity(context, activity):
+    return render('activity_streams/deleted_related_item.html',
+        extra_vars = {'activity': activity})
+
 def render_deleted_resource_activity(context, activity, detail):
     return render('activity_streams/deleted_resource.html',
         extra_vars = {'activity': activity, 'detail': detail})
@@ -1352,7 +1356,8 @@ def render_deleted_group_activity(context, activity):
   'new group' : render_new_group_activity,
   'changed group' : render_changed_group_activity,
   'deleted group' : render_deleted_group_activity,
-  'new related item': render_new_related_activity
+  'new related item': render_new_related_activity,
+  'deleted related item': render_deleted_related_activity
   }
 
 def _activity_list_to_html(context, activity_stream):
diff --git a/ckan/logic/validators.py b/ckan/logic/validators.py
index 3ca2e10..3f58a78 100644
--- a/ckan/logic/validators.py
+++ b/ckan/logic/validators.py
@@ -160,7 +160,8 @@ def activity_type_exists(activity_type):
     'new group' : group_id_exists,
     'changed group' : group_id_exists,
     'deleted group' : group_id_exists,
-    'new related item': related_id_exists
+    'new related item': related_id_exists,
+    'deleted related item': related_id_exists
     }
 
 def object_id_validator(key, activity_dict, errors, context):
diff --git a/ckan/templates/activity_streams/deleted_related_item.html b/ckan/templates/activity_streams/deleted_related_item.html
new file mode 100644
index 0000000..bf615e1
--- /dev/null
+++ b/ckan/templates/activity_streams/deleted_related_item.html
@@ -0,0 +1,14 @@
+<html
+  xmlns="http://www.w3.org/1999/xhtml"
+  xmlns:i18n="http://genshi.edgewall.org/i18n"
+  xmlns:py="http://genshi.edgewall.org/"
+  xmlns:xi="http://www.w3.org/2001/XInclude"
+  py:strip=""
+  >
+${h.activity_div(
+  template=_("{actor} deleted the related item {object}"),
+  activity=activity,
+  actor=h.linked_user(activity.user_id),
+  object=activity.data.related.title,
+  )}
+</html>


================================================================



More information about the ckan-changes mailing list