Skip to content

Commit

Permalink
Merge pull request #2904 from OCHA-DAP/staging
Browse files Browse the repository at this point in the history
Preparing release
  • Loading branch information
aalecs committed May 27, 2015
2 parents eea3a8b + c2aed08 commit 1dbb900
Show file tree
Hide file tree
Showing 39 changed files with 897 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
request = common.request
_ = common._


log = logging.getLogger(__name__)

suffix = '#datasets-section'


def _get_embed_url(viz_config):
ckan_url = config.get('ckan.site_url', '').strip()
position = ckan_url.find('//')
Expand All @@ -52,8 +52,8 @@ def _get_embed_url(viz_config):
url = ckan_url + widget_url
return url

class CustomOrgController(org.OrganizationController, simple_search_controller.HDXSimpleSearchController):

class CustomOrgController(org.OrganizationController, simple_search_controller.HDXSimpleSearchController):
def org_read(self, id):

org_info = self.get_org(id)
Expand All @@ -66,7 +66,6 @@ def org_read(self, id):
'css_path': less.generate_custom_css_path(css_dest_dir, id, org_info['modified_at'], True)
}


result = render(
'organization/custom/custom_org.html', extra_vars=template_data)

Expand All @@ -77,49 +76,54 @@ def assemble_viz_config(self, visualization):
visualization = json.loads(visualization)
except:
return "{}"

config = {
'title':visualization.get('viz-title',''),
'data_link_url':visualization.get('viz-data-link-url','#'),
'type': visualization.get('visualization-select','')
'title': visualization.get('viz-title', ''),
'data_link_url': visualization.get('viz-data-link-url', '#'),
'type': visualization.get('visualization-select', '')
}

if visualization.get('visualization-select','') == 'WFP':
if visualization.get('visualization-select', '') == 'WFP':
config.update({
'embedded': "true"
'embedded': "true",
'data_link_url':visualization.get('viz-data-link-url','#'),
'type': visualization.get('visualization-select',''),
'resource_id': visualization.get('viz-resource-id', '#'),
'datastore_id':visualization.get('viz-resource-id', '')
})
return config

if visualization.get('datatype_1','') =='filestore':
if visualization.get('datatype_1', '') == 'filestore':
datatype = "filestore"
data = h.url_for('perma_storage_file', id=visualization.get('dataset_id_1',''), resource_id=visualization.get('resource_id_1',''))
data = h.url_for('perma_storage_file', id=visualization.get('dataset_id_1', ''),
resource_id=visualization.get('resource_id_1', ''))
else:
datatype = "datastore"
data = "/api/action/datastore_search?resource_id="+visualization.get('resource_id_1','')+"&limit=10000000"

if visualization.get('datatype_2','') =='filestore':
data = "/api/action/datastore_search?resource_id=" + visualization.get('resource_id_1',
'') + "&limit=10000000"

if visualization.get('datatype_2', '') == 'filestore':
geotype = "filestore"
geo = h.url_for('perma_storage_file', id=visualization.get('dataset_id_2',''), resource_id=visualization.get('resource_id_2',''))
geo = h.url_for('perma_storage_file', id=visualization.get('dataset_id_2', ''),
resource_id=visualization.get('resource_id_2', ''))
else:
geotype = "datastore"
geo = "/api/action/datastore_search?resource_id="+visualization.get('resource_id_2','')+"&limit=10000000"
geo = "/api/action/datastore_search?resource_id=" + visualization.get('resource_id_2',
'') + "&limit=10000000"

#beware that visualisation type constants are also used in the template to select different resource bundles
if visualization.get('visualization-select','') == '3W-dashboard':
# beware that visualisation type constants are also used in the template to select different resource bundles
if visualization.get('visualization-select', '') == '3W-dashboard':
config.update({'datatype': datatype,
'data': data,
'whoFieldName':visualization.get('who-column',''),
'whatFieldName':visualization.get('what-column',''),
'whereFieldName':visualization.get('where-column',''),
'geotype': geotype,
'geo':geo,
'joinAttribute':visualization.get('where-column-2',''),
'nameAttribute':visualization.get('map_district_name_column',''),
'x':visualization.get('pos-x',''),
'y':visualization.get('pos-y',''),
'zoom':visualization.get('zoom',''),
'colors':visualization.get('colors','')
})
'data': data,
'whoFieldName': visualization.get('who-column', ''),
'whatFieldName': visualization.get('what-column', ''),
'whereFieldName': visualization.get('where-column', ''),
'geotype': geotype,
'geo': geo,
'joinAttribute': visualization.get('where-column-2', ''),
'nameAttribute': visualization.get('map_district_name_column', ''),
'colors': visualization.get('colors', '')
})

