def test_cached_get_group_package_stuff(self):
        global num_filter_focus_countries

        # calling the function to make sure it's cached
        caching.cached_get_group_package_stuff()
        # resetting counter
        num_filter_focus_countries = 0

        # the result should have been cached so filter_focus_countries should not be called
        caching.cached_get_group_package_stuff()
        assert (
            num_filter_focus_countries == 0
        ), "number of calls to filter_focus_countries should be 0 , instead {num}".format(
            num=num_filter_focus_countries
        )

        caching.invalidate_group_caches()
        # the result should have been removed from cache so filter_focus_countries should be called
        caching.cached_get_group_package_stuff()
        assert (
            num_filter_focus_countries == 1
        ), "number of calls to filter_focus_countries should be 1 , instead {num}".format(
            num=num_filter_focus_countries
        )

        # the result should have been cached so the num of calls to filter_focus_countries shouldn't increase
        caching.cached_get_group_package_stuff()
        assert (
            num_filter_focus_countries == 1
        ), "number of calls to filter_focus_countries should be 1 , instead {num}".format(
            num=num_filter_focus_countries
        )
Example #2
0
    def index(self):
        group_type = None
        context = {'model': model, 'session': model.Session,
                   'user': c.user or c.author, 'for_view': True,
                   'with_private': False}

        q = c.q = request.params.get('q', '')
        data_dict = {'all_fields': True, 'q': q}
        sort_by = c.sort_by_selected = request.params.get('sort')
        if sort_by:
            data_dict['sort'] = sort_by
        try:
            self._check_access('site_read', context)
        except NotAuthorized:
            abort(401, _('Not authorized to see this page'))
        if c.userobj:
            context['user_id'] = c.userobj.id
            context['user_is_admin'] = c.userobj.sysadmin



        c.group_package_stuff = caching.cached_get_group_package_stuff()

        ##Removing groups without geojson for the map
        c.group_map = []
        for gp in c.group_package_stuff:
            '''
                Removed check for geojson data because in the new version this information 
                does not come from the group_list action and for now we are not using the map.
                If we'll need this we should implement some caching functionality for this too.
            '''
            c.group_map.append(gp)

        #print c.group_package_stuff

        if c.userobj is not None:
            msg = None
            url = h.url_for(controller='user', action='edit')
            is_google_id = \
                c.userobj.name.startswith('https://www.google.com/accounts/o8/id')
            if not c.userobj.email and (is_google_id and not c.userobj.fullname):
                msg = _(u'Please <a href="{link}">update your profile</a>'
                        u' and add your email address and your full name. '
                        u'{site} uses your email address'
                        u' if you need to reset your password.'.format(
                            link=url, site=g.site_title))
            elif not c.userobj.email:
                msg = _('Please <a href="%s">update your profile</a>'
                        ' and add your email address. ') % url + \
                    _('%s uses your email address'
                        ' if you need to reset your password.') \
                    % g.site_title
            elif is_google_id and not c.userobj.fullname:
                msg = _('Please <a href="%s">update your profile</a>'
                        ' and add your full name.') % (url)
            if msg:
                h.flash_notice(msg, allow_html=True)

        return base.render('home/index.html', cache_force=True)
Example #3
0
    def index(self):
        group_type = None
        context = {
            'model': model,
            'session': model.Session,
            'user': c.user or c.author,
            'for_view': True,
            'with_private': False
        }

        q = c.q = request.params.get('q', '')
        data_dict = {'all_fields': True, 'q': q}
        sort_by = c.sort_by_selected = request.params.get('sort')
        if sort_by:
            data_dict['sort'] = sort_by
        try:
            self._check_access('site_read', context)
        except NotAuthorized:
            abort(401, _('Not authorized to see this page'))
        if c.userobj:
            context['user_id'] = c.userobj.id
            context['user_is_admin'] = c.userobj.sysadmin

        c.group_package_stuff = caching.cached_get_group_package_stuff()

        ##Removing groups without geojson for the map
        c.group_map = []
        for gp in c.group_package_stuff:
            '''
                Removed check for geojson data because in the new version this information 
                does not come from the group_list action and for now we are not using the map.
                If we'll need this we should implement some caching functionality for this too.
            '''
            c.group_map.append(gp)

        # print c.group_package_stuff

        if c.userobj is not None:
            site_title = config.get('ckan.site_title', 'CKAN')
            msg = None
            url = h.url_for(controller='user', action='edit')
            is_google_id = \
                c.userobj.name.startswith('https://www.google.com/accounts/o8/id')
            if not c.userobj.email and (is_google_id
                                        and not c.userobj.fullname):
                msg = _(u'Please <a href="{link}">update your profile</a>'
                        u' and add your email address and your full name. '
                        u'{site} uses your email address'
                        u' if you need to reset your password.'.format(
                            link=url, site=site_title))
            elif not c.userobj.email:
                msg = _('Please <a href="%s">update your profile</a>'
                        ' and add your email address. ') % url + \
                      _('%s uses your email address'
                        ' if you need to reset your password.') \
                      % site_title
            elif is_google_id and not c.userobj.fullname:
                msg = _('Please <a href="%s">update your profile</a>'
                        ' and add your full name.') % (url)
            if msg:
                h.flash_notice(msg, allow_html=True)

        # template_data = {
        #     'data': {
        #         'hdx.carousel.config': logic.get_action('hdx_carousel_settings_show')({}, {})
        #     }
        # }

        return base.render('home/index.html', cache_force=True)
Example #4
0
def run_on_startup():
    cache_on_startup = config.get('hdx.cache.onstartup', 'true')
    if 'true' == cache_on_startup:
        _generate_license_list()
        caching.cached_get_group_package_stuff()