Skip to content

Commit

Permalink
Merge pull request #477 from OCHA-DAP/staging
Browse files Browse the repository at this point in the history
Merge STAG to PROD
  • Loading branch information
danmihaila committed Jun 3, 2014
2 parents 35ede8e + 74adf9a commit 82243cc
Show file tree
Hide file tree
Showing 38 changed files with 2,571 additions and 141 deletions.
7 changes: 6 additions & 1 deletion ckanext-hdx_theme/ckanext/hdx_theme/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import ckan.plugins as plugins
import ckan.lib.plugins as lib_plugins
import ckan.new_authz as new_authz
import beaker.cache as bcache

import ckanext.hdx_theme.caching as caching

from ckan.common import _

Expand Down Expand Up @@ -77,5 +80,7 @@ def organization_list_for_user(context, data_dict):
# it['created']=org.created.isoformat()
return orgs_list


def cached_group_list(context, data_dict):
groups = caching.cached_group_list()
return groups

56 changes: 56 additions & 0 deletions ckanext-hdx_theme/ckanext/hdx_theme/caching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'''
Created on Jun 2, 2014
@author: alexandru-m-g
'''

import ckan.plugins.toolkit as tk
import beaker.cache as bcache

import ckanext.hdx_theme.country_list_hardcoded as focus_countries


bcache.cache_regions.update({
'hdx_memory_cache':{
'expire': 172800, # 2 days
'type':'memory',
'key_length': 250
}
})


@bcache.cache_region('hdx_memory_cache', 'cached_group_list')
def cached_group_list():
groups = tk.get_action('group_list')(data_dict={'all_fields': True})
return groups


def invalidate_cached_group_list():
bcache.region_invalidate(cached_group_list, 'hdx_memory_cache', 'cached_group_list')



def filter_focus_countries(group_package_stuff):
focus_group_package_stuff = []
for grp_dict in group_package_stuff:
if grp_dict['display_name'] in focus_countries.FOCUS_COUNTRIES:
focus_group_package_stuff.append(grp_dict)

return focus_group_package_stuff

@bcache.cache_region('hdx_memory_cache', 'focus_countries_list')
def cached_get_group_package_stuff():
group_package_stuff = tk.get_action('cached_group_list')()
focus_group_package_stuff = filter_focus_countries(group_package_stuff)

return sorted(focus_group_package_stuff, key=lambda k: k['title'])

def invalidate_cached_get_group_package_stuff():
bcache.region_invalidate(cached_get_group_package_stuff, 'hdx_memory_cache', 'focus_countries_list')


def invalidate_group_caches():
for invalidate_func in group_invalidation_functions:
invalidate_func()

group_invalidation_functions = [invalidate_cached_group_list, invalidate_cached_get_group_package_stuff]
62 changes: 62 additions & 0 deletions ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/bs_popover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use strict";

ckan.module('bs_popover', function($, _) {
return {
initialize : function() {
var content = this.options.content;
if (this.options.social_div_id) {
var contentEl = $('#'+this.options.social_div_id);
var newContent = contentEl.html();
contentEl.remove();
if ( newContent && newContent.length > 0 )
content = newContent;
}

var popoverWrapper = document.body;
if (this.options.social_wrapper_div_id) {
var tempPopoverWrapper = $('#'+this.options.social_wrapper_div_id);
if (tempPopoverWrapper) {
popoverWrapper = tempPopoverWrapper;
this.popoverWrapper = tempPopoverWrapper;
}
}

this.el.popover({
trigger : this.options.trigger,
placement : this.options.placement,
content : content,
title : this.options.title,
html: true,
container: popoverWrapper
});

this.el.on('click.bs_popover', $.proxy(this._onClick, this));
},
_onClick: function(e){
this.el.popover("show");
e.stopPropagation();
$('html').on('click.bs_popover', $.proxy(this._onOtherClick, this));
},
_onOtherClick: function(e) {
this.el.popover("hide");
$('html').off('click.bs_popover');

},
// _isVisible: function() {
// var popoverDivEls = this.popoverWrapper.find('.popover');
// if (popoverDivEls && popoverDivEls.length > 0 )
// return true;
//
// return false;
// },
options : {
placement : 'top',
trigger : 'manual',
content : 'Empty !',
title : 'No Title !',
social_div_id : null,
social_wrapper_div_id: null

}
};
});
14 changes: 12 additions & 2 deletions ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/dataset_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ $('#country-drop').change(function(){
$('#'+id).remove();
$(event.target).parent().remove();
}
//Reset dropdown for better userability
$('#country-drop option[value=-1]').attr('selected', true);
});

