Beispiel #1
0
def get_ckan(user):
    """ Returns a CKAN instance if configuration contains both a host
    and a key.  If not, returns None
    """
    from runtime_config.logic import get_config
    from ckanapi import RemoteCKAN

    ckan_host = get_config('ckan.host')
    if not (ckan_host and user.apikey):
        return None

    return RemoteCKAN(ckan_host, apikey=user.apikey)
Beispiel #2
0
def _manage_context(request, only_user, view_name):
    q = request.GET.get('q')
    sort = request.GET.get('sort')

    page = 1
    try:
        page = int(request.GET.get('page'))
    except BaseException:
        page = 1

    if sort == 'name':
        sort_name_next = '-name'
        sort_published_next = 'published'
    elif sort == '-name':
        sort_name_next = ''
        sort_published_next = 'published'
    elif sort == 'published':
        sort_name_next = 'name'
        sort_published_next = '-published'
    elif sort == '-published':
        sort_name_next = 'name'
        sort_published_next = ''
    else:
        sort_name_next = 'name'
        sort_published_next = 'published'

    if sort and sort not in ['name', 'published', '-name', '-published']:
        sort = None

    total, page_count, datasets = dataset_list(
        request.user, page, filter_query=q, sort=sort, only_user=only_user
    )

    ckan_host = get_config('ckan.host') or ''

    organisation = request.user.primary_organisation()

    return {
        "current_view": view_name,
        "datasets": datasets,
        "organisation": organisation,
        "total": total,
        "page_range": range(1, page_count + 1),
        "current_page": page,
        "q": q or "",
        "find_url": settings.FIND_URL or ckan_host,
        "sort": sort,
        "qs_name_next": reverse(view_name) +
        _query_string(q, sort_name_next),
        "qs_published_next": reverse(view_name) +
        _query_string(q, sort_published_next)
    }
Beispiel #3
0
 def test_missing(self):
     assert get_config('missing') is None
Beispiel #4
0
 def test_find_inactive(self):
     assert get_config('ckan') is None
Beispiel #5
0
 def test_find_active(self):
     assert get_config('logserver') == 'https://logging'