return config

Expand Down Expand Up @@ -171,7 +175,7 @@ def generate_template_data(self, org_info):
{'model': model, 'session': model.Session},
{'id': org_info['id']}
)
add_data_url = h.url_for('add dataset')+'?organization_id={}'.format(org_info['id'])
add_data_url = h.url_for('add dataset') + '?organization_id={}'.format(org_info['id'])
template_data = {
'data': {
'org_info': org_info,
Expand Down Expand Up @@ -238,14 +242,15 @@ def get_org(self, org_id):

org_url = [el.get('value', None) for el in result.get('extras', []) if el.get('key', '') == 'org_url']

json_extra = [el.get('value', None) for el in result.get('extras', []) if el.get('key', '') == 'customization']
json_extra = [el.get('value', None) for el in result.get('extras', []) if
el.get('key', '') == 'customization']
jsonstring = json_extra[0] if len(json_extra) == 1 else ''
if jsonstring and jsonstring.strip():
json_dict = json.loads(jsonstring)
top_line_src_info = self._get_top_line_src_info(json_dict)
images = self._get_images(json_dict)
else:
top_line_src_info = (None,None)
top_line_src_info = (None, None)
images = (None, None)

org_dict = {
Expand All @@ -260,7 +265,7 @@ def get_org(self, org_id):
'modified_at': result.get('modified_at', ''),
'image_sq': images[0],
'image_rect': images[1],
'visualization_config': result.get('visualization_config',''),
'visualization_config': result.get('visualization_config', ''),
}

return org_dict
Expand All @@ -274,18 +279,17 @@ def get_org(self, org_id):

def _get_images(self, json_dict):
if 'image_sq' in json_dict and 'image_rect' in json_dict:
return (json_dict['image_sq'], json_dict['image_rect'])
return (json_dict['image_sq'], json_dict['image_rect'])
elif 'image_sq' in json_dict:
return (json_dict['image_sq'], None)
elif 'image_rect' in json_dict:
return (None, json_dict['image_rect'])

return (None, None)


def _get_top_line_src_info(self, json_dict):
if 'topline_dataset' in json_dict and 'topline_resource' in json_dict:
return (json_dict['topline_dataset'], json_dict['topline_resource'])
return (json_dict['topline_dataset'], json_dict['topline_resource'])

return (None, None)

Expand Down Expand Up @@ -386,7 +390,7 @@ def _populate_facet_links(self, facets, params):
item['is_used'] = True
else:
params_item_copy[code] = params_item_copy[
code] + [item['name']]
code] + [item['name']]
item['filter_link'] = h.url_for(
self._get_named_route(), **params_item_copy) + suffix
item['is_used'] = False
Expand Down Expand Up @@ -433,7 +437,7 @@ def pager_url(q=None, page=None):
'auth_user_obj': c.userobj}

is_org_member = (context.get('user', None) and
new_authz.has_user_permission_for_group_or_org(org_code, context.get('user'), 'read'))
new_authz.has_user_permission_for_group_or_org(org_code, context.get('user'), 'read'))
if is_org_member:
context['ignore_capacity_check'] = True

Expand Down Expand Up @@ -471,7 +475,7 @@ def generate_query_placeholder(self, tab, dataset_count, indicator_count):
body = ''

if tab == 'all':
body = hdx_helpers.hdx_show_singular_plural(dataset_count+indicator_count,
body = hdx_helpers.hdx_show_singular_plural(dataset_count + indicator_count,
_('indicator / dataset'),
_('indicators & datasets'), True)
elif tab == 'indicators':
Expand All @@ -496,4 +500,3 @@ def check_access(self, action_name, data_dict=None):
result = False

return result

2 changes: 1 addition & 1 deletion ckanext-hdx_package/ckanext/hdx_package/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _tag_search(context, data_dict):
term, escape='\\')
q = q.filter(model.Tag.name.ilike('%' + escaped_term + '%'))

q = q.filter(model.PackageTag.state == 'active')
q = q.join('package_tags').filter(model.PackageTag.state == 'active')
count = q.count()
q = q.offset(offset)
q = q.limit(limit)
Expand Down
7 changes: 3 additions & 4 deletions ckanext-hdx_package/ckanext/hdx_package/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class HDXPackagePlugin(plugins.SingletonPlugin, tk.DefaultDatasetForm):
plugins.implements(plugins.IActions)
plugins.implements(plugins.IMiddleware, inherit=True)
plugins.implements(plugins.IResourceController, inherit=True)

