[Python] Get a limit of organizations on the screen (CKAN)

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I'm developing a theme on CKAN (inspired by https://data.gov.sg/) and I'm trying to display my organizations in cards at my index.html (see image and don't mind design errors :p) image of cards

    I've written a controller that's returning the datasets on the screen succesfully but not the organizations. I'll display the codes here and appreciate if you could help me!

    home.py (controller):

    import ckan.lib.base as base
    from pylons import c

    class HomeController(base.BaseController):
    def index(self):
    context = {'ignore_auth': True}

    datasets = toolkit.get_action('package_search')(context, {'rows': 6})['results']

    organizations = toolkit.get_action('organization_list')(context, {
    'all_fields': True,
    'include_dataset_count': True,
    'limit': 100
    })


    return base.render('home/index.html', extra_vars={
    'datasets': datasets,
    'organizations': organizations
    })


    dataset block being called at index.html

    {% block dataset_container %}

    <div class="textos-div">
    <h2 class="text-center text-md-center texto-h2">
    <strong>5.0K+</strong> <span class="span-titulo">datasets from</span> <strong>70</strong> <span class="span-titulo">government agencies</span>
    </h2>
    </div>

    <div class="container my-5">
    <!-- ORGANIZAÇÕES -->
    <h3 class="mb-3">Organizations</h3>
    <div class="row g-4">
    {% for org in organizations %}
    <div class="col-12 col-md-4">
    <a href="{{ h.url_for('organization.read', id=org.name) }}" class="card border-1 rounded-4 p-3 h-100 text-decoration-none">
    {% if org.image_display_url %}
    <img src="{{ org.image_display_url }}" alt="capa da organização">
    {% endif %}
    <p class="titulo-dataset m-0">{{ org.title }}</p>
    <p class="text-muted small">{{ org.description[:100] }}{% if org.description|length > 100 %}...{% endif %}</p>
    </a>
    </div>
    {% endfor %}
    </div>

    <!-- DATASETS -->
    <h3 class="mt-5 mb-3">Latest Datasets</h3>
    <div class="row g-4">
    {% for dataset in c.datasets %}
    <div class="col-12 col-md-4">
    <a href="{{ h.url_for('dataset.read', id=dataset.name) }}" class="card border-1 rounded-4 p-3 h-100 text-decoration-none">
    {% if dataset.organization and dataset.organization.image_url %}
    <img src="{{ h.url_for_static('/uploads/group/' ~ dataset.organization.image_url) }}" alt="{{ dataset.organization.title }}" class="mb-2" style="max-height: 30px;">
    {% endif %}
    <p class="titulo-dataset m-0">{{ dataset.title }}</p>
    <p class="text-muted small">{{ dataset.notes[:100] }}{% if dataset.notes|length > 100 %}...{% endif %}</p>
    <p class="text-muted small">1.2M API CALLS • 4.5K DOWNLOADS</p>
    </a>
    </div>
    {% endfor %}
    </div>

    <div class="text-center mt-4">
    <a href="{{ h.url_for('dataset.search') }}" class="text-decoration-none fw-semibold link-dataset">
    View all datasets <i class="fa-solid fa-arrow-right ms-1"></i>
    </a>
    </div>
    </div>

    {% endblock %}



    plugin.py :

    import ckan.plugins as plugins
    import ckan.plugins.toolkit as toolkit


    # import ckanext.almavivasolutionss.cli as cli
    # import ckanext.almavivasolutionss.helpers as helpers
    # import ckanext.almavivasolutionss.views as views
    # from ckanext.almavivasolutionss.logic import (
    # action, auth, validators
    # )


    class AlmavivasolutionssPlugin(plugins.SingletonPlugin):
    plugins.implements(plugins.IConfigurer)

    # plugins.implements(plugins.IAuthFunctions)
    # plugins.implements(plugins.IActions)
    # plugins.implements(plugins.IBlueprint)
    # plugins.implements(plugins.IClick)
    # plugins.implements(plugins.ITemplateHelpers)
    # plugins.implements(plugins.IValidators)


    # IConfigurer

    def update_config(self, config_):
    toolkit.add_template_directory(config_, "templates")
    toolkit.add_public_directory(config_, "public")
    toolkit.add_resource("assets", "almavivasolutionss")

    def before_map(self, map):
    from ckan.config.routing import SubMapper
    controller = 'ckanext.almavivasolutionss.controllers.home:HomeController'

    with SubMapper(map, controller=controller) as m:
    m.connect('/', action='index')

    return map


    # IAuthFunctions

    # def get_auth_functions(self):
    # return auth.get_auth_functions()

    # IActions

    # def get_actions(self):
    # return action.get_actions()

    # IBlueprint

    # def get_blueprint(self):
    # return views.get_blueprints()

    # IClick

    # def get_commands(self):
    # return cli.get_commands()

    # ITemplateHelpers

    # def get_helpers(self):
    # return helpers.get_helpers()

    # IValidators

    # def get_validators(self):
    # return validators.get_validators()




    Am I missing something? I've tried debuggind and different codes at home.py but nothing worked out. I'm learning CKAN now so I'm not an expert

    Thank you in advance!

    Continue reading...

Compartilhe esta Página