related auth func
related auth func

file:a/README.rst -> file:b/README.rst
This CKAN Extension customises a CKAN instance for the hosting of data.gov.au. This CKAN Extension customises a CKAN instance for the hosting of data.gov.au.
   
It comprises: It comprises:
   
* A custom Package edit form that defaults to cc-by licence * A custom Package edit form that defaults to cc-by licence
* Replaces links with http/https protocol independent versions * Replaces links with http/https protocol independent versions
* Provides HTML to users to embed data previews on their own website * Provides HTML to users to embed data previews on their own website
* A cut down licenses.json file * A cut down licenses.json file
   
This extension is complimented by ckanext-agls for AGLS metadata and ckanext-googleanalytics for Google Analytics tracking of API usage This extension is complemented by ckanext-agls for AGLS metadata, ckanext-googleanalytics for Google Analytics tracking of API usage and ckanext-dga-stats for the customised site statistics page.
   
Installation Installation
============ ============
   
To install this package, from your CKAN virtualenv, run the following from your CKAN base folder (e.g. ``pyenv/``):: To install this package, from your CKAN virtualenv, run the following from your CKAN base folder (e.g. ``pyenv/``)::
   
pip install -e git+https://github.com/okfn/ckanext-datagovau#egg=ckanext-datagovau pip install -e git+https://github.com/okfn/ckanext-datagovau#egg=ckanext-datagovau
   
Then activate it by setting ``ckan.plugins = datagovau`` in your main ``ini``-file. Then activate it by setting ``ckan.plugins = datagovau`` in your main ``ini``-file.
   
To add the cut down licenses.json set ``licenses_group_url = http://%(ckan.site_url)/licenses.json`` To add the cut down licenses.json set ``licenses_group_url = http://%(ckan.site_url)/licenses.json``
or copy ``ckanext/datagovau/theme/public/licenses.json`` to the same folder as your CKAN config ini file or copy ``ckanext/datagovau/theme/public/licenses.json`` to the same folder as your CKAN config ini file
and set ``licenses_group_url = file://%(here)s/licenses.json`` and set ``licenses_group_url = file://%(here)s/licenses.json``
   
   
   
file:b/admin/start.sh (new)
  export NEW_RELIC_CONFIG_FILE="newrelic.ini"
  export VIRTUAL_ENV="/var/lib/ckan/dga/pyenv"
  export PATH="/var/lib/ckan/dga/pyenv:/var/lib/ckan/dga/pyenv/bin:$PATH"
  cd /var/lib/ckan/dga/pyenv/src/ckan
  newrelic-admin run-program paster serve development.ini
 
import logging import logging
   
import ckan.plugins as plugins import ckan.plugins as plugins
import ckan.lib as lib import ckan.lib as lib
import ckan.lib.dictization.model_dictize as model_dictize import ckan.lib.dictization.model_dictize as model_dictize
import ckan.plugins.toolkit as tk import ckan.plugins.toolkit as tk
import ckan.model as model import ckan.model as model
from pylons import config from pylons import config
   
from sqlalchemy import orm from sqlalchemy import orm
import ckan.model import ckan.model
   
# get user created datasets and those they have edited # get user created datasets and those they have edited
def get_user_datasets(user_dict): def get_user_datasets(user_dict):
created_datasets_list = user_dict['datasets'] created_datasets_list = user_dict['datasets']
active_datasets_list = [x['data']['package'] for x in active_datasets_list = [x['data']['package'] for x in
lib.helpers.get_action('user_activity_list',{'id':user_dict['id']}) if x['data'].get('package')] lib.helpers.get_action('user_activity_list',{'id':user_dict['id']}) if x['data'].get('package')]
raw_list = created_datasets_list + active_datasets_list raw_list = created_datasets_list + active_datasets_list
filtered_dict = {} filtered_dict = {}
for dataset in raw_list: for dataset in raw_list:
if dataset['id'] not in filtered_dict.keys(): if dataset['id'] not in filtered_dict.keys():
filtered_dict[dataset['id']] = dataset filtered_dict[dataset['id']] = dataset
return filtered_dict.values() return filtered_dict.values()
   
  def related_create(context, data_dict=None):
  return {'success': False, 'msg': 'No one is allowed to create related items'}
   
