Skip to content

Commit 97882fa

Browse files
author
Thomas Hanke
committed
removed dark_model config in admin form, some kind of value change in config causes dark mode to enable even when disabled in config file
1 parent 3549118 commit 97882fa

File tree

3 files changed

+43
-38
lines changed

3 files changed

+43
-38
lines changed

ckanext/matolabtheme/plugin.py

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from ckan.lib.plugins import DefaultTranslation
66

77

8+
log = __import__("logging").getLogger(__name__)
9+
10+
11+
812
class MatolabthemePlugin(plugins.SingletonPlugin, DefaultTranslation):
913
plugins.implements(plugins.IConfigurer)
1014
plugins.implements(plugins.IConfigDeclaration)
@@ -21,18 +25,49 @@ def update_config(self, config_):
2125
toolkit.add_public_directory(config_, "public")
2226
toolkit.add_resource("assets", "matolabtheme")
2327

28+
# IConfigDeclaration
29+
30+
def declare_config_options(self, declaration: Declaration, key: Key):
31+
32+
declaration.annotate("matolabtheme")
33+
group = key.ckanext.matolabtheme
34+
declaration.declare(group.contact_url, "https://github.com/Mat-O-Lab")
35+
declaration.declare(
36+
group.legal_person_md, "legal person name, street number, Zip city, country"
37+
)
38+
declaration.declare(
39+
group.contact_dp_commissioner_email_md,
40+
"[[email protected]](mailto:[email protected]?subject=dataprotection CKAN)",
41+
)
42+
declaration.declare(
43+
group.dsvgo_contact_md,
44+
"legal person name, street number, Zip city, country",
45+
)
46+
option=declaration.declare_bool(group.dark_mode, False)
47+
option.set_validators("not_missing boolean_validator")
48+
declaration.declare(group.banner_top, "/static/banner_top.png")
49+
declaration.declare(group.banner_top_upload, "")
50+
declaration.declare(group.clear_banner_top_upload, "")
51+
declaration.declare(group.banner_bottom, "/static/banner_bottom.png")
52+
declaration.declare(group.banner_bottom_upload, "")
53+
declaration.declare(group.clear_banner_bottom_upload, "")
54+
declaration.declare(group.attribution_logo, "/static/favicon.png")
55+
declaration.declare(group.attribution_logo_upload, "")
56+
declaration.declare(group.clear_attribution_logo_upload, "")
57+
2458
def update_config_schema(self, schema):
2559

2660
ignore_missing = toolkit.get_validator("ignore_missing")
61+
bool_val = toolkit.get_validator("boolean_validator")
2762
unicode_safe = toolkit.get_validator("unicode_safe")
28-
63+
dark_mode=toolkit.config.get("ckanext.matolabtheme.dark_mode")
2964
schema.update(
3065
{
3166
# This is an existing CKAN core configuration option, we are just
3267
# making it available to be editable at runtime
33-
"ckanext.matolabtheme.dark_mode": [
34-
ignore_missing,
35-
],
68+
# "ckanext.matolabtheme.dark_mode": [
69+
# ignore_missing, bool_val
70+
# ],
3671
"ckanext.matolabtheme.banner_top": [
3772
ignore_missing,
3873
unicode_safe,
@@ -71,38 +106,9 @@ def update_config_schema(self, schema):
71106
],
72107
}
73108
)
74-
75109
return schema
76110

