Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#847] Add extra_public_paths example
- Loading branch information
Sean Hammond
committed
Oct 7, 2013
1 parent
068d0e0
commit 3c7f6c8
Showing
9 changed files
with
178 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
46 changes: 46 additions & 0 deletions
46
ckanext/example_theme/v11_extra_public_directory/plugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import ckan.plugins as plugins | ||
import ckan.plugins.toolkit as toolkit | ||
|
||
|
||
def most_popular_groups(): | ||
'''Return a sorted list of the groups with the most 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': 'packages desc', 'all_fields': True}) | ||
|
||
# Truncate the list to the 10 most popular groups only. | ||
groups = groups[:10] | ||
|
||
return groups | ||
|
||
|
||
class ExampleThemePlugin(plugins.SingletonPlugin): | ||
'''An example theme plugin. | ||
''' | ||
plugins.implements(plugins.IConfigurer) | ||
|
||
# Declare that this plugin will implement ITemplateHelpers. | ||
plugins.implements(plugins.ITemplateHelpers) | ||
|
||
def update_config(self, config): | ||
|
||
# Add this plugin's templates dir to CKAN's extra_template_paths, so | ||
# that CKAN will use this plugin's custom templates. | ||
toolkit.add_template_directory(config, 'templates') | ||
|
||
# Add this plugin's public dir to CKAN's extra_public_paths, so | ||
# that CKAN will use this plugin's custom static files. | ||
toolkit.add_public_directory(config, 'public') | ||
|
||
def get_helpers(self): | ||
'''Register the most_popular_groups() function above as a template | ||
helper function. | ||
''' | ||
# Template helper function names should begin with the name of the | ||
# extension they belong to, to avoid clashing with functions from | ||
# other extensions. | ||
return {'example_theme_most_popular_groups': most_popular_groups} |
Binary file added
BIN
+16.7 KB
ckanext/example_theme/v11_extra_public_directory/public/promoted-image.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions
37
ckanext/example_theme/v11_extra_public_directory/templates/home/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{% ckan_extends %} | ||
|
||
{% block home_image_content %} | ||
<a class="media-image" href="#"> | ||
<img src="featured-image.jpg" alt="Featured image" | ||
width="420" height="220" /> | ||
</a> | ||
{% endblock %} | ||
|
||
{% block home_image_caption %} | ||
{{ _("This is a customized featured section") }} | ||
{% endblock %} | ||
|
||
{% block secondary_content %} | ||
|
||
<div class="row"> | ||
|
||
<div class="span6"> | ||
<div class="box"> | ||
<section class="module"> | ||
<header class="module-heading"> | ||
<h3>Recent activity</h3> | ||
</header> | ||
<div class="module-content"> | ||
{{ h.recently_changed_packages_activity_stream(limit=10) }} | ||
</div> | ||
</section> | ||
</div> | ||
</div> | ||
|
||
<div class="span6"> | ||
{% snippet 'snippets/example_theme_most_popular_groups.html' %} | ||
</div> | ||
|
||
</div> | ||
|
||
{% endblock %} |
13 changes: 13 additions & 0 deletions
13
ckanext/example_theme/v11_extra_public_directory/templates/home/snippets/promoted.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% ckan_extends %} | ||
|
||
{% block home_image_caption %} | ||
{{ _("CKAN's data previewing tool has many powerful features") }} | ||
{% endblock %} | ||
|
||
{# Replace the promoted image. #} | ||
{% block home_image_content %} | ||
<a class="media-image" href="#"> | ||
<img src="/promoted-image.jpg" alt="Featured image" | ||
width="420" height="220" /> | ||
</a> | ||
{% endblock %} |
1 change: 1 addition & 0 deletions
1
ckanext/example_theme/v11_extra_public_directory/templates/snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../v10_HTML_and_CSS/templates/snippets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters