[ckan-changes] [okfn/ckan] 7cc252: [2347] Added activity for creating of related item...

GitHub noreply at github.com
Thu May 3 13:37:58 UTC 2012


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

  Changed paths:
    M ckan/logic/action/create.py
    M ckan/logic/action/get.py
    M ckan/logic/validators.py
    A ckan/templates/activity_streams/new_related_item.html
    M ckan/templates/related/add-related.html
    M ckan/templates/related/dashboard.html

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


diff --git a/ckan/logic/action/create.py b/ckan/logic/action/create.py
index 5da99b6..84f9921 100644
--- a/ckan/logic/action/create.py
+++ b/ckan/logic/action/create.py
@@ -116,6 +116,7 @@ def resource_create(context, data_dict):
 
 def related_create(context, data_dict):
     model = context['model']
+    session = context['session']
     user = context['user']
     userobj = model.User.get(user)
 
@@ -141,10 +142,30 @@ def related_create(context, data_dict):
         dataset.related.append( related )
         model.repo.commit_and_remove()
 
+    session.flush()
+
+    related_dict = model_dictize.related_dictize(related, context)
+    activity_dict = {
+            'user_id': userobj.id,
+            'object_id': related.id,
+            'activity_type': 'new related item',
+            }
+    activity_dict['data'] = {
+            'related': related_dict
+    }
+    activity_create_context = {
+        'model': model,
+        'user': user,
+        'defer_commit':True,
+        'session': session
+    }
+    activity_create(activity_create_context, activity_dict, ignore_auth=True)
+    session.commit()
+
     context["related"] = related
     context["id"] = related.id
     log.debug('Created object %s' % str(related.title))
-    return model_dictize.related_dictize(related, context)
+    return related_dict
 
 
 def package_relationship_create(context, data_dict):
diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py
index 4d26f89..0cc18d7 100644
--- a/ckan/logic/action/get.py
+++ b/ckan/logic/action/get.py
@@ -1245,6 +1245,11 @@ def render_new_package_activity(context, activity):
     return render('activity_streams/new_package.html',
         extra_vars = {'activity': activity})
 
+def render_new_related_activity(context, activity):
+    return render('activity_streams/new_related_item.html',
+        extra_vars = {'activity': activity,
+                      'type': activity['data']['related']['type']})
+
 def render_deleted_package_activity(context, activity):
     return render('activity_streams/deleted_package.html',
         extra_vars = {'activity': activity})
@@ -1347,6 +1352,7 @@ 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
   }
 
 def _activity_list_to_html(context, activity_stream):
diff --git a/ckan/logic/validators.py b/ckan/logic/validators.py
index 58c69ee..3ca2e10 100644
--- a/ckan/logic/validators.py
+++ b/ckan/logic/validators.py
@@ -114,6 +114,20 @@ def group_id_exists(group_id, context):
         raise Invalid('%s: %s' % (_('Not found'), _('Group')))
     return group_id
 
+
+def related_id_exists(related_id, context):
+    """Raises Invalid if the given related_id does not exist in the model
+    given in the context, otherwise returns the given related_id.
+
+    """
+    model = context['model']
+    session = context['session']
+
+    result = session.query(model.Related).get(related_id)
+    if not result:
+        raise Invalid('%s: %s' % (_('Not found'), _('Related')))
+    return related_id
+
 def group_id_or_name_exists(reference, context):
     """
     Raises Invalid if a group identified by the name or id cannot be found.
@@ -146,6 +160,7 @@ 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
     }
 
 def object_id_validator(key, activity_dict, errors, context):
diff --git a/ckan/templates/activity_streams/new_related_item.html b/ckan/templates/activity_streams/new_related_item.html
new file mode 100644
index 0000000..be06907
--- /dev/null
+++ b/ckan/templates/activity_streams/new_related_item.html
@@ -0,0 +1,13 @@
+<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} created the %s {object}"),
+        activity=activity,
+        actor=h.linked_user(activity.user_id),
+        object=h.link_to(activity.data.related['title'], h.url_for(controller='related', action='read', id=activity.data.related['id']))
+  ) % type}
+</html>
diff --git a/ckan/templates/related/add-related.html b/ckan/templates/related/add-related.html
index e5b2a64..fdda87d 100644
--- a/ckan/templates/related/add-related.html
+++ b/ckan/templates/related/add-related.html
@@ -21,7 +21,7 @@ <h3 class="heading">Add related item</h3>
       <div class="control-group">
         <label for="related-type">Type of item</label>
         <select id="related-type" name="type" class="span6 chzn-select">
-          <option value="app">Application</option>
+          <option value="application">Application</option>
           <option value="idea">Idea</option>
           <option value="visualization">Visualization</option>
         </select>
diff --git a/ckan/templates/related/dashboard.html b/ckan/templates/related/dashboard.html
index 39b4664..7149cd6 100644
--- a/ckan/templates/related/dashboard.html
+++ b/ckan/templates/related/dashboard.html
@@ -31,7 +31,7 @@ <h4 py:if="not c.page.item_count"><strong>${c.page.item_count}</strong> related
             <label for="type">Filter by type</label>
             <select name="type">
                 <option value="">All</option>
-                <option value="app" py:attrs="{'selected': 'selected' if c.filters.get('type') == 'app' else None}">Application</option>
+                <option value="application" py:attrs="{'selected': 'selected' if c.filters.get('type') == 'application' else None}">Application</option>
                 <option value="idea"  py:attrs="{'selected': 'selected' if c.filters.get('type') == 'idea' else None}">Idea</option>
                 <option value="visualization"  py:attrs="{'selected': 'selected' if c.filters.get('type') == 'visualization' else None}">Visualization</option>
             </select>


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



More information about the ckan-changes mailing list