Skip to content

Commit

Permalink
Merge pull request #9 from yongjiel/archive-date
Browse files Browse the repository at this point in the history
Archive date - If the date in the archive_date field has passed the record will have the archive banner displayed.
  • Loading branch information
coreyerickson authored Oct 4, 2016
2 parents c198117 + 58922b2 commit 47b52e2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
23 changes: 19 additions & 4 deletions ckanext/open_alberta/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import ckan.plugins.toolkit as toolkit
from ckanext.open_alberta import helpers
import pylons.config as config
import datetime
import dateutil.parser as parser

@toolkit.side_effect_free
def counter_on_off(context, data_dict=None):
Expand All @@ -22,6 +24,17 @@ def latest_datasets():

return datasets['results']

def check_archive_date(archive_date=""):
""" Return false if archive_date is empty or later than today.
Otherwise, return true.
"""
if archive_date == "":
return False
today = datetime.datetime.now()
archive_date = parser.parse(archive_date)
if today < archive_date:
return False
return True

class OpenAlbertaPagesPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.IRoutes, inherit=True)
Expand Down Expand Up @@ -96,7 +109,8 @@ def update_config(self, config_):
toolkit.add_resource('fanstatic', 'open_alberta')

def get_helpers(self):
return {'open_alberta_latest_datasets': latest_datasets}
return {'open_alberta_latest_datasets': latest_datasets,
'open_alberta_check_archive_date': check_archive_date}

def get_actions(self):
# Registers the custom API method defined above
Expand All @@ -109,6 +123,10 @@ def before_map(self, m):
m.connect('clone', '/dataset/clone/{id}',
controller='ckanext.open_alberta.controller:PackageCloneController',
action='index')

m.connect('delete-multiple' ,'/datasets/delete_multiple',
controller='ckanext.open_alberta.controller:PackagesDeleteController',
action='delete_datasets')
return m


Expand Down Expand Up @@ -152,6 +170,3 @@ def get_helpers(self):
'rss_fetch_feed': helpers.fetch_feed,
}




Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{% endblock %}

{% block delete_button %}
{% if form_style == 'edit' and h.check_access('package_delete', {'id': c.pkg_dict.id}) %}
{% if (form_style == 'edit' or c.pkg_dict.state == 'draft') and h.check_access('package_delete', {'id': c.pkg_dict.id}) %}
{{ super() }}
{% endif %}
{% endblock %}
13 changes: 11 additions & 2 deletions ckanext/open_alberta/templates/package/read.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
{# Display notes on package/read.html#}
{% set notes = h.markdown_extract(pkg.notes,extract_length=5000) %}

{% if pkg.archive_date|length > 0 %}
{% set archive_date = pkg.archive_date %}
{% elif pkg.archivedate|length > 0 %}
{% set archive_date = pkg.archivedate %}
{% else %}
{% set archive_date = "" %}
{% endif %}

{% block primary_content_inner %}
<div class="container nopadding">
<div class="row">
Expand All @@ -30,8 +38,9 @@ <h1>
</h1>
#}
</div>
{% if pkg.archive_date|length > 0 or pkg.archivedate|length > 0 %}
<div class="col-sm-12">

{% if h.open_alberta_check_archive_date(archive_date) %}
<div class="col-sm-12">
<h3 class="archived-item"><i class="fa fa-archive"></i> Archived</h3>
<div class="archived-item-explanation">This item has been replaced by a more recent resource or the content may be otherwise out of date. It is provided for informational and research purposes.</div>
</div>
Expand Down

0 comments on commit 47b52e2

Please sign in to comment.