Skip to content

Commit

Permalink
Merge pull request #39 from OriHoch/dylanjw-feature/get_homepage_snippet
Browse files Browse the repository at this point in the history
Dylanjw feature/get homepage snippet
  • Loading branch information
OriHoch authored Nov 24, 2017
2 parents 37b87db + e6d948b commit e59faa8
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 136 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ If you have an existing ckan installation and just want to install the odata plu
* From activated Python 2.7 virtualenv:
* `bin/install.sh`
* ```paster serve `pwd`/ckan/development-local.ini```

## Restoring from backup

Given that you have `ckan-dump/data.tar.gz` and `ckan-dump/db.gz` from k8s backup job:

```
gunzip -c ckan-dump/db.gz > ckan-dump/db.sql
paster --plugin=ckan db clean -c `pwd`/ckan/development-local.ini
paster --plugin=ckan db load ckan-dump/db.sql -c `pwd`/ckan/development-local.ini
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,27 @@
font-weight: bold;
font-size: 110%;
}

.odatasets ul.dataset-list {
padding-right: 25px;
padding-left: 25px;
padding-bottom: 25px;
}

.odatasets h2 {
font-size:250%;
direction:rtl;
text-align:right;
padding-right: 15px;

}

.odatasets p.alldatasets {
text-align: left;
padding-left: 25px;
padding-top: 20px;
}

.odatasets p.alldatasets a {
font-size: 150%;
}
14 changes: 9 additions & 5 deletions ckan/ckanext-odata_org_il/ckanext/odata_org_il/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import ckan.plugins.toolkit as toolkit
from ckan.lib.plugins import DefaultTranslation


class Odata_Org_IlPlugin(plugins.SingletonPlugin, DefaultTranslation):
plugins.implements(plugins.ITranslation)
plugins.implements(plugins.IConfigurer)
Expand All @@ -18,11 +17,16 @@ def update_config(self, config_):
def i18n_domain(self):
return 'ckan'

def get_homepage_snippet(self, *args, **kwargs):
# TODO: show last updated datasets
return ""
def get_homepage_datasets(self, *args, **kwargs):
psearch = toolkit.get_action("package_search")
psearch_ret = psearch(data_dict={"sort":"timestamp desc","rows":5})
results = psearch_ret['results']
return results
# result_str_list = [ "Name: %(name)s<br>Notes: %(notes)s<br>Created:%(metadata_created)s<br>Modified:%(metadata_modified)s<br>URL:%(url)s" % entry for entry in results ]
# return "<br>".join(result_str_list)

# Tell CKAN what custom template helper functions this plugin provides,
# see the ITemplateHelpers plugin interface.
def get_helpers(self):
return {'get_homepage_snippet': self.get_homepage_snippet}
return {'homepage_datasets': self.get_homepage_datasets}

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
{% block search %}
{% snippet 'home/snippets/search.html' %}
{% endblock %}
{% snippet 'home/snippets/stats.html' %}
</div>
<div class="container">
{% block tags %}
{% snippet 'package/snippets/tags.html' %}
{% endblock %}
</div>

</div>
<div role="main">
<div role="main" class="odatasets">
<div class="container">
{{ h.get_homepage_snippet() }}
<div class="box">
<h2 dir="rtl">עדכונים אחרונים</h2>
{% snippet 'snippets/package_list.html', packages=h.homepage_datasets() %}
<p class="alldatasets">
<a href="/dataset">לכל המסמכים</a>
</p>
</div>


</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{% set stats = h.get_site_statistics() %}

<div class="box stats">
<div class="box stats" style="margin-top: 25px">
<div class="inner">
<h3>{{ _('{0} statistics').format(g.site_title) }}</h3>
<ul>
{% block stats_group %}
<li>
Expand Down
38 changes: 19 additions & 19 deletions k8s/jobs/ckan-create-db.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
apiVersion: batch/v1
kind: Job
metadata:
name: ckan-create-db
spec:
template:
metadata:
name: ckan-create-db
spec:
containers:
- name: ckan-create-db
image: postgres:9.6.3-alpine
env:
- {name: PGPASSWORD, valueFrom: {secretKeyRef: {name: "env-vars", key: "POSTGRES_PASSWORD"}}}
command: ["su-exec", "postgres", "bash", "-c", "psql -h db -U postgres -c 'CREATE DATABASE ckan;'"]
resources:
requests:
cpu: 1m
restartPolicy: Never
#apiVersion: batch/v1
#kind: Job
#metadata:
# name: ckan-create-db
#spec:
# template:
# metadata:
# name: ckan-create-db
# spec:
# containers:
# - name: ckan-create-db
# image: postgres:9.6.3-alpine
# env:
# - {name: PGPASSWORD, valueFrom: {secretKeyRef: {name: "env-vars", key: "POSTGRES_PASSWORD"}}}
# command: ["su-exec", "postgres", "bash", "-c", "psql -h db -U postgres -c 'CREATE DATABASE ckan;'"]
# resources:
# requests:
# cpu: 1m
# restartPolicy: Never
50 changes: 25 additions & 25 deletions k8s/jobs/ckan-initialize-db.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
apiVersion: batch/v1
kind: Job
metadata:
name: ckan-initialize-db
spec:
template:
metadata:
name: ckan-initialize-db
spec:
containers:
- name: ckan-initialize-db
image: orihoch/data4dappl-ckan
args: ["db", "init", "-c", "/etc/ckan/default/development.ini"]
resources:
requests:
cpu: 1m
volumeMounts:
- name: etc-ckan-default
mountPath: /etc/ckan/default
readOnly: true
volumes:
- name: etc-ckan-default
secret:
secretName: etc-ckan-default
restartPolicy: Never
#apiVersion: batch/v1
#kind: Job
#metadata:
# name: ckan-initialize-db
#spec:
# template:
# metadata:
# name: ckan-initialize-db
# spec:
# containers:
# - name: ckan-initialize-db
# image: orihoch/data4dappl-ckan
# args: ["db", "init", "-c", "/etc/ckan/default/development.ini"]
# resources:
# requests:
# cpu: 1m
# volumeMounts:
# - name: etc-ckan-default
# mountPath: /etc/ckan/default
# readOnly: true
# volumes:
# - name: etc-ckan-default
# secret:
# secretName: etc-ckan-default
# restartPolicy: Never
86 changes: 43 additions & 43 deletions k8s/jobs/ckan-restore-data.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
apiVersion: batch/v1
kind: Job
metadata:
name: ckan-restore-data
spec:
template:
metadata:
name: ckan-restore-data
spec:
nodeSelector:
# loads data dump from hostPath
# TODO: change to use network shared filesystem
kubernetes.io/hostname: gke-data4dappl-default-pool-29af7936-z7tf
containers:
- name: ckan-restore-data
# this image was updated with psql which is needed to restore db
image: gcr.io/hasadna-odata/data4dappl-ckan:34085ec7df43172d33c7fb53858374af76886be1
command:
- "bash"
- "-c"
- >
tar -xzvf /var/ckan-dump/data.tar.gz -C /var/lib/ckan
resources:
requests:
cpu: 5m
volumeMounts:
- name: etc-ckan-default
mountPath: /etc/ckan/default
readOnly: true
- name: ckan-dump
mountPath: /var/ckan-dump
- name: ckan-data
mountPath: /var/lib/ckan
volumes:
- name: etc-ckan-default
secret:
secretName: etc-ckan-default
- name: ckan-dump
hostPath: {path: /var/ckan-dump}
- name: ckan-data
persistentVolumeClaim:
claimName: ckan-data
restartPolicy: Never
#apiVersion: batch/v1
#kind: Job
#metadata:
# name: ckan-restore-data
#spec:
# template:
# metadata:
# name: ckan-restore-data
# spec:
# nodeSelector:
# # loads data dump from hostPath
# # TODO: change to use network shared filesystem
# kubernetes.io/hostname: gke-data4dappl-default-pool-29af7936-z7tf
# containers:
# - name: ckan-restore-data
# # this image was updated with psql which is needed to restore db
# image: gcr.io/hasadna-odata/data4dappl-ckan:34085ec7df43172d33c7fb53858374af76886be1
# command:
# - "bash"
# - "-c"
# - >
# tar -xzvf /var/ckan-dump/data.tar.gz -C /var/lib/ckan
# resources:
# requests:
# cpu: 5m
# volumeMounts:
# - name: etc-ckan-default
# mountPath: /etc/ckan/default
# readOnly: true
# - name: ckan-dump
# mountPath: /var/ckan-dump
# - name: ckan-data
# mountPath: /var/lib/ckan
# volumes:
# - name: etc-ckan-default
# secret:
# secretName: etc-ckan-default
# - name: ckan-dump
# hostPath: {path: /var/ckan-dump}
# - name: ckan-data
# persistentVolumeClaim:
# claimName: ckan-data
# restartPolicy: Never
80 changes: 40 additions & 40 deletions k8s/jobs/ckan-restore-db.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
apiVersion: batch/v1
kind: Job
metadata:
name: ckan-restore-db
spec:
template:
metadata:
name: ckan-restore-db
spec:
nodeSelector:
# loads data dump from hostPath
# TODO: change to use network shared filesystem
kubernetes.io/hostname: gke-data4dappl-default-pool-29af7936-z7tf
containers:
- name: ckan-restore-db
# this image was updated with psql which is needed to restore db
image: gcr.io/hasadna-odata/data4dappl-ckan:34085ec7df43172d33c7fb53858374af76886be1
command:
- "bash"
- "-c"
- >
gunzip -c /var/ckan-dump/db.gz > /db &&
../../bin/paster --plugin=ckan db clean -c /etc/ckan/default/development.ini &&
../../bin/paster --plugin=ckan db load /db -c /etc/ckan/default/development.ini
resources:
requests:
cpu: 5m
volumeMounts:
- name: etc-ckan-default
mountPath: /etc/ckan/default
readOnly: true
- name: ckan-dump
mountPath: /var/ckan-dump
volumes:
- name: etc-ckan-default
secret:
secretName: etc-ckan-default
- name: ckan-dump
hostPath: {path: /var/ckan-dump}
restartPolicy: Never
#apiVersion: batch/v1
#kind: Job
#metadata:
# name: ckan-restore-db
#spec:
# template:
# metadata:
# name: ckan-restore-db
# spec:
# nodeSelector:
# # loads data dump from hostPath
# # TODO: change to use network shared filesystem
# kubernetes.io/hostname: gke-data4dappl-default-pool-29af7936-z7tf
# containers:
# - name: ckan-restore-db
# # this image was updated with psql which is needed to restore db
# image: gcr.io/hasadna-odata/data4dappl-ckan:34085ec7df43172d33c7fb53858374af76886be1
# command:
# - "bash"
# - "-c"
# - >
# gunzip -c /var/ckan-dump/db.gz > /db &&
# ../../bin/paster --plugin=ckan db clean -c /etc/ckan/default/development.ini &&
# ../../bin/paster --plugin=ckan db load /db -c /etc/ckan/default/development.ini
# resources:
# requests:
# cpu: 5m
# volumeMounts:
# - name: etc-ckan-default
# mountPath: /etc/ckan/default
# readOnly: true
# - name: ckan-dump
# mountPath: /var/ckan-dump
# volumes:
# - name: etc-ckan-default
# secret:
# secretName: etc-ckan-default
# - name: ckan-dump
# hostPath: {path: /var/ckan-dump}
# restartPolicy: Never

0 comments on commit e59faa8

Please sign in to comment.