77-
# IConfigDeclaration
78-
79-
def declare_config_options(self, declaration: Declaration, key: Key):
80-
81-
declaration.annotate("matolabtheme")
82-
group = key.ckanext.matolabtheme
83-
declaration.declare(group.contact_url, "https://github.com/Mat-O-Lab")
84-
declaration.declare(
85-
group.legal_person_md, "legal person name, street number, Zip city, country"
86-
)
87-
declaration.declare(
88-
group.contact_dp_commissioner_email_md,
89-
"[[email protected]](mailto:[email protected]?subject=dataprotection CKAN)",
90-
)
91-
declaration.declare(
92-
group.dsvgo_contact_md,
93-
"legal person name, street number, Zip city, country",
94-
)
95-
declaration.declare_bool(group.dark_mode, False)
96-
declaration.declare(group.banner_top, "/static/banner_top.png")
97-
declaration.declare(group.banner_top_upload, "")
98-
declaration.declare(group.clear_banner_top_upload, "")
99-
declaration.declare(group.banner_bottom, "/static/banner_bottom.png")
100-
declaration.declare(group.banner_bottom_upload, "")
101-
declaration.declare(group.clear_banner_bottom_upload, "")
102-
declaration.declare(group.attribution_logo, "/static/favicon.png")
103-
declaration.declare(group.attribution_logo_upload, "")
104-
declaration.declare(group.clear_attribution_logo_upload, "")
105-
111+
106112
# ITemplateHelpers
107113

108114
def get_helpers(self):

ckanext/matolabtheme/templates/matolabtheme/theme_config.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{% block admin_form %}
1414
{{ h.csrf_input() }}
1515
<!-- Dark Mode Toggle Switch -->
16-
{{ form.checkbox('ckanext.matolabtheme.dark_mode', id='field-matolabthem-darkmode', label= _('Enable Dark Mode'), checked=((true if data['ckanext.matolabtheme.dark_mode'] else false)), error=error, classes=['control-medium']) }}
16+
<!-- {{ form.checkbox('ckanext.matolabtheme.dark_mode', id='field-matolabthem-darkmode', label= _('Enable Dark Mode'), checked=((true if data['ckanext.matolabtheme.dark_mode'] else false)), error=error, classes=['control-medium']) }} -->
1717

1818
{% set field1_url = 'ckanext.matolabtheme.banner_top' %}
1919
{% set is_upload = data[field1_url] and not data[field1_url].startswith('http') %}

ckanext/matolabtheme/views.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ def post(self) -> Union[str, Response]:
4949
)
5050
)
5151
)
52+
dark_mode=toolkit.config.get("ckanext.matolabtheme.dark_mode")
5253
# Set dark_mode based on whether the checkbox was checked
5354
data_dict['ckanext.matolabtheme.dark_mode'] = 'ckanext.matolabtheme.dark_mode' in req
5455
del data_dict["save"]
5556
# data = logic.get_action("config_option_update")(
5657
# {"user": current_user.name}, data_dict
5758
# )
58-
log.debug(data_dict)
5959
# Handle banner uploads AFTER calling CKAN’s function
6060
upload = uploader.get_uploader("admin")
6161
for key in list(data_dict.keys()):
@@ -103,7 +103,6 @@ def post(self) -> Union[str, Response]:
103103
model.set_system_info(key, value)
104104
config[key] = value
105105
elif key == "ckanext.matolabtheme.dark_mode":
106-
log.debug(f"dark_mode: {data_dict[key]}")
107106
value = data_dict[key]
108107
model.set_system_info(key, value)
109108
config[key] = value
@@ -114,7 +113,6 @@ def post(self) -> Union[str, Response]:
114113
error_summary = e.error_summary
115114
vars = dict(data=data, errors=errors, error_summary=error_summary)
116115
return base.render("matolabtheme/theme_config.html", extra_vars=vars)
117-
118116
return h.redirect_to("matolabtheme.theme_config")
119117

120118
def get(self) -> str:
@@ -126,6 +124,7 @@ def get(self) -> str:
126124
logic.check_access("sysadmin", context)
127125
except logic.NotAuthorized:
128126
base.abort(403, _("Need to be system administrator to administer"))
127+
dark_mode=toolkit.config.get("ckanext.matolabtheme.dark_mode")
129128
schema = ckan.logic.schema.update_configuration_schema()
130129
data = {}
131130
for key in schema:

0 commit comments

Comments
 (0)