Skip to content

Commit

Permalink
Merge pull request #1126 from okfn/1126-homepage-module
Browse files Browse the repository at this point in the history
Homepage modules
  • Loading branch information
johnglover committed Oct 3, 2013
2 parents 4e6625a + 4ee4ddb commit c82d8e5
Show file tree
Hide file tree
Showing 15 changed files with 344 additions and 159 deletions.
6 changes: 6 additions & 0 deletions ckan/controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def _get_config_form_items(self):
{'text': 'Green', 'value': '/base/css/green.css'},
{'text': 'Maroon', 'value': '/base/css/maroon.css'},
{'text': 'Fuchsia', 'value': '/base/css/fuchsia.css'}]

homepages = [{'value': '1', 'text': 'Introductory area, search, featured group and featured organization'},
{'value': '2', 'text': 'Search, stats, introductory area, featured organization and featured group'},
{'value': '3', 'text': 'Search, introductory area and stats'}]

items = [
{'name': 'ckan.site_title', 'control': 'input', 'label': _('Site Title'), 'placeholder': ''},
{'name': 'ckan.main_css', 'control': 'select', 'options': styles, 'label': _('Style'), 'placeholder': ''},
Expand All @@ -42,6 +47,7 @@ def _get_config_form_items(self):
{'name': 'ckan.site_about', 'control': 'markdown', 'label': _('About'), 'placeholder': _('About page text')},
{'name': 'ckan.site_intro_text', 'control': 'markdown', 'label': _('Intro Text'), 'placeholder': _('Text on home page')},
{'name': 'ckan.site_custom_css', 'control': 'textarea', 'label': _('Custom CSS'), 'placeholder': _('Customisable css inserted into the page header')},
{'name': 'ckan.homepage_style', 'control': 'select', 'options': homepages, 'label': _('Homepage'), 'placeholder': ''},
]
return items

Expand Down
2 changes: 2 additions & 0 deletions ckan/lib/app_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'ckan.site_about',
'ckan.site_intro_text',
'ckan.site_custom_css',
'ckan.homepage_style',
]

