Skip to content

Commit dfda5fb

Browse files
committed
refactor: pass variables to designated dict instead of using c-object
1 parent 8a9a15b commit dfda5fb

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed

ckanext/harvester_dashboard/blueprints/dashboard.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import logging
2+
from typing import Any
23

34
import ckan.plugins.toolkit as tk
4-
from ckan.common import _, c, request
5+
from ckan.common import _, current_user, request
56
from ckan.lib.base import render
7+
from ckan.types import Context
68
from flask import Blueprint
79

810
from ckanext.harvester_dashboard.helpers import harvester_dashboard_organization_title
@@ -29,48 +31,59 @@
2931

3032

3133
def dashboard():
32-
c.q = request.params.get("q", "")
33-
c.source_type = request.params.get("source_type", RESULT_ALL)
34-
c.job_result = request.params.get("job_result", RESULT_ALL)
35-
c.job_run = request.params.get("job_run", RESULT_ALL)
36-
context = {"user": c.user, "auth_user_obj": c.userobj}
34+
context: Context = {
35+
"user": current_user.name,
36+
"auth_user_obj": current_user,
37+
}
3738
harvest_source_list = tk.get_action("get_harvest_source_infos_for_user")(
3839
context, {}
39-
) # noqa
40-
c.source_type_options = _get_source_type_options(harvest_source_list)
41-
c.job_result_options = RESULT_OPTIONS
42-
c.job_run_options = RUN_OPTIONS
40+
)
41+
extra_vars: dict[str, Any] = {
42+
"q": request.params.get("q", ""),
43+
"source_type": request.params.get("source_type", RESULT_ALL),
44+
"job_result": request.params.get("job_result", RESULT_ALL),
45+
"job_run": request.params.get("job_run", RESULT_ALL),
46+
"source_type_options": _get_source_type_options(harvest_source_list),
47+
"job_result_options": RESULT_OPTIONS,
48+
"job_run_options": RUN_OPTIONS,
49+
"harvest_source_infos": harvest_source_list,
50+
}
4351
harvest_source_list = list(
4452
filter(
4553
lambda harvest_source_info: _source_type_test(
46-
harvest_source_info, c.source_type
54+
harvest_source_info, extra_vars["source_type"]
4755
),
4856
harvest_source_list,
4957
)
5058
)
5159
harvest_source_list = list(
5260
filter(
5361
lambda harvest_source_info: _job_result_test(
54-
harvest_source_info, c.job_result
62+
harvest_source_info, extra_vars["job_result"]
5563
),
5664
harvest_source_list,
5765
)
5866
)
5967
harvest_source_list = list(
6068
filter(
61-
lambda harvest_source_info: _job_run_test(harvest_source_info, c.job_run),
69+
lambda harvest_source_info: _job_run_test(
70+
harvest_source_info, extra_vars["job_run"]
71+
),
6272
harvest_source_list,
6373
)
6474
)
65-
if c.q:
75+
if extra_vars.get("q"):
6676
harvest_source_list = list(
6777
filter(
68-
lambda harvest_source_info: _source_name_test(harvest_source_info, c.q),
78+
lambda harvest_source_info: _source_name_test(
79+
harvest_source_info, extra_vars["q"]
80+
),
6981
harvest_source_list,
7082
)
7183
)
72-
c.harvest_source_infos = harvest_source_list
73-
return render("harvester_dashboard/list.html")
84+
extra_vars["harvest_source_infos"] = harvest_source_list
85+
86+
return render("harvester_dashboard/list.html", extra_vars)
7487

7588

7689
def _source_type_test(harvest_source_info, source_type):

ckanext/harvester_dashboard/templates/harvester_dashboard/list.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
<h1>{{ _('Harvester Dashboard') }}</h1>
1515
<p>Last Harvest Jobs filtered by:</p>
1616
<ul>
17-
<li>Source type: {{ c.source_type }}</li>
18-
<li>Job result: {{ c.job_result }}</li>
19-
<li>Job run status: {{ c.job_run }}</li>
17+
<li>Source type: {{ source_type }}</li>
18+
<li>Job result: {{ job_result }}</li>
19+
<li>Job run status: {{ job_run }}</li>
2020
</ul>
21-
{% for harvest_source_info in c.harvest_source_infos %}
21+
{% for harvest_source_info in harvest_source_infos %}
2222
{% set job = harvest_source_info.job.last_job %}
2323
{% set organization = harvest_source_info.organization %}
2424
{% set source = harvest_source_info.source %}
@@ -52,5 +52,5 @@ <h3><a href="{{ source_url }}">Harvester Name: {{ source.title }}</a></h3>
5252

5353
{% block secondary_content %}
5454
{% snippet 'harvester_dashboard/snippets/helper.html' %}
55-
{% snippet 'harvester_dashboard/snippets/search.html' %}
55+
{% snippet 'harvester_dashboard/snippets/search.html', source_type_options=source_type_options, job_result_options=job_result_options, job_run_options=job_run_options %}
5656
{% endblock %}

ckanext/harvester_dashboard/templates/harvester_dashboard/snippets/search.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% import 'macros/form.html' as form %}
22

33
<section class="module module-narrow module-shallow simple-input">
4-
{{ c.user_roles }}
4+
{{ user_roles }}
55
<h2 class="module-heading">{{ _('Harvesters') }}</h2>
66
<form id="user-search-form"
77
class="module-content field-bordered"
@@ -10,7 +10,7 @@ <h2 class="module-heading">{{ _('Harvesters') }}</h2>
1010
<div class="field">
1111
<label for="field-harvester-search">{{ _('Search Harvesters') }}</label>
1212
<input id="ogdch_user_search"
13-
value="{{ c.q }}"
13+
value="{{ q }}"
1414
class="field form-control"
1515
name="q"
1616
autocomplete="off"
@@ -24,19 +24,19 @@ <h2 class="module-heading">{{ _('Harvesters') }}</h2>
2424
<div class="field">
2525
{% set format_attrs = {'data-module': 'autocomplete'} %}
2626
{{ form.select('source_type', label=_('Harvest Source Type'),
27-
options=c.source_type_options, selected=c.source_type, error='',
27+
options=source_type_options, selected=source_type, error='',
2828
attrs=format_attrs, is_required=false) }}
2929
</div>
3030
<div class="field">
3131
{% set format_attrs = {'data-module': 'autocomplete'} %}
3232
{{ form.select('job_result', label=_('Job Result'),
33-
options=c.job_result_options, selected=c.job_result, error='',
33+
options=job_result_options, selected=job_result, error='',
3434
attrs=format_attrs, is_required=false) }}
3535
</div>
3636
<div class="field">
3737
{% set format_attrs = {'data-module': 'autocomplete'} %}
3838
{{ form.select('job_run', label=_('Job Run'),
39-
options=c.job_run_options, selected=c.job_run, error='',
39+
options=job_run_options, selected=job_run, error='',
4040
attrs=format_attrs, is_required=false) }}
4141
</div>
4242
<div class="reset-search">

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from setuptools import setup, find_packages # Always prefer setuptools over distutils
21
from os import path
32

3+
from setuptools import find_packages, setup # Always prefer setuptools over distutils
4+
45
here = path.abspath(path.dirname(__file__))
56

67

0 commit comments

Comments
 (0)