class DataGovAuPlugin(plugins.SingletonPlugin, class DataGovAuPlugin(plugins.SingletonPlugin,
tk.DefaultDatasetForm): tk.DefaultDatasetForm):
'''An example IDatasetForm CKAN plugin. '''An example IDatasetForm CKAN plugin.
   
Uses a tag vocabulary to add a custom metadata field to datasets. Uses a tag vocabulary to add a custom metadata field to datasets.
   
''' '''
plugins.implements(plugins.IConfigurer, inherit=False) plugins.implements(plugins.IConfigurer, inherit=False)
plugins.implements(plugins.ITemplateHelpers, inherit=False) plugins.implements(plugins.ITemplateHelpers, inherit=False)
  plugins.implements(plugins.IAuthFunctions)
   
  def get_auth_functions(self):
  return {'rekated_create': related_create}
   
def update_config(self, config): def update_config(self, config):
# Add this plugin's templates dir to CKAN's extra_template_paths, so # Add this plugin's templates dir to CKAN's extra_template_paths, so
# that CKAN will use this plugin's custom templates. # that CKAN will use this plugin's custom templates.
# here = os.path.dirname(__file__) # here = os.path.dirname(__file__)
# rootdir = os.path.dirname(os.path.dirname(here)) # rootdir = os.path.dirname(os.path.dirname(here))
   
tk.add_template_directory(config, 'templates') tk.add_template_directory(config, 'templates')
tk.add_public_directory(config, 'theme/public') tk.add_public_directory(config, 'theme/public')
tk.add_resource('theme/public', 'ckanext-datagovau') tk.add_resource('theme/public', 'ckanext-datagovau')
# config['licenses_group_url'] = 'http://%(ckan.site_url)/licenses.json' # config['licenses_group_url'] = 'http://%(ckan.site_url)/licenses.json'
   