config_details = {
Expand All @@ -46,6 +47,7 @@
'ckan.dumps_format': {},
'ckan.api_url': {},
'ofs.impl': {'name': 'ofs_impl'},
'ckan.homepage_style': {'default': '1'},

# split string
'search.facets': {'default': 'organization groups tags res_format license_id',
Expand Down
77 changes: 77 additions & 0 deletions ckan/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,80 @@ def new_activities():
return action({}, {})


def get_featured_organizations(count=1):
'''Returns a list of favourite organization in the form
of organization_list action function
'''
config_orgs = config.get('ckan.featured_orgs', '').split()
orgs = featured_group_org(get_action='organization_show',
list_action='organization_list',
count=count,
items=config_orgs)
return orgs


def get_featured_groups(count=1):
'''Returns a list of favourite group the form
of organization_list action function
'''
config_groups = config.get('ckan.featured_groups', '').split()
groups = featured_group_org(get_action='group_show',
list_action='group_list',
count=count,
items=config_groups)
return groups


def featured_group_org(items, get_action, list_action, count):
def get_group(id):
context = {'ignore_auth': True,
'limits': {'packages': 2},
'for_view': True}
data_dict = {'id': id}

try:
out = logic.get_action(get_action)(context, data_dict)
except logic.ObjectNotFound:
return None
return out

groups_data = []

extras = logic.get_action(list_action)({}, {})

# list of found ids to prevent duplicates
found = []
for group_name in items + extras:
group = get_group(group_name)
if not group:
continue
# check if duplicate
if group['id'] in found:
continue
found.append(group['id'])
groups_data.append(group)
if len(groups_data) == count:
break

return groups_data


def get_site_statistics():
stats = {}
stats['dataset_count'] = logic.get_action('package_search')(
{}, {"rows": 1})['count']
stats['group_count'] = len(logic.get_action('group_list')({}, {}))
stats['organization_count'] = len(
logic.get_action('organization_list')({}, {}))
result = model.Session.execute(
'''select count(*) from related r
left join related_dataset rd on r.id = rd.related_id
where rd.status = 'active' or rd.id is null''').first()[0]
stats['related_count'] = result

return stats


# these are the functions that will end up in `h` template helpers
__allowed_functions__ = [
# functions defined in ckan.lib.helpers
Expand Down Expand Up @@ -1761,4 +1835,7 @@ def new_activities():
'radio',
'submit',
'asbool',
'get_featured_organizations',
'get_featured_groups',
'get_site_statistics',
]
145 changes: 75 additions & 70 deletions ckan/public/base/less/homepage.less
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
.hero {
background: url("@{imagePath}/background-tile.png");
padding: 20px 0;
min-height: 0;
> .container {
position: relative;
padding-bottom: 0;
}
.search-giant {
margin-bottom: 10px;
input {
border-color: darken(@mastheadBackgroundColorEnd, 5);
}
.homepage {

[role=main] {
padding: 20px 0;
min-height: 0;
}
.page-heading {
font-size: 18px;
margin-bottom: 0;

.row {
position: relative;
}
.module-dark {

.module-search {
padding: 5px;
margin-bottom: 0;
margin: 0;
color: @mastheadTextColor;
background: @layoutTrimBackgroundColor;
.search-giant {
margin-bottom: 10px;
input {
border-color: darken(@mastheadBackgroundColorEnd, 5);
}
}
.module-content {
.border-radius(3px 3px 0 0);
background-color: @mastheadBackgroundColor;
Expand All @@ -32,66 +31,72 @@
line-height: 40px;
}
}
}
.tags {
.clearfix();
padding: 5px 10px 10px 10px;
background-color: darken(@mastheadBackgroundColor, 10%);
.border-radius(0 0 3px 3px);
h3,
.tag {
display: block;
float: left;
margin: 5px 10px 0 0;
}
h3 {
font-size: @baseFontSize;
line-height: @baseLineHeight;
padding: 2px 8px;
.tags {
.clearfix();
padding: 5px 10px 10px 10px;
background-color: darken(@mastheadBackgroundColor, 10%);
.border-radius(0 0 3px 3px);
h3,
.tag {
display: block;
float: left;
margin: 5px 10px 0 0;
}
h3 {
font-size: @baseFontSize;
line-height: @baseLineHeight;
padding: 2px 8px;
}
}
}
}

.hero-primary,
.hero-secondary {
.makeColumn(6);
}

.hero-primary {
margin-left: 0; // Remove grid margin.
margin-bottom: 0;
}

.hero-secondary {
position: absolute;
bottom: 0;
right: 0;
.hero-secondary-inner {
bottom: 0;
left: 0;
right: 0;
.group-list {
margin: 0;
}
}

.main.homepage {
padding-top: 20px;
padding-bottom: 20px;
border-top: 1px solid @layoutTrimBorderColor;
.module-heading .media-image {
margin-right: 15px;
max-height: 53px;
.box-shadow(0 0 0 2px rgba(255, 255, 255, 0.5));
.box .inner {
padding: @gutterY @gutterX;
}
.group-listing .box {
min-height: 275px;

.stats {
h3 {
margin: 0 0 10px 0;
}
ul {
.unstyled;
.clearfix;
li {
float: left;
width: 25%;
font-weight: 300;
a {
display: block;
b {
display: block;
font-size: @fontSizeLarge*2;
line-height: 1.5;
}
&:hover {
text-decoration: none;
}
}
}
}
}
.group-list {
margin-bottom: 0;
.dataset-content {
min-height: 70px;

&.layout-1 .row1 .col2 {
position: absolute;
bottom: 0;
right: 0;
.module-search {
bottom: 0;
left: 0;
right: 0;
}
}
.box .module {
margin-top: 0;

&.layout-2 .stats {
margin-top: @gutterY;
}

}
8 changes: 7 additions & 1 deletion ckan/templates/admin/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

{% block primary_content_inner %}
<form method='post' action="" class="form-horizontal">
{{ autoform.generate(form_items, data, errors) }}
{% block admin_form %}
{{ autoform.generate(form_items, data, errors) }}
{% endblock %}
<div class="form-actions">
{% set locale = h.dump_json({'content': _('Are you sure you want to reset the config?')}) %}
<a href="{% url_for controller='admin', action='reset_config' %}" class="btn btn-danger pull-left" data-module="confirm-action" data-module-i18n="{{ locale }}">{{ _('Reset') }}</a>
Expand All @@ -20,6 +22,7 @@ <h2 class="module-heading">
{{ _('CKAN config options') }}
</h2>
<div class="module-content">
{% block admin_form_help %}
{% set about_url = h.url_for(controller='home', action='about') %}
{% set home_url = h.url_for(controller='home', action='index') %}
{% set docs_url = "http://docs.ckan.org/en/{0}/theming.html".format(g.ckan_doc_version) %}
Expand All @@ -38,7 +41,10 @@ <h2 class="module-heading">
<code>&lt;head&gt;</code> tag of every page. If you wish to customize
the templates more fully we recommend
<a href="{{ docs_url }}" target="_blank">reading the documentation</a>.</p>
<p><strong>Homepage:</strong> This is for choosing a predefined layout for
the modules that appear on your homepage.</p>
{% endtrans %}
{% endblock %}
</div>
</div>
{% endblock %}

0 comments on commit c82d8e5

Please sign in to comment.