Skip to content

Commit

Permalink
[#60] Adds stats and latest datasets to the homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmartin committed Apr 24, 2013
1 parent a264bee commit 6bec998
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 0 deletions.
67 changes: 67 additions & 0 deletions ckanext/geodatagov/fanstatic_library/styles/geodatagov.css
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ a {
background: url("../images/banner.jpg");
height: 301px;
overflow: hidden;
-webkit-border-radius: 0 0 3px 3px;
-moz-border-radius: 0 0 3px 3px;
-o-border-radius: 0 0 3px 3px;
border-radius: 0 0 3px 3px;
}
.homepage .intro {
color: #FFF;
Expand Down Expand Up @@ -457,6 +461,69 @@ a {
#hp-message .alert {
margin: 0;
}
#hp-stats {
*zoom: 1;
margin: 10px 0;
}
#hp-stats:before,
#hp-stats:after {
display: table;
content: "";
line-height: 0;
}
#hp-stats:after {
clear: both;
}
#hp-stats .split {
float: left;
width: 449px;
margin: 0 10px;
}
#hp-stats .module-heading {
-webkit-border-radius: 3px 3px 0 0;
-moz-border-radius: 3px 3px 0 0;
-o-border-radius: 3px 3px 0 0;
border-radius: 3px 3px 0 0;
}
#hp-stats .module-heading a {
font-weight: 300;
}
#hp-stats .dataset-item {
border-top: 1px solid #DDD;
}
#hp-stats .dataset-item .dataset-content {
padding-bottom: 0;
}
#hp-stats .dataset-item:first-child {
border-top-width: 0;
}
#hp-stats .module {
margin: 0;
}
#hp-stats .module table {
margin-bottom: 0;
}
#hp-stats .module table tr:first-child th,
#hp-stats .module table tr:first-child td {
border-top-width: 0;
}
#hp-stats .module table th,
#hp-stats .module table td {
padding: 7px 15px;
}
#hp-stats .module table th {
font-weight: 300;
color: #666;
}
#hp-stats .module table td {
font-weight: bold;
}
#hp-stats .module table td.more {
text-align: right;
}
#hp-stats .module table td.more a {
font-weight: 300;
}
.format-label[data-format="ISO-19139"],
.format-label[data-format*="ISO-19139"] {
background-position: 0 0;
Expand Down
53 changes: 53 additions & 0 deletions ckanext/geodatagov/fanstatic_library/styles/homepage.less
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
background: url("@{geoLocalThemeURL}images/banner.jpg");
height: 301px;
overflow: hidden;
.border-radius(0 0 3px 3px);
}
.intro {
color: #FFF;
Expand Down Expand Up @@ -45,3 +46,55 @@
margin: 0;
}
}

#hp-stats {
.clearfix;
margin: 10px 0;
.split {
float: left;
width: 449px;
margin: 0 10px;
}
.module-heading {
.border-radius(3px 3px 0 0);
a {
font-weight: 300;
}
}
.dataset-item {
border-top: 1px solid #DDD;
.dataset-content {
padding-bottom: 0;
}
&:first-child {
border-top-width: 0;
}
}
.module {
margin: 0;
table {
margin-bottom: 0;
tr:first-child {
th, td {
border-top-width: 0;
}
}
th, td {
padding: 7px 15px;
}
th {
font-weight: 300;
color: #666;
}
td {
font-weight: bold;
&.more {
text-align: right;
a {
font-weight: 300;
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions ckanext/geodatagov/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,17 @@ def is_web_format(resource):
if (format in WEB_FORMATS):
return True
return False

def get_homepage_stats():
'''Return a few key stats'''
return (
('Datasets', 50000, '#'),
('Collection Datasets', 10000, ''),
('Applications', 100, ''),
)

def get_latest_datasets(limit=4):
'''Return a list of the latest datasets on the site.'''
response = p.toolkit.get_action('package_search')(
data_dict={'sort': 'metadata_modified desc', 'rows': limit})
return response['results']
2 changes: 2 additions & 0 deletions ckanext/geodatagov/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ def get_helpers(self):
'get_collection_package': geodatagov_helpers.get_collection_package,
'resource_preview_custom': geodatagov_helpers.resource_preview_custom,
'is_web_format': geodatagov_helpers.is_web_format,
'get_homepage_stats': geodatagov_helpers.get_homepage_stats,
'get_latest_datasets': geodatagov_helpers.get_latest_datasets,
}

## IActions
Expand Down
38 changes: 38 additions & 0 deletions ckanext/geodatagov/templates/home/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,44 @@ <h1>{{ _('Welcome to Geospatial Data')}}</h1>
<p>Data.gov is currently transitioning the geospatial catalog from <a href="http://geo.data.gov">Geo.data.gov</a> to this site. You will see additional functionality and data sources coming to this site through June 2013, while the two sites operate in parallel. If you have comments or suggestions on this site, please <a href="http://www.data.gov/contact-us">contact us</a>.</p>
</div>
</div>
<div id="hp-stats">
{% set stats = h.get_homepage_stats() %}
<div class="split">
<div class="box module module-narrow module-shallow">
<h3 class="module-heading">
<i class="icon-bar-chart"></i>
{{ _('Quick stats') }}
</h3>
<table class="table table-hover">
<col width="20">
<col width="80">
<col width="20">
{% for stat, value, url in stats %}
<tr>
<td>{{ value }}</td>
<th scope="row">{{ _(stat) }}</th>
<td class="more">
{% if url %}
<a href="{{ url }}">more</a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% set datasets = h.get_latest_datasets() %}
<div class="split">
<div class="box module module-narrow module-shallow">
<h3 class="module-heading">
<a href="{{ h.url_for(controller='package', action='search') }}" class="pull-right">{{ _('more') }}</a>
<i class="icon-sitemap"></i>
{{ _('Latest datasets') }}
</h3>
{% snippet 'snippets/package_list.html', packages=datasets, list_class="unstyled dataset-list", item_class="dataset-item module-content", truncate=120 %}
</div>
</div>
</div>
</div>
</div>
{% endblock %}

0 comments on commit 6bec998

Please sign in to comment.