Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EP #63

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
*.scssc
54 changes: 32 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,67 @@
# data.codefordc.org
The beginnings of an open source project for data.codefordc.org, which is the beginnings of a replacement for opendatadc.org.

This repository is an open-source project for [data.codefordc.org](http://data.codefordc.org/), a [CKAN](https://ckan.org/) data portal run by [Code for DC](https://codefordc.org/).

This repository includes the CKAN theme used by data.codefordc.org as well any custom pages used by the site.

## Local development Setup Instructions
## Setup instructions

### Prerequisites

- Git
- [Docker](https://docs.docker.com/engine/installation/) for your OS.
- [Docker](https://docs.docker.com/engine/installation/) for your operating system

### Cloning the repository

First, you'll need to fork this repository and clone it onto your computer. To fork it, click "Fork" in the upper-right corner of this page. You can then clone your fork using one of these two methods:
- in the terminal, navigate to whatever directory you want the repository to be cloned into and run `git clone https://github.com/<username>/opendatadc` (replace `<username>` with your GitHub username)
- inside of [GitHub Desktop](https://desktop.github.com/), go to _File > Clone Repository_ and then choose where to clone the repo to

This is the only time you will need to do this step. In future development sessions, you can just run the steps in the "Getting started" section.

### Getting started
1. Run `git clone https://github.com/codefordc/opendatadc`
2. Navigate to `opendatadc` (where the source was just cloned into)
3. Run `docker-compose up -d`

Thats it! CKAN and all its services are now running.
In the terminal, navigate to `opendatadc` (or whatever directory you cloned the repository into) and run `docker-compose up -d`. Thats it! CKAN and all its services should now be running.

To view a local demo version of the site, open your favorite web browser and go to `http://localhost:5000/`. You should see a demo version of the Open Data DC site!

To view a local demo version of the site, open your favorite web browser and go to `http://localhost:5000/`.
If the page doesn't load after a minute or so, try running `docker-compose restart ckan`. (You may be having an issue that sometimes happens where CKAN starts before the postgres and solr services have finished starting up.)

Alternatively, particularly if you are on Windows, try navigating to `192.168.99.100:5000`. (On Windows and OSX, docker-machine creates a virtual machine and will assign it a local IP address on your machine. In most cases it will be `192.168.99.100`, but you can verify this by running `docker-machine ip` in the terminal. On Linux, the docker daemon is running natively, so all the docker processes will be exposed on `127.0.0.1`.)

### Test data
Test data and admin users can be added very easily.

1. From the directory where the source was cloned to run `docker-compose exec ckan bash`
2. Run `paster sysadmin add admin -c /etc/ckan/default/development.ini`
3. Run `paster create-test-data -c /etc/ckan/default/development.ini`
Test data and admin users can be added very easily.

### Troubleshooting
- Known issue: CKAN starts before the postgres and solr services have finished starting up
- Solution: Run `docker-compose restart ckan`
From the directory where the source was cloned, run `docker-compose exec ckan bash`. You should now see a promt within the terminal that begins with `/usr/lib/ckan/default/src/ckan#`.

To create a test user, run `paster sysadmin add admin -c /etc/ckan/default/development.ini`.

### Appendix A - Setting up the docker IPs
On Windows and OSX, docker-machine creates a virtual machine and will assign it a local IP address on your machine.
In most cases it will be `192.168.99.100`.
To create test data, run `paster create-test-data -c /etc/ckan/default/development.ini`.

On Linux, the docker daemon is running natively, so all the docker processes will be exposed on `127.0.0.1`.
To exit this prompt, run `exit`.

## Local development
Changes to the source HTML, JS, and CSS(SCSS) files will automatically show up when the browser is reloaded. Python changes will require the CKAN container to be restarted. To do so run `docker-compose restart ckan`

Changes to the source HTML, JavaScript, and CSS/SCSS files will automatically show up when the browser is reloaded.

Changes to Python files will require the CKAN container to be restarted. To do so run `docker-compose restart ckan`.

### Styles

SASS is used to create and maintain styles for the theme in order to compile the styles run
```
sass ckanext/open_data_dc/fanstatic/open_data_dc.scss ckanext/open_data_dc/fanstatic/open_data_dc.css
```

### Changing templates, files, javascript
Is a very large subject and the best way to get started is to read the [CKAN documents](http://docs.ckan.org/en/latest/theming/templates.html)
### Changing templates, files, JavaScript

Is a very large subject and the best way to get started is to read the [CKAN documents](http://docs.ckan.org/en/latest/theming/templates.html)

Feel free to contribute here or join us on [Waffle.io](https://waffle.io/codefordc/data.codefordc.org)

## Deploying a new version

1. Login to the remote production machine through ssh
2. Activate the default virtualenv environment (should say (default) in terminal)
3. Navigate to `/usr/lib/ckan/default/src/ckanext-open-data-dc`
Expand Down
29 changes: 28 additions & 1 deletion ckanext/open_data_dc/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit

# def get_with_tag(tag):
#
# packages = toolkit.get_action('package_search')(
# data_dict={'fq': ('tags:'+tag)})
#
# return packages

def get_with_tag(tag):

packages = toolkit.get_action('package_search')(
data_dict={'fq': 'tags:'+tag})

return packages

def most_popular_groups():
'''Return a sorted list of the groups with the most datasets.'''
Expand All @@ -12,6 +25,16 @@ def most_popular_groups():

return groups

def least_popular_groups():
'''Return a sorted list of the groups with the fewest datasets.'''

# Get a list of all the site's groups from CKAN, sorted by number of
# datasets.
groups = toolkit.get_action('group_list')(
data_dict={'sort': 'package_count asc', 'all_fields': True})

return groups

class Open_Data_DcPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IConfigurer)

Expand All @@ -31,4 +54,8 @@ def get_helpers(self):
# Template helper function names should begin with the name of the
# extension they belong to, to avoid clashing with functions from
# other extensions.
return {'open_data_dc_most_popular_groups': most_popular_groups}
return {
'open_data_dc_most_popular_groups': most_popular_groups,
'open_data_dc_least_popular_groups': least_popular_groups,
'open_data_dc_get_with_tag': get_with_tag
}
1 change: 1 addition & 0 deletions ckanext/open_data_dc/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ <h1>
('about', _('About'))
) }}
{% endblock %}
<li><a href="/datarequests">Data Requests</a></li>
</ul>
</nav>
{% endblock %}
Expand Down
11 changes: 10 additions & 1 deletion ckanext/open_data_dc/templates/home/layout1.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@
</div>
</div>
</div>
</div>
</div>
<div role="main">
<div class="container">
<div class="row row3">
<div class="span12 col1">
{% snippet 'home/snippets/test.html' %}
</div>
</div>
</div>
</div>
19 changes: 19 additions & 0 deletions ckanext/open_data_dc/templates/home/snippets/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<section class="module-content categories-list">
<div>
{% for group in h.open_data_dc_get_with_tag('promoted').results %}
<a href="{{ h.url_for('dataset_read', action='read', id=group.name) }}">
<div class="category">
<!-- <img src="{{ group.image_display_url or h.url_for_static('/base/images/placeholder-group.png') }}" alt="{{ group.name }}" /> -->
<h3>{{ group.title }} (this is a link!)</h3>
</div>
</a>
<!-- <h3>{{ group }}</h3> -->
<!-- <a href="{{ h.url_for('group_read', action='read', id=group.name) }}">
<div class="category">
<img src="{{ group.image_display_url or h.url_for_static('/base/images/placeholder-group.png') }}" alt="{{ group.name }}" />
<h3>{{ group.display_name}}</h3>
</div>
</a> -->
{% endfor %}
</div>
<section>
13 changes: 13 additions & 0 deletions ckanext/open_data_dc/templates/snippets/least_popular_groups.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{# Renders a list of the site's least popular groups. #}
<section class="module-content categories-list">
<div>
{% for group in h.open_data_dc_least_popular_groups() %}
<a href="{{ h.url_for('group_read', action='read', id=group.name) }}">
<div class="category">
<img src="{{ group.image_display_url or h.url_for_static('/base/images/placeholder-group.png') }}" alt="{{ group.name }}" />
<h3>{{ group.display_name}}</h3>
</div>
</a>
{% endfor %}
</div>
<section>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<a href="{{ h.url_for('group_read', action='read', id=group.name) }}">
<div class="category">
<img src="{{ group.image_display_url or h.url_for_static('/base/images/placeholder-group.png') }}" alt="{{ group.name }}" />
<h3>{{ group.display_name}}</h3>
</div>
</a>
<h3>{{ group.display_name}}</h3>
</div>
</a>
{% endfor %}
</div>
<section>