beginnings of autoupdate script
--- /dev/null
+++ b/admin/autoupdate.py
@@ -1,1 +1,53 @@
+import requests
+import ckanapi
+# copy (select id,url,format,extras from resource where extras like '%"autoupdate": "active"%') TO STDOUT WITH CSV;
+# f759e4b6-723c-4863-8a26-1529d689cad8,http://data.gov.au/geoserver/geelong-roofprints-kml/wms?request=GetCapabilities,wms,"{""autoupdate"": ""active""}"
+import fileinput
+import csv
+def updateresource(resource_id):
+ url = 'http://data.disclosurelo.gs'
+ api_key = ''
+ db_credentials = ''
+ print resource_id
+ ckan = ckanapi.RemoteCKAN('http://data.disclosurelo.gs')
+ #ckan = ckanapi.RemoteCKAN('http://demo.ckan.org')
+ resource = ckan.action.resource_show(id=resource_id)
+ print resource
+ url = resource['url']
+ #last_modified= 'Mon, 24 Feb 2014 01:48:29 GMT'
+ #etag='"1393206509.38-638"'
+ headers={}
+ if 'etag' in resource:
+ headers['If-None-Match'] = resource['etag']
+ if 'file_last_modified' in resource:
+ headers["If-Modified-Since"] = resource['file_last_modified']
+ r = requests.head(url, headers=headers)
+ if r.status_code == 304:
+ print 'not modified'
+ return
+ else:
+ print r.status_code
+ print r.headers
+ if 'last-modified' in r.headers:
+ resource['file_last_modified'] = r.headers['last-modified']
+ if 'etag' in r.headers:
+ resource['etag'] = r.headers['etag']
+ #save updated resource
+# result = ckan.action.resource_update(id,resource)
+ if 'format' == 'shp':
+ print "geoingest!" db_settings_json, api_url, api_key, resource['dataset_id']
+ else:
+ ckan.action.datapusher_submit(resource_id=id)
+
+if len(sys.argv) != 5:
+ print "spatial ingester. command line: postgis_url api_url api_key"
+ sys.exit(errno.EACCES)
+else:
+ (path, db_settings_json, api_url, api_key) = sys.argv
+ db_settings = json.loads(db_settings_json)
+
+for line in fileinput.input():
+ row = csv.reader(line)
+ updateresource(line.replace("\n",""))
+
--- /dev/null
+++ b/admin/start.sh
@@ -1,1 +1,6 @@
+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
--- a/ckanext/datagovau/plugin.py
+++ b/ckanext/datagovau/plugin.py
@@ -22,6 +22,9 @@
filtered_dict[dataset['id']] = dataset
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,
tk.DefaultDatasetForm):
'''An example IDatasetForm CKAN plugin.
@@ -31,6 +34,10 @@
'''
plugins.implements(plugins.IConfigurer, 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):
# Add this plugin's templates dir to CKAN's extra_template_paths, so
--- a/ckanext/datagovau/templates/home/index.html
+++ b/ckanext/datagovau/templates/home/index.html
@@ -1,24 +1,18 @@
{% ckan_extends %}
- {% block home_search %}
-
-<div class="hero-secondary-inner">
-<script type="text/javascript" src="http://www.google.com/jsapi">
+{% 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>
-</div>
-
-
+ <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=4
+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/'> Subscribe to the blog </a></div>"
@@ -48,15 +42,6 @@
</script>
- <form class="module-content search-form" method="get" action="{% url_for controller='package', action='search' %}">
- <h3 class="heading">{{ _("Search Your Data") }}</h3>
- <div class="search-input control-group search-giant">
- <input type="text" class="search" name="q" value="{{ c.q }}" autocomplete="off" placeholder="{{ _('eg. Gold Prices') }}" />
- <button type="submit">
- <i class="icon-search"></i>
- <span>{{ _('Search') }}</span>
- </button>
- </div>
- </form>
+{{ super() }}
{% endblock %}
--- /dev/null
+++ b/ckanext/datagovau/templates/home/snippets/promoted.html
@@ -1,1 +1,17 @@
+{% 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>
+
--- a/ckanext/datagovau/templates/home/snippets/search.html
+++ /dev/null
@@ -1,70 +1,1 @@
-<div class="hero-secondary-inner">
-<script type="text/javascript" src="http://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>
-</div>
-
-
-
-<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/'> 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>
-
-{% set tags = h.get_facet_items_dict('tags', limit=3) %}
-{% set placeholder = _('eg. Gold Prices') %}
-
-<div class="module module-search module-narrow module-shallow box">
- <form class="module-content search-form" method="get" action="{% url_for controller='package', action='search' %}">
- <h3 class="heading">{{ _("Search Your Data") }}</h3>
- <div class="search-input control-group search-giant">
- <input type="text" class="search" name="q" value="" autocomplete="off" placeholder="{{ placeholder }}" />
- <button type="submit">
- <i class="icon-search"></i>
- <span>{{ _('Search') }}</span>
- </button>
- </div>
- </form>
- <div class="tags">
- <h3>{{ _('Popular Tags') }}</h3>
- {% for tag in tags %}
- <a class="tag" href="{% url_for controller='package', action='search', tags=tag.name %}">{{ h.truncate(tag.display_name, 22) }}</a>
- {% endfor %}
- </div>
-</div>
-
--- /dev/null
+++ b/ckanext/datagovau/templates/home/snippets/stats.html
@@ -1,1 +1,78 @@
+{% 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/'> 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>
+
--- /dev/null
+++ b/ckanext/datagovau/templates/package/snippets/resource_form.html
@@ -1,1 +1,43 @@
+{% ckan_extends %}
+ {% block basic_fields_url %}
+ {% set is_upload = (data.url_type == 'upload') %}
+ {% set field_url='url' %}
+ {% set field_upload='upload' %}
+ {% set field_clear='clear_upload' %}
+ {% set is_upload_enabled=h.uploads_enabled() %}
+ {% set is_url=data.url and not is_upload %}
+ {% set upload_label=_('File') %}
+ {% set url_label=_('URL') %}
+
+ {% set placeholder = placeholder if placeholder else _('http://example.com/my-image.jpg') %}
+ {% set url_label = url_label or _('Image URL') %}
+ {% set upload_label = upload_label or _('Image') %}
+
+ {% if is_upload_enabled %}
+ <div class="image-upload" data-module="image-upload" data-module-is_url="{{ 'true' if is_url else 'false' }}" data-module-is_upload="{{ 'true' if is_upload else 'false' }}"
+ data-module-field_url="{{ field_url }}" data-module-field_upload="{{ field_upload }}" data-module-field_clear="{{ field_clear }}" data-module-upload_label="{{ upload_label }}">
+ {% endif %}
+
+ {% call form.input(field_url, label=url_label, id='field-image-url', placeholder=placeholder, value=data.get(field_url), error=errors.get(field_url), classes=['control-full']) %}
+<span id="autoupdate_form">
+ {% call form.select('autoupdate', label=_('Generate API from this Link'), options= [{'value': 'active', 'text': 'Active'}, {'value': 'inactive', 'text': 'Inactive'}], selected='Active', error=errors.autoupdate) %}
+<br/>
+Where a file is compatible with either CKAN or GeoServer we will attempt to make a functional end-point for this resource. The link provided above will also be checked for a new version based on the update frequency as set at the dataset level.
+</span>
+{% endcall %}
+{% endcall %}
+
+ {% if is_upload_enabled %}
+ {{ form.input(field_upload, label=upload_label, id='field-image-upload', type='file', placeholder='', value='', error='', classes=['control-full']) }}
+ {% if is_upload %}
+ {{form.checkbox(field_clear, label=_('Clear Upload'), id='field-clear-upload', value='true', error='', classes=['control-full']) }}
+ {% endif %}
+ {% endif %}
+
+ {% if is_upload_enabled %}</div>{% endif %}
+
+
+ {% endblock %}
+
+