[ckan-changes] [okfn/ckan] 5a9741: [2347] viewcount migration and related on user pag...

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


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

  Changed paths:
    M ckan/controllers/user.py
    M ckan/lib/dictization/model_dictize.py
    A ckan/migration/versions/058_add_related_viewcount.py
    M ckan/templates/user/read.html

  Log Message:
  -----------
  [2347] viewcount migration and related on user page


diff --git a/ckan/controllers/user.py b/ckan/controllers/user.py
index d17df6f..d836a45 100644
--- a/ckan/controllers/user.py
+++ b/ckan/controllers/user.py
@@ -91,6 +91,7 @@ def read(self, id=None):
         except NotAuthorized:
             abort(401, _('Not authorized to see this page'))
 
+        context['with_related'] = True
         try:
             user_dict = get_action('user_show')(context,data_dict)
         except NotFound:
diff --git a/ckan/lib/dictization/model_dictize.py b/ckan/lib/dictization/model_dictize.py
index 74aa8b7..d95950c 100644
--- a/ckan/lib/dictization/model_dictize.py
+++ b/ckan/lib/dictization/model_dictize.py
@@ -355,6 +355,13 @@ def user_dictize(user, context):
     result_dict['number_of_edits'] = user.number_of_edits()
     result_dict['number_administered_packages'] = user.number_administered_packages()
 
+    model = context['model']
+    session = model.Session
+
+    if context.get('with_related'):
+        result_dict['related_items'] = session.query(model.Related).\
+                        filter(model.Related.owner_id==user.id).all()
+
     return result_dict
 
 def task_status_dictize(task_status, context):
diff --git a/ckan/migration/versions/058_add_related_viewcount.py b/ckan/migration/versions/058_add_related_viewcount.py
new file mode 100644
index 0000000..f85493e
--- /dev/null
+++ b/ckan/migration/versions/058_add_related_viewcount.py
@@ -0,0 +1,11 @@
+from sqlalchemy import *
+from migrate import *
+
+def upgrade(migrate_engine):
+    migrate_engine.execute('''
+        ALTER TABLE "related"
+            ADD COLUMN view_count int NOT NULL DEFAULT 0;
+
+        UPDATE related SET view_count=0 WHERE view_count IS NULL;
+    '''
+    )
diff --git a/ckan/templates/user/read.html b/ckan/templates/user/read.html
index 681f0db..91b14c1 100644
--- a/ckan/templates/user/read.html
+++ b/ckan/templates/user/read.html
@@ -1,7 +1,7 @@
 <html xmlns:py="http://genshi.edgewall.org/"
   xmlns:xi="http://www.w3.org/2001/XInclude"
   py:strip="">
-  
+
   <py:def function="page_title">${c.user_dict['display_name']} - User</py:def>
   <py:def function="page_heading">
     ${h.linked_gravatar(c.user_dict['email_hash'],48)}
@@ -14,7 +14,7 @@
     </span>
     </py:if>
   </py:def>
-  
+
   <div py:match="content" py:strip="">
     <div class="summary">
       <div class="row">
@@ -58,6 +58,10 @@
               <strong>${c.user_dict['number_of_edits']}</strong>
               <span>Edits</span>
             </li>
+            <li>
+                <strong>${len(c.user_dict['related_items'])}</strong>
+                <span>Related items</span>
+            </li>
           </ul>
         </div>
       </div><!-- /row -->


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



More information about the ckan-changes mailing list