Ejemplo n.º 1
0
def single_popular_dataset_html(top=20):
    dataset_dict = single_popular_dataset(top)
    groups = package.get("groups", [])
    publishers = [g for g in groups if g.get("type") == "organization"]
    publisher = publishers[0] if publishers else {"name": "", "title": ""}
    context = {"dataset": dataset_dict, "publisher": publisher_dict}
    return base.render_snippet("ga_report/ga_popular_single.html", **context)
Ejemplo n.º 2
0
def single_popular_dataset_html(top=20):
    dataset_dict = single_popular_dataset(top)
    groups = package.get('groups', [])
    publishers = [g for g in groups if g.get('type') == 'organization']
    publisher = publishers[0] if publishers else {'name': '', 'title': ''}
    context = {'dataset': dataset_dict, 'publisher': publisher_dict}
    return base.render_snippet('ga_report/ga_popular_single.html', **context)
Ejemplo n.º 3
0
def render_snippet(template: str, data: Optional[dict[str, Any]] = None):
    """Render a template snippet and return the output.

    See :doc:`/theming/index`.

    """
    data = data or {}
    return base.render_snippet(template, **data)
Ejemplo n.º 4
0
def render_snippet(template, data=None):
    """Render a template snippet and return the output.

    See :doc:`/theming/index`.

    """
    data = data or {}
    return base.render_snippet(template, **data)
Ejemplo n.º 5
0
def stats_for_resource(resource_id):
    stats = get_stats_for_resource(resource_id)
    #if no stats from db, give '0' counts
    if not stats:
        stats = {'visits': 0, 'downloads': 0}
    return base.render_snippet('piwik_snippets/resource_stats.html',
                               visits=stats['visits'],
                               downloads=stats['downloads'])
Ejemplo n.º 6
0
def render_form_snippet(name, data=None, extra_args=None, **kwargs):
    field = {"field_name": "test", "label": "Test"}
    field.update(kwargs)
    with mock_pylons_request():
        return render_snippet("scheming/form_snippets/" + name,
                              field=field,
                              data=data or {},
                              errors=None,
                              **(extra_args or {}))
Ejemplo n.º 7
0
def stats_for_resource(resource_id):
    stats = get_stats_for_resource(resource_id)

    #if no stats from db, give '0' counts
    if not stats:
        stats = {'visits': 0, 'downloads': 0}

    return base.render_snippet('piwik_snippets/resource_stats.html',
                               visits=stats['visits'],
                               downloads=stats['downloads'])
Ejemplo n.º 8
0
def single_popular_dataset_html(top=100):
    dataset_dict = single_popular_dataset(top)
    groups = package.get('groups', [])
    publishers = [ g for g in groups if g.get('type') == 'organization' ]
    publisher = publishers[0] if publishers else {'name':'', 'title': ''}
    context = {
        'dataset': dataset_dict,
        'publisher': publisher_dict
        }
    return base.render_snippet('ga_report/ga_popular_single.html', **context)
Ejemplo n.º 9
0
def stats_for_package(package_name):
    stats = get_stats_for_package(package_name)

    #if no stats from db, give '0' counts
    if not stats:
        stats = {'total': 0, 'recent': 0}
    return base.render_snippet('piwik_snippets/piwik_stats.html',
                               total=stats['total'],
                               recent=stats['recent'],
                               recent_days=recent_days())
Ejemplo n.º 10
0
def caeser_ffff(arg1, arg_package, arg_id, arg_name):
    # temp_s = "/dataset"
    # temp_index = arg1.index(temp_s)
    # temp_index = temp_index + 9
    # final_s = arg1[temp_index:]
    return base.render_snippet('snippets/add_button.html',
                               package_name=arg1,
                               pack_id=arg_id,
                               pack_r_id=arg_package,
                               user_name=arg_name)
Ejemplo n.º 11
0
def stats_for_package(package_name):
    stats = get_stats_for_package(package_name)

    #if no stats from db, give '0' counts
    if not stats:
        stats = {'total': 0, 'recent': 0}

    return base.render_snippet('piwik_snippets/piwik_stats.html',
                               total=stats['total'],
                               recent=stats['recent'],
                               recent_days=recent_days())
Ejemplo n.º 12
0
def most_popular_datasets(publisher, count=20, preview_image=None):

    if not publisher:
        _log.error("No valid publisher passed to 'most_popular_datasets'")
        return ""

    results = _datasets_for_publisher(publisher, count)

    ctx = {"dataset_count": len(results), "datasets": results, "publisher": publisher, "preview_image": preview_image}

    return base.render_snippet("ga_report/publisher/popular.html", **ctx)