def get_helpers(self): def get_helpers(self):
return {'get_user_datasets': get_user_datasets} return {'get_user_datasets': get_user_datasets}
   
   
  {% ckan_extends %}
 
  {% block header_site_navigation %}
  <nav class="section navigation">
  <ul class="nav nav-pills">
  {% block header_site_navigation_tabs %}
  {{ h.build_nav_main(
  ('search', _('Datasets')),
  ('organizations_index', _('Organizations')),
  ('about', _('About'))
  ) }}
  <li><a href="//data.gov.au/stats">Site Statistics</a></li>
  <li><a href="https://datagovau.ideascale.com/">Feedback/Request Data</a></li>
  {% endblock %}
  </ul>
  </nav>
  {% endblock %}
 
  {% ckan_extends %}
  {% block home_secondary_content %}
  <script type="text/javascript" src="//www.google.com/jsapi">
  </script>
  <script type="text/javascript">
  google.load("feeds", "1") //Load Google Ajax Feed API (version 1)
  </script>
 
  <div id="feeddiv"></div>
 
  <script type="text/javascript">
 
  var feedcontainer=document.getElementById("feeddiv")
  var feedurl="http://www.finance.gov.au/taxonomy/term/1274/feed"
  var feedlimit=3
  var rssoutput="<div class='module module-shallow module-narrow module-dark info box' style='color:black'><h2>Latest data.gov.au News</h2><i class='ckan-icon ckan-icon-feed'></i><a href='http://www.finance.gov.au/taxonomy/term/1274/feed/'>&nbsp;Subscribe to the blog </a></div>"
 
 
  function rssfeedsetup(){
  var feedpointer=new google.feeds.Feed(feedurl) //Google Feed API method
  feedpointer.setNumEntries(feedlimit) //Google Feed API method
  feedpointer.load(displayfeed) //Google Feed API method
  }
 
  function displayfeed(result){
  if (!result.error){
  var thefeeds=result.feed.entries
  for (var i=0; i<thefeeds.length; i++) {
  rssoutput+="<div class='module module-shallow module-narrow module-dark info box'><h3><a href='" + thefeeds[i].link + "'>" + thefeeds[i].title + "</a></h3>"
  rssoutput+= " <font color='black'>Posted on " + new Date(thefeeds[i].publishedDate).toDateString() + "</font></div>"
  }
  rssoutput+=""
  feedcontainer.innerHTML=rssoutput
  }
  else
  alert("Error fetching feeds!")
  }
 
  window.onload=function(){
  rssfeedsetup()
  }
 
  </script>
 
  {{ super() }}
  {% endblock %}
 
  {% set intro = g.site_intro_text %}
 
  <div class="module-content box">
  <header>
  {% if intro %}
  {{ h.render_markdown(intro) }}
  {% else %}
  <h1 class="page-heading">{{ _("Welcome to CKAN") }}</h1>
  <p>
  {% trans %}This is a nice introductory paragraph about CKAN or the site
  in general. We don't have any copy to go here yet but soon we will
  {% endtrans %}
  </p>
  {% endif %}
  </header>
  </div>
 
 
  {% set stats = h.get_site_statistics() %}
 
  <div class="box stats">
  <div class="inner">
  <h3>{{ _('{0} statistics').format(g.site_title) }}</h3>
  <ul>
  <li>
  <a href="{{ h.url_for(controller='package', action='search') }}">
  <b>{{ h.SI_number_span(stats.dataset_count) }}</b>
  {{ _('dataset') if stats.dataset_count == 1 else _('datasets') }}
  </a>
  </li>
  <li>
  <a href="{{ h.url_for(controller='organization', action='index') }}">
  <b>{{ h.SI_number_span(stats.organization_count) }}</b>
  {{ _('organisation') if stats.organization_count == 1 else _('organisations') }}
  </a>
  </li>
  <li>
  <a href="{{ h.url_for(controller='group', action='index') }}">
  <b>{{ h.SI_number_span(stats.group_count) }}</b>
  {{ _('group') if stats.group_count == 1 else _('groups') }}
  </a>
  </li>
  <!--<li>
  <a href="{{ h.url_for(controller='related', action='dashboard') }}">
  <b>{{ h.SI_number_span(stats.related_count) }}</b>
  {{ _('related item') if stats.related_count == 1 else _('related items') }}
  </a>
  </li>-->
  </ul>
  </div>
  </div>
 
  <div id="feeddiv">
  </div>
 
  <script type="text/javascript" src="//www.google.com/jsapi">
  </script>
  <script type="text/javascript">
  google.load("feeds", "1") //Load Google Ajax Feed API (version 1)
  </script>
 
  <script type="text/javascript">
 
  var feedcontainer=document.getElementById("feeddiv")
  var feedurl="http://www.finance.gov.au/taxonomy/term/1274/feed"
  var feedlimit=4
  var rssoutput="<div class='module module-shallow module-narrow module-dark info box' style='color:black'><h2>Latest data.gov.au News</h2><i class='ckan-icon ckan-icon-feed'></i><a href='http://www.finance.gov.au/taxonomy/term/1274/feed/'>&nbsp;Subscribe to the blog </a></div>"
 
 
  function rssfeedsetup(){
  var feedpointer=new google.feeds.Feed(feedurl) //Google Feed API method
  feedpointer.setNumEntries(feedlimit) //Google Feed API method
  feedpointer.load(displayfeed) //Google Feed API method
  }
 
  function displayfeed(result){
  if (!result.error){
  var thefeeds=result.feed.entries
  for (var i=0; i<thefeeds.length; i++) {
  rssoutput+="<div class='module module-shallow module-narrow module-dark info box'><h3><a href='" + thefeeds[i].link + "'>" + thefeeds[i].title + "</a></h3>"
  rssoutput+= " <font color='black'>Posted on " + new Date(thefeeds[i].publishedDate).toDateString() + "</font></div>"
  }
  rssoutput+=""
  feedcontainer.innerHTML=rssoutput
  }
  else
  alert("Error fetching feeds!")
  }
 
  window.onload=function(){
  rssfeedsetup()
  }
 
  </script>