Skip to content

Commit

Permalink
[1126] move homepage modules into core and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Oct 2, 2013
1 parent 3fbe844 commit ad55287
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 110 deletions.
3 changes: 1 addition & 2 deletions ckan/controllers/home.py
Expand Up @@ -179,8 +179,7 @@ def db_to_form_schema(group_type=None):

# END OF DIRTYNESS

template = 'home/layout{0}.html'.format(g.homepage_style)
return base.render(template, cache_force=True)
return base.render('home/index.html', cache_force=True)

def license(self):
return base.render('home/license.html')
Expand Down
1 change: 1 addition & 0 deletions ckan/lib/app_globals.py
Expand Up @@ -29,6 +29,7 @@
'ckan.site_about',
'ckan.site_intro_text',
'ckan.site_custom_css',
'ckan.homepage_style',
]

config_details = {
Expand Down
71 changes: 71 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -1663,6 +1663,74 @@ def new_activities():
action = logic.get_action('dashboard_new_activities_count')
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
# ckeck 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__ = [
Expand Down Expand Up @@ -1761,4 +1829,7 @@ def new_activities():
'radio',
'submit',
'asbool',
'get_featured_organizations',
'get_featured_groups',
'get_site_statistics',
]
16 changes: 1 addition & 15 deletions ckan/templates/home/index.html
@@ -1,15 +1 @@
{% extends "page.html" %}

{% block subtitle %}{{ _("Welcome") }}{% endblock %}

{% block maintag %}{% endblock %}
{% block toolbar %}{% endblock %}

{% block content %}
<div class="homepage{% block homepage_layout_class %}{% endblock %}">
<div class="container">
{{ self.flash() }}
</div>
{% block primary_content %}{% endblock %}
</div>
{% endblock %}
{% include "home/layout" + (g.homepage_style or '1') + ".html" %}
15 changes: 15 additions & 0 deletions ckan/templates/home/index_base.html
@@ -0,0 +1,15 @@
{% extends "page.html" %}

{% block subtitle %}{{ _("Welcome") }}{% endblock %}

{% block maintag %}{% endblock %}
{% block toolbar %}{% endblock %}

{% block content %}
<div class="homepage{% block homepage_layout_class %}{% endblock %}">
<div class="container">
{{ self.flash() }}
</div>
{% block primary_content %}{% endblock %}
</div>
{% endblock %}
@@ -1,4 +1,4 @@
{% extends 'home/index.html' %}
{% extends 'home/index_base.html' %}

{% block homepage_layout_class %} layout-1{% endblock %}

Expand Down
@@ -1,4 +1,4 @@
{% extends 'home/index.html' %}
{% extends 'home/index_base.html' %}

{% block homepage_layout_class %} layout-2{% endblock %}

Expand Down
@@ -1,4 +1,4 @@
{% extends 'home/index.html' %}
{% extends 'home/index_base.html' %}

{% block homepage_layout_class %} layout-3{% endblock %}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file removed ckanext/homepage/__init__.py
Empty file.
89 changes: 0 additions & 89 deletions ckanext/homepage/plugin.py

This file was deleted.

14 changes: 14 additions & 0 deletions doc/configuration.rst
Expand Up @@ -810,6 +810,20 @@ Defines a list of group names or group ids. This setting is used to display
groups and datasets from each group on the home page in the default templates
(2 groups and 2 datasets for each group are displayed).

.. _ckan.featured_organizations:

ckan.featured_orgs
^^^^^^^^^^^^^^^^^^^^

Example::

ckan.featured_orgs = org_one org_two

Default Value: (empty)

Defines a list of organization names or ids. This setting is used to display
organization and datasets from each group on the home page in the default
templates (2 groups and 2 datasets for each group are displayed).

.. _ckan.gravatar_default:

Expand Down
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -129,7 +129,6 @@
[ckan.system_plugins]
domain_object_mods = ckan.model.modification:DomainObjectModificationExtension
homepage = ckanext.homepage.plugin:HomepagePlugin
[ckan.test_plugins]
routes_plugin=tests.ckantestplugins:RoutesPlugin
Expand Down

0 comments on commit ad55287

Please sign in to comment.