Ejemplo n.º 13
0
def render_form_snippet(name, data=None, extra_args=None, **kwargs):
    field = {
        'field_name': 'test',
        'label': 'Test',
    }
    field.update(kwargs)
    with mock_pylons_request():
        return render_snippet('scheming/form_snippets/' + name,
                              field=field,
                              data=data or {},
                              errors=None,
                              **(extra_args or {}))
def render_form_snippet(name, data=None, extra_args=None, **kwargs):
    field = {
        'field_name': 'test',
        'label': 'Test',
    }
    field.update(kwargs)
    with mock_pylons_request():
        return render_snippet(
            'scheming/form_snippets/' + name,
            field=field,
            data=data or {},
            errors=None,
            **(extra_args or {}))
Ejemplo n.º 15
0
def most_popular_datasets(publisher, count=20, preview_image=None):

    if not publisher:
        _log.error("No valid publisher passed to 'most_popular_datasets'")
        return ""

    results = _datasets_for_publisher(publisher, count)

    ctx = {
        'dataset_count': len(results),
        'datasets': results,
        'publisher': publisher,
        'preview_image': preview_image
    }

    return base.render_snippet('ga_report/publisher/popular.html', **ctx)
Ejemplo n.º 16
0
def popular_datasets(count=10):
    import random

    publisher = None
    publishers = _get_publishers(30)
    total = len(publishers)
    while not publisher or not datasets:
        rand = random.randrange(0, total)
        publisher = publishers[rand][0]
        if not publisher.state == "active":
            publisher = None
            continue
        datasets = _datasets_for_publisher(publisher, 10)[:count]

    ctx = {"datasets": datasets, "publisher": publisher}
    return base.render_snippet("ga_report/ga_popular_datasets.html", **ctx)
Ejemplo n.º 17
0
def popular_datasets(count=10):
    import random

    publisher = None
    publishers = _get_publishers(30)
    total = len(publishers)
    while not publisher or not datasets:
        rand = random.randrange(0, total)
        publisher = publishers[rand][0]
        if not publisher.state == 'active':
            publisher = None
            continue
        datasets = _datasets_for_publisher(publisher, 10)[:count]

    ctx = {'datasets': datasets, 'publisher': publisher}
    return base.render_snippet('ga_report/ga_popular_datasets.html', **ctx)
Ejemplo n.º 18
0
def most_popular_datasets(publisher, count=100, preview_image=None):

    if not publisher:
        _log.error("No valid publisher passed to 'most_popular_datasets'")
        return ""

    results = _datasets_for_publisher(publisher, count)

    ctx = {
        'dataset_count': len(results),
        'datasets': results,

        'publisher': publisher,
        'preview_image': preview_image
    }

    return base.render_snippet('ga_report/publisher/popular.html', **ctx)
Ejemplo n.º 19
0
def tracking_info(data_obj):
    """
    Helper to render a snippet
    """
    #print data_obj
    total = -1
    recent = -1
    if 'tracking_summary' in data_obj:
        tracking_summary = data_obj['tracking_summary']
        if 'total' in tracking_summary:
            total = tracking_summary['total']
        if 'recent' in tracking_summary:
            recent = tracking_summary['recent']
    else:
        if 'views_total' in data_obj:
            total = data_obj['views_total']
        if 'views_recent' in data_obj:
            recent = data_obj['views_recent']
    return base.render_snippet('tracking.html', total=total, recent=recent)
Ejemplo n.º 20
0
 def _call(cls, args, kwargs):
     return base.render_snippet(*args, **kwargs)
