[ckan-changes] commit/ckanextiati: amercader: [license] Inherit license from publisher

Bitbucket commits-noreply at bitbucket.org
Mon Nov 14 11:33:25 UTC 2011


1 new commit in ckanextiati:


https://bitbucket.org/okfn/ckanextiati/changeset/7c77d68c0003/
changeset:   7c77d68c0003
user:        amercader
date:        2011-11-14 12:33:15
summary:     [license] Inherit license from publisher

License information can not be set at a dataset level, they are always
inherited from the publisher (group). The license field in the dataset
form has been removed.
affected #:  5 files

diff -r 95edb354c8d9669481e0437a9be023d27d46fb97 -r 7c77d68c0003549a2000d58bf4c38f59401e7bec README.txt
--- a/README.txt
+++ b/README.txt
@@ -49,7 +49,7 @@
 ckan.site_url = http://iati.test.ckan.net
 
 # Add any other plugins you want to use:
-ckan.plugins = iati_forms iati_approval iati_group_authz iati_package_authz wordpresser synchronous_search
+ckan.plugins = iati_forms iati_approval iati_group_authz iati_package_authz iati_license_override wordpresser synchronous_search
 
 # Use a proxy wordpress to provide help & about pages (etc)
 wordpresser.proxy_host = http://iatiregistry.wordpress.org/


diff -r 95edb354c8d9669481e0437a9be023d27d46fb97 -r 7c77d68c0003549a2000d58bf4c38f59401e7bec ckanext/iati/plugin.py
--- a/ckanext/iati/plugin.py
+++ b/ckanext/iati/plugin.py
@@ -2,10 +2,13 @@
 
 from logging import getLogger
 
+from ckan.model import Package, Group
 from ckan.plugins import implements, SingletonPlugin
 from ckan.plugins import IRoutes
 from ckan.plugins import IConfigurer
 from ckan.plugins import IActions
+from ckan.plugins import IGroupController
+from ckan.plugins import IPackageController
 
 import ckanext.iati
 
@@ -81,3 +84,34 @@
             'package_show_rest':package_show_rest_iati
         }
 
+class IatiLicenseOverride(SingletonPlugin):
+
+    implements(IGroupController,inherit=True)
+    implements(IPackageController,inherit=True)
+
+    def _override_license(self,group):
+        group_license_id = group.extras.get('license_id')
+
+        if group.packages and group_license_id:
+            # Check if license changed
+            if group.packages[0].license_id != group_license_id:
+                for package in group.packages:
+                    package.license_id = group_license_id
+
+    def create(self,entity):
+        if isinstance(entity,Package):
+            # Assign group's license to the newly created package
+            group = entity.groups[0] if len(entity.groups) else None
+            if group and group.extras.get('license_id'):
+                entity.license_id = group.extras.get('license_id')
+
+        elif isinstance(entity,Group):
+            self._override_license(entity)
+
+    def edit(self,entity):
+        if isinstance(entity,Package):
+            # Licenses are only handled at the group level
+            pass
+        elif isinstance(entity,Group):
+            self._override_license(entity)
+


diff -r 95edb354c8d9669481e0437a9be023d27d46fb97 -r 7c77d68c0003549a2000d58bf4c38f59401e7bec ckanext/iati/templates/_util_local.html
--- a/ckanext/iati/templates/_util_local.html
+++ b/ckanext/iati/templates/_util_local.html
@@ -9,7 +9,7 @@
         standard package listing --><ul py:def="package_list_local(packages)" class="packages"><li py:for="package in packages"
-        class="${'fullyopen' if (package.isopen and package.resources) else None}">
+        class="${'fullyopen' if ((package.isopen if isinstance(package.isopen,bool) else package.isopen()) and package.resources) else None}"><div class="header"><span class="title">
 				${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))}
@@ -26,7 +26,7 @@
           </ul></py:if><ul class="openness">
-          <py:if test="package.isopen">
+          <py:if test="package.isopen if isinstance(package.isopen,bool) else package.isopen()"><li><a href="http://opendefinition.org/okd/" title="This package satisfies the Open Definition."><img src="http://assets.okfn.org/images/ok_buttons/od_80x15_blue.png" alt="[Open Data]" />
@@ -38,7 +38,7 @@
               </a></li></py:if>
-          <py:if test="not package.isopen">
+          <py:if test="not (package.isopen if isinstance(package.isopen,bool) else package.isopen())"><li><span class="closed">
                 ${h.icon('lock')} Not Openly Licensed


diff -r 95edb354c8d9669481e0437a9be023d27d46fb97 -r 7c77d68c0003549a2000d58bf4c38f59401e7bec ckanext/iati/templates/package/form_iati.html
--- a/ckanext/iati/templates/package/form_iati.html
+++ b/ckanext/iati/templates/package/form_iati.html
@@ -101,16 +101,6 @@
             <dd><input id="language" name="language" size="40" type="text" value="${data.get('language', '')}" /></dd><dd class="instructions basic">The ISO 639-1 code for the default language of the file (e.g. 'en').</dd>
 
-            <dt><label class="field_opt" for="license_id">License</label></dt>
-            <dd>
-                <select id="license_id" name="license_id">
-                    <py:for each="licence_desc, licence_id in c.licences">
-                        <option value="${licence_id}" py:attrs="{'selected': 'selected' if data.get('license_id', '') == licence_id else None}" >${licence_desc}</option>
-                    </py:for>
-                </select>
-            </dd>
-            <dd class="instructions basic">Choose from the dropdown the appropriate licence under which your data is being published. This will  already contain the licence specified in your publisher record, For more information on IATI's licensing guidelines go to <a href="http://iatistandard.org/standard/licencing">http://iatistandard.org/standard/licencing</a>.</dd>
-
             <dt><label class="field_opt" for="tags">Tags</label></dt><dd><input class="autocomplete-tag" id="tag_string" name="tag_string" size="40" type="text"


diff -r 95edb354c8d9669481e0437a9be023d27d46fb97 -r 7c77d68c0003549a2000d58bf4c38f59401e7bec setup.py
--- a/setup.py
+++ b/setup.py
@@ -32,7 +32,8 @@
       iati_package_authz = ckanext.iati.authz:IatiPackageAuthzExtension
       iati_forms = ckanext.iati.plugin:IatiForms
       iati_actions = ckanext.iati.plugin:IatiActions
-      
+      iati_license_override = ckanext.iati.plugin:IatiLicenseOverride
+
       [paste.paster_command]
       create-iati-fixtures = ckanext.iati.fixtures:CreateIatiFixtures
       iati-archiver=ckanext.iati.commands:Archiver

Repository URL: https://bitbucket.org/okfn/ckanextiati/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list