From 0ed87d21ed2ac72bee897b98875764f6556f72ae Mon Sep 17 00:00:00 2001 From: Mark Gregson Date: Thu, 1 Dec 2016 15:45:16 +1100 Subject: [PATCH 1/4] Action rating_package_get is side_effect_free The get action doesn't cause a state change and so it is convenient to and okay to call it via a GET request. --- ckanext/rating/logic/action.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ckanext/rating/logic/action.py b/ckanext/rating/logic/action.py index 64e2ce2..e433c4d 100644 --- a/ckanext/rating/logic/action.py +++ b/ckanext/rating/logic/action.py @@ -50,6 +50,8 @@ def rating_package_create(context, data_dict): return Rating.get_package_rating(package.id) + +@toolkit.side_effect_free def rating_package_get(context, data_dict): package_id = data_dict.get('package_id') From 246b7140db7c9e1d492cac9edaeaa117472f2987 Mon Sep 17 00:00:00 2001 From: Mark Gregson Date: Thu, 1 Dec 2016 15:50:19 +1100 Subject: [PATCH 2/4] Add docstring for rating_package_get --- ckanext/rating/logic/action.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ckanext/rating/logic/action.py b/ckanext/rating/logic/action.py index 64e2ce2..c8449fd 100644 --- a/ckanext/rating/logic/action.py +++ b/ckanext/rating/logic/action.py @@ -51,6 +51,16 @@ def rating_package_create(context, data_dict): return Rating.get_package_rating(package.id) def rating_package_get(context, data_dict): + ''' + Get the rating and count of ratings for a package. + + Returns a dictionary containing rating and ratings counts. + + :param package_id: the id of the package + :type package_id: string + :rtype: dictionary + + ''' package_id = data_dict.get('package_id') error = None From ab387ccf24cf15d10cb5259bbf742b29fe9ce5dd Mon Sep 17 00:00:00 2001 From: Mark Gregson Date: Wed, 7 Dec 2016 11:00:23 +1100 Subject: [PATCH 3/4] Declare ckanext and ckanext.rating as namespace packages If the ckanext package is not declared as a namespace package the virtual environment is broken after a pip install. --- ckanext/rating/__init__.py | 7 +++++++ setup.py | 2 ++ 2 files changed, 9 insertions(+) diff --git a/ckanext/rating/__init__.py b/ckanext/rating/__init__.py index e69de29..2e2033b 100644 --- a/ckanext/rating/__init__.py +++ b/ckanext/rating/__init__.py @@ -0,0 +1,7 @@ +# this is a namespace package +try: + import pkg_resources + pkg_resources.declare_namespace(__name__) +except ImportError: + import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/setup.py b/setup.py index 83b2335..6cd1c68 100644 --- a/setup.py +++ b/setup.py @@ -55,6 +55,8 @@ setup( # simple. Or you can use find_packages(). packages=find_packages(exclude=['contrib', 'docs', 'tests*']), + namespace_packages=['ckanext', 'ckanext.rating'], + # List run-time dependencies here. These will be installed by pip when your # project is installed. For an analysis of "install_requires" vs pip's # requirements files see: From a8b5e00561f8a081f03613b49ec4809a952b09d2 Mon Sep 17 00:00:00 2001 From: Jari Voutilainen Date: Wed, 7 Dec 2016 09:03:39 +0200 Subject: [PATCH 4/4] Updated installation commands --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 29d8843..6236492 100644 --- a/README.rst +++ b/README.rst @@ -35,7 +35,7 @@ To install ckanext-rating: 2. Install the ckanext-rating Python package into your virtual environment:: - pip install ckanext-rating + pip install -e git+https://github.com/6aika/ckanext-rating.git#egg=ckanext-rating 3. Add ``rating`` to the ``ckan.plugins`` setting in your CKAN config file (by default the config file is located at @@ -62,4 +62,4 @@ do:: git clone https://github.com/6aika/ckanext-rating.git cd ckanext-rating python setup.py develop - pip install -r dev-requirements.txt \ No newline at end of file + pip install -r dev-requirements.txt