Skip to content

Commit

Permalink
[#1126] Brings featured groups/orgs from from be06121 into this branch
Browse files Browse the repository at this point in the history
It's just a slightly edited version of
https://github.com/okfn/ckan/blob/be06121/ckanext/featured/plugin.py as now
the helpers are returning data and not data+html.
  • Loading branch information
johnmartin committed Aug 29, 2013
1 parent c3c39ea commit 6b1b6f0
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
67 changes: 61 additions & 6 deletions ckanext/homepage/plugin.py
Expand Up @@ -6,19 +6,74 @@

class HomepagePlugin(p.SingletonPlugin):
p.implements(p.IConfigurer, inherit=True)
p.implements(p.ITemplateHelpers, inherit=True)
p.implements(p.IConfigurable, inherit=True)

featured_groups_cache = None
featured_orgs_cache = None

def configure(self, config):
groups = config.get('ckan.featured_groups', '')
if groups:
log.warning('Config setting `ckan.featured_groups` is deprecated '
'please use `ckanext.homepage.groups`')
self.groups = config.get('ckanext.homepage.groups', groups).split()
self.orgs = config.get('ckanext.homepage.orgs', '').split()

def update_config(self, config):
p.toolkit.add_template_directory(config, 'theme/templates')

def get_featured_organization(self):
return
def get_featured_organizations(self, count=1):
orgs = self.featured_group_org(get_action='organization_show',
list_action='organization_list',
count=count,
items=self.orgs)
self.featured_orgs_cache = orgs
return self.featured_orgs_cache

def get_featured_groups(self, count=1):
groups = self.featured_group_org(get_action='group_show',
list_action='group_list',
count=count,
items=self.groups)
self.featured_groups_cache = groups
return self.featured_groups_cache

def featured_group_org(self, 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 = p.toolkit.get_action(get_action)(context, data_dict)
except p.toolkit.ObjectNotFound:
return None
return out

groups_data = []

extras = p.toolkit.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

def get_featured_group(self):
return
return groups_data

def get_helpers(self):
return {
'get_featured_organization': self.get_featured_organization,
'get_featured_group': self.get_featured_group,
'get_featured_organizations': self.get_featured_organizations,
'get_featured_groups': self.get_featured_groups,
}
@@ -1,5 +1,7 @@
{% set group = h.get_featured_group() %}
{% set groups = h.get_featured_groups() %}

<div class="box">
{% snippet 'snippets/group_item.html', group=group, truncate=50, truncate_title=35 %}
</div>
{% for group in groups %}
<div class="box">
{% snippet 'snippets/group_item.html', group=group, truncate=50, truncate_title=35 %}
</div>
{% endfor %}
@@ -1,5 +1,7 @@
{% set organization = h.get_featured_organization() %}
{% set organizations = h.get_featured_organizations() %}

<div class="box">
{% snippet 'snippets/organization_item.html', organization=organization, truncate=50, truncate_title=35 %}
</div>
{% for organization in organizations %}
<div class="box">
{% snippet 'snippets/organization_item.html', organization=organization, truncate=50, truncate_title=35 %}
</div>
{% endfor %}

0 comments on commit 6b1b6f0

Please sign in to comment.