def update_config(self, config):
tk.add_template_directory(config, 'templates')

Expand Down Expand Up @@ -163,7 +163,7 @@ def _modify_package_schema(self, schema):
tk.get_converter('convert_to_extras')],
'subnational': [tk.get_validator('ignore_missing'),
tk.get_converter('convert_to_extras')],
'quality': [tk.get_validator('ignore_missing'),
'quality': [tk.get_validator('ignore_not_sysadmin'), tk.get_validator('ignore_missing'),
tk.get_converter('convert_to_extras')],
})

Expand Down Expand Up @@ -222,8 +222,7 @@ def show_package_schema(self):
tk.get_validator('ignore_missing')],
'subnational': [tk.get_converter('convert_from_extras'),
tk.get_validator('ignore_missing')],
'quality': [tk.get_converter('convert_from_extras'),
tk.get_validator('ignore_missing')],
'quality': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')],
})
return schema

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
'''

import ckan.tests as tests
from ckan.tests.functional.api.base import *
import json
import webtest
import ckan.plugins as p
import ckan.lib.create_test_data as ctd
Expand All @@ -23,7 +25,7 @@

log = logging.getLogger(__name__)

class TestMetadataFields(tests.WsgiAppCase):
class TestMetadataFields(tests.WsgiAppCase, ApiTestCase):

@classmethod
def setup_class(cls):
Expand Down Expand Up @@ -143,6 +145,13 @@ def test_related_items_owner_status(self):
#Confirm related item owner status
assert result['owner_id'] == user.id

def test_tags_autocomplete(self):
offset = '/api/2/util/tag/autocomplete?incomplete=a'

res = self.app.get(offset, status=[200,302])
r = json.loads(res.body)
assert len(r['ResultSet']['Result']) > 0

def _related_create(self, title, description, type, url, image_url):
usr = logic.get_action('get_site_user')({'model':model,'ignore_auth': True},{})

Expand Down
5 changes: 5 additions & 0 deletions ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/base/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ a:focus,
display: inline-block;
width: 45px;
padding: 0;
line-height: 45px;
}
.pagination li.active a,
.module .pagination li.active a {
Expand Down Expand Up @@ -277,6 +278,10 @@ body {
line-height: 25px;
color: #eeeeee;
}
.newHeader .header-user-box i,
.newHeader .header-user-box > span > a i {
display: none;
}
.newHeader .header-user-name {
color: #f2645a;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
display: inline-block;
width: 45px;
padding: 0;
line-height: 45px;
}
.pagination li.active a,
.module .pagination li.active a {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ function buildGraphs() {
}
},
y: {
//label: {
// text: unitName,
// position: 'outer-middle'
//}
label: {
text: unitName,
position: 'outer-middle'
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function prepareGraph(element, data, colX, colXType, colXFormat, colY, graphType
return graph;
}

function prepareGraph2(element, data, colXType, colXFormat, graphType, colorList) {
function prepareGraph2(element, data, colXType, colXFormat, graphType, colorList, columnYLabel) {
var config = {
bindto: element,
color: {
Expand All @@ -109,6 +109,12 @@ function prepareGraph2(element, data, colXType, colXFormat, graphType, colorList
max: 22
}
}
},
y: {
label: {
text: columnYLabel,
position: 'outer-middle'
}
}
}
};
Expand Down Expand Up @@ -172,7 +178,7 @@ function autoGraph() {
sourceListDiv.html(sourceList);

$.when.apply($, promises).done(function(sources){
var columnX, columnXType, columnXFormat, columnY, graphType;
var columnX, columnXType, columnXFormat, columnY, columnYLabel, graphType;

var dataCols = [];
var dataColsInit = false;
Expand All @@ -189,6 +195,7 @@ function autoGraph() {
columnXType = null,
columnXFormat = null,
columnY = response.column_y,
columnYLabel = graphData.title_y,
graphType = graphData.type;

if (data.fields[0].type == 'timestamp'){
Expand All @@ -213,7 +220,7 @@ function autoGraph() {
dataCols.push(colY);
}
}
graph = prepareGraph2(graphDataDiv[0], dataCols, columnXType, columnXFormat, graphType, colorList);
graph = prepareGraph2(graphDataDiv[0], dataCols, columnXType, columnXFormat, graphType, colorList, columnYLabel);
});

});
Expand Down
Loading

0 comments on commit 1dbb900

Please sign in to comment.