|
1 | 1 | import logging
|
| 2 | +from typing import Any |
2 | 3 |
|
3 | 4 | import ckan.plugins.toolkit as tk
|
4 |
| -from ckan.common import _, c, request |
| 5 | +from ckan.common import _, current_user, request |
5 | 6 | from ckan.lib.base import render
|
| 7 | +from ckan.types import Context |
6 | 8 | from flask import Blueprint
|
7 | 9 |
|
8 | 10 | from ckanext.harvester_dashboard.helpers import harvester_dashboard_organization_title
|
|
29 | 31 |
|
30 | 32 |
|
31 | 33 | 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 | + } |
37 | 38 | harvest_source_list = tk.get_action("get_harvest_source_infos_for_user")(
|
38 | 39 | 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 | + } |
43 | 51 | harvest_source_list = list(
|
44 | 52 | filter(
|
45 | 53 | lambda harvest_source_info: _source_type_test(
|
46 |
| - harvest_source_info, c.source_type |
| 54 | + harvest_source_info, extra_vars["source_type"] |
47 | 55 | ),
|
48 | 56 | harvest_source_list,
|
49 | 57 | )
|
50 | 58 | )
|
51 | 59 | harvest_source_list = list(
|
52 | 60 | filter(
|
53 | 61 | lambda harvest_source_info: _job_result_test(
|
54 |
| - harvest_source_info, c.job_result |
| 62 | + harvest_source_info, extra_vars["job_result"] |
55 | 63 | ),
|
56 | 64 | harvest_source_list,
|
57 | 65 | )
|
58 | 66 | )
|
59 | 67 | harvest_source_list = list(
|
60 | 68 | 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 | + ), |
62 | 72 | harvest_source_list,
|
63 | 73 | )
|
64 | 74 | )
|
65 |
| - if c.q: |
| 75 | + if extra_vars.get("q"): |
66 | 76 | harvest_source_list = list(
|
67 | 77 | 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 | + ), |
69 | 81 | harvest_source_list,
|
70 | 82 | )
|
71 | 83 | )
|
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) |
74 | 87 |
|
75 | 88 |
|
76 | 89 | def _source_type_test(harvest_source_info, source_type):
|
|
0 commit comments