Skip to content

Commit

Permalink
#4228 adding more analytics info on the contribute page
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandru-m-g committed Jun 20, 2016
1 parent afda062 commit 3252ffa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import ckan.lib.navl.dictization_functions as dict_fns
import ckan.lib.helpers as h

import ckanext.hdx_package.helpers.analytics as analytics

from ckan.common import _, request, response, c
from ckan.lib.search import SearchIndexError
from ckan.controllers.api import CONTENT_TYPES
Expand Down Expand Up @@ -110,8 +112,12 @@ def _abort(self, save_type, status_code, message):
def _prepare_and_render(self, save_type='', data=None, errors=None, error_summary=None):

save_type = save_type if save_type else ''

analytics_dict = self._generate_analytics_data(data)

template_data = {
'data': data,
'analytics': analytics_dict,
'errors': errors,
'error_summary': error_summary,
'aborted': False
Expand All @@ -123,6 +129,20 @@ def _prepare_and_render(self, save_type='', data=None, errors=None, error_summar
else:
return base.render('contribute_flow/create_edit.html', extra_vars=template_data)

def _generate_analytics_data(self, data):
# in case of an edit event we populate the analytics info
analytics_dict = {}
if data and data.get('id'):
analytics_dict['is_cod'] = analytics.is_cod(data)
analytics_dict['is_indicator'] = analytics.is_indicator(data)
analytics_dict['group_names'], analytics_dict['group_ids'] = analytics.extract_locations_in_json(data)
else:
analytics_dict['is_cod'] = 'false'
analytics_dict['is_indicator'] = 'false'
analytics_dict['group_names'] = '[]'
analytics_dict['group_ids'] = '[]'
return analytics_dict

def _save_or_update(self, context, package_type=None):
data_dict = {}
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

{% import 'macros/form.html' as form %}

{# The line below is for google analytics #}
{% block analytics_org_name %}{{ data.get('organization',{}).name }}{% endblock %}
{% block analytics_org_id %}{{ data.get('organization',{}).id }}{% endblock %}
{% block analytics_is_cod %}{{ analytics.is_cod }}{% endblock %}
{% block analytics_is_indicator %}{{ analytics.is_indicator }}{% endblock %}
{% block analytics_group_names %}{{ analytics.group_names | safe }}{% endblock %}
{% block analytics_group_ids %}{{ analytics.group_ids | safe }}{% endblock %}
{% block analytics_dataset_name %}{{ data.name }}{% endblock %}
{% block analytics_dataset_id %}{{ data.id }}{% endblock %}

{% block subtitle %}{{ _('Contribute') }}{% endblock %}

{% set edit_mode = True if data else False %}
{% set data = data if data else h.generate_mandatory_fields() %}
{% set errors = {} %}
{% set test_options = [{},{'value':'test', 'text':'Test'}, {'value':'test2', 'text':'Test2'}] %}

{% set user_is_sysadmin = h.check_access('sysadmin') %}

{% set form_title = _('Edit Details') if edit_mode else _('Add Details') %}
Expand Down

0 comments on commit 3252ffa

Please sign in to comment.