$('#field-organizations').change(function(){
if($(this).val() == ''){
$('#field-private option[value=False]').attr('selected', true);
$('#field-private').attr('disabled', true);
$('#field-private').attr('readonly', true);
}else{
$('#field-private').removeAttr('disabled');
$('#field-private').removeAttr('readonly');
}
});

Expand Down Expand Up @@ -67,3 +69,11 @@ $('#field-organizations').change(function(){
}
$("#field-dataset_date, #date_range1, #date_range2").datepicker();
});

$('#field-license').change(function(){
if($(this).val() == 'hdx-other'){
$('#licenses-other-define').show();
}else{
$('#licenses-other-define').hide();
}
});
86 changes: 86 additions & 0 deletions ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/follow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* Follow buttons
* Handles calling the API to follow the current user
*
* action - This being the action that the button should perform. Currently: "follow" or "unfollow"
* type - The being the type of object the user is trying to support. Currently: "user" or "group"
* id - id of the objec the user is trying to follow
* loading - State management helper
*
* Examples
*
* <a data-module="follow" data-module-action="follow" data-module-type="user" data-module-id="{user_id}">Follow User</a>
*
*/
this.ckan.module('hdx_follow', function($, _) {
return {
/* options object can be extended using data-module-* attributes */
options : {
action: null,
type: null,
id: null,
loading: false,
i18n: {
follow: _('Follow'),
unfollow: _('Unfollow')
}
},

/* Initialises the module setting up elements and event listeners.
*
* Returns nothing.
*/
initialize: function () {
$.proxyAll(this, /_on/);
this.el.on('click', this._onClick);
},

/* Handles the clicking of the follow button
*
* event - An event object.
*
* Returns nothing.
*/
_onClick: function(event) {
var options = this.options;
if (
options.action
&& options.type
&& options.id
&& !options.loading
) {
event.preventDefault();
var client = this.sandbox.client;
var path = options.action + '_' + options.type;
options.loading = true;
this.el.addClass('disabled');
client.call('POST', path, { id : options.id }, this._onClickLoaded);
}
},

/* Fired after the call to the API to either follow or unfollow
*
* json - The return json from the follow / unfollow API call
*
* Returns nothing.
*/
_onClickLoaded: function(json) {
var options = this.options;
var sandbox = this.sandbox;
options.loading = false;
this.el.removeClass('disabled');
var followers = $(this.el).parent().parent().find(".followersNumber").find("span");
var next_val = parseInt(followers.html());
if (options.action == 'follow') {
options.action = 'unfollow';
this.el.html(this.i18n('unfollow'));
next_val = next_val + 1;
} else {
options.action = 'follow';
this.el.html(this.i18n('follow'));
next_val = next_val - 1;
}
followers.html(next_val);
sandbox.publish('follow-' + options.action + '-' + options.id);
}
};
});
24 changes: 24 additions & 0 deletions ckanext-hdx_theme/ckanext/hdx_theme/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sqlalchemy
import ckan.logic as logic
import datetime
import version
import count
import json
import logging
Expand Down Expand Up @@ -116,5 +117,28 @@ def render_date_from_concat_str(str, separator='-'):
log.warning(e)

return result

def hdx_build_nav_icon_with_message(menu_item, title, **kw):
htmlResult = h.build_nav_icon(menu_item, title, **kw)
if 'message' not in kw or not kw['message']:
return htmlResult
else:
newResult = str(htmlResult).replace('</a>',
' <span class="nav-short-message">{message}</span></a>'.format(message=kw['message']) )
return h.literal(newResult)

def hdx_num_of_new_related_items():
max_days = 30;
count = 0;
now = datetime.datetime.now()
for related in c.pkg.related:
if (related.created):
difference = now-related.created
days = difference.days
if days < max_days:
count += 1
return count


def hdx_version():
return version.hdx_version
10 changes: 10 additions & 0 deletions ckanext-hdx_theme/ckanext/hdx_theme/licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ class LicenseOtherPublicDomainNoRestrictions(DefaultLicense):
def title(self):
return _("Public Domain / No Restrictions")

class LicenseHdxMultiple(DefaultLicense):
# domain_content = True
id = "hdx-multi"
# is_generic = True
# is_okd_compliant = True

@property
def title(self):
return _("Multiple Licenses")

class LicenseHdxOther(DefaultLicense):
# domain_content = True
id = "hdx-other"
Expand Down
Loading

0 comments on commit 82243cc

Please sign in to comment.