Ejemplo n.º 21
0
    def test_restricted_string_snippet(self):
        """
        """
        sysadmin = factories.Sysadmin()
        org = factories.Organization(
            users=[{'name': sysadmin['id'], 'capacity': 'admin'}]
        )
        dataset = factories.Dataset(owner_org=org['id'])

        restricted1 = """{
            "level": "restricted",
            "allowed_organizations": "fjelltopp,unaids,fjelltopp",
            "allowed_users":""
        }"""
        resource1 = factories.Resource(
            package_id=dataset['id'],
            restricted=restricted1
        )

        restricted2 = """{
            "level": "restricted",
            "allowed_organizations": "",
            "allowed_users":"test_user_0,test_user_1"
        }"""
        resource2 = factories.Resource(
            package_id=dataset['id'],
            restricted=restricted2
        )

        restricted3 = """{
            "level": "restricted",
            "allowed_organizations": "fjelltopp,unaids,fjelltopp",
            "allowed_users":"test_user_0,test_user_1"
        }"""
        resource3 = factories.Resource(
            package_id=dataset['id'],
            restricted=restricted3
        )

        restricted4 = """{
            "level": "restricted",
            "allowed_organizations": "",
            "allowed_users":""
        }"""
        resource4 = factories.Resource(
            package_id=dataset['id'],
            restricted=restricted4
        )

        html1 = render_snippet(
            'restricted/restricted_string.html',
            res=resource1,
            pkg=dataset
        )
        log.debug(pformat(html1))
        expected = (
            "Access restricted to specific <a href='#' data-module"
            "='restricted_popup' data-module-title='Access granted to "
            "organizations' data-module-content='fjelltopp<br />unaids"
            "<br />" + org['name'] + "'>organizations</a>"
        )
        assert expected in html1

        html2 = render_snippet(
            'restricted/restricted_string.html',
            res=resource2,
            pkg=dataset
        )
        log.debug(pformat(html2))
        expected = (
            "Access restricted to specific <a href='#' "
            "data-module='restricted_popup' data-module-title='Access "
            "granted to users' data-module-content='test_user_0<br />"
            "test_user_1'>users</a>"
        )
        assert expected in html2

        html3 = render_snippet(
            'restricted/restricted_string.html',
            res=resource3,
            pkg=dataset
        )
        log.debug(pformat(html3))
        expected = (
            "Access restricted to specific <a href='#' "
            "data-module='restricted_popup' data-module-title='Access "
            "granted to organizations' data-module-content='fjelltopp<br />"
            "unaids<br />" + org['name'] + "'>organizations</a> and "
            "<a href='#' data-module='restricted_popup' "
            "data-module-title='Access granted to users' "
            "data-module-content='test_user_0<br />test_user_1'>users</a>."
        )
        assert expected in html3

        html4 = render_snippet(
            'restricted/restricted_string.html',
            res=resource4,
            pkg=dataset
        )
        log.debug(pformat(html4))
        expected = (
            'Access restricted to members of <a href="/organization/'
            '{}">{}</a>'.format(org['name'], org['title'])
        )
        assert expected in html4
Ejemplo n.º 22
0
 def _call(cls, args, kwargs):
     return base.render_snippet(*args, **kwargs)
Ejemplo n.º 23
0
 def _call(cls, args, kwargs):
     assert len(args) == 1
     return base.render_snippet(args[0], **kwargs)
Ejemplo n.º 24
0
Archivo: helpers.py Proyecto: HHS/ckan
def snippet(template_name, **kw):
    ''' This function is used to load html snippets into pages. keywords
    can be used to pass parameters into the snippet rendering '''
    import ckan.lib.base as base
    return base.render_snippet(template_name, **kw)
Ejemplo n.º 25
0
def snippet(template_name, **kw):
    ''' This function is used to load html snippets into pages. keywords
    can be used to pass parameters into the snippet rendering '''
    import ckan.lib.base as base
    return base.render_snippet(template_name, **kw)
Ejemplo n.º 26
0
 def _call(cls, args: Iterable[Any], kwargs: dict[str, Any]):
     return base.render_snippet(*args, **kwargs)
Ejemplo n.º 27
0
def tracking_info(data_obj):
    return base.render_snippet('tracking.html', total=data_obj['tracking_summary']['total'], recent=data_obj['tracking_summary']['recent'])
Ejemplo n.º 28
0
def caeser_check_if_add():
    return base.render_snippet('snippets/add_button.html')
Ejemplo n.º 29
0
 def _call(cls, args, kwargs):
     assert len(args) == 1
     return base.render_snippet(args[0], **kwargs)
Ejemplo n.º 30
0
                if len(output) >= organisations_limit:
                    break
        brokenlinks_count = sum(
            organisation.get('deadLinks', 0) for organisation in organisations)
        log.info(
            'Broken links for loop took {0}s ({1} deadLinks fetched)'.format(
                time.time() - start, brokenlinks_count))
        start = time.time()
        reordered_org = sorted(output, key=lambda k: k['name'])
        log.info('Broken links reordered result took {0}s'.format(time.time() -
                                                                  start))

        noBrokenLinks_val = (offset == 0 and len(output) == 0)

        return base.render_snippet(
            'organization/snippets/broken_links_list.html',
            organizations=reordered_org,
            noBrokenLinks=noBrokenLinks_val)


def _get_organisation_datasets(context, owner):
    """
    Get the list of datasets from an organisation.
    :param owner: The organisation's identifier "owner_org" related to the excepted datasets.
    :return: list of datasets related to the organisation.
    """
    dead_links = {}
    try:
        publisher = model.Group.get(owner)
        publisher_uri = uri_util.create_publisher_uri(publisher.name)
        dead_links = get_organisation_broken_links(publisher_uri)
    except Exception, e: