Skip to content

Commit de77a8c

Browse files
author
Thomas Hanke
committed
fixed the config form again
1 parent 9851bd8 commit de77a8c

File tree

2 files changed

+21
-44
lines changed

2 files changed

+21
-44
lines changed

ckanext/matolabtheme/plugin.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,46 +76,14 @@ def update_config_schema(self, schema):
7676
ignore_missing,
7777
unicode_safe,
7878
],
79-
"ckanext.matolabtheme.banner_top_upload": [
80-
ignore_missing,
81-
unicode_safe,
82-
],
83-
"ckanext.matolabtheme.banner_bottom_upload": [
84-
ignore_missing,
85-
unicode_safe,
86-
],
87-
"ckanext.matolabtheme.clear_banner_top_upload": [
88-
ignore_missing,
89-
unicode_safe,
90-
],
91-
"ckanext.matolabtheme.clear_banner_bottom_upload": [
92-
ignore_missing,
93-
unicode_safe,
94-
],
9579
"ckanext.matolabtheme.favicon": [
9680
ignore_missing,
9781
unicode_safe,
9882
],
99-
"ckanext.matolabtheme.favicon_upload": [
100-
ignore_missing,
101-
unicode_safe,
102-
],
103-
"ckanext.matolabtheme.clear_favicon_upload": [
104-
ignore_missing,
105-
unicode_safe,
106-
],
10783
"ckanext.matolabtheme.attribution_logo": [
10884
ignore_missing,
10985
unicode_safe,
11086
],
111-
"ckanext.matolabtheme.attribution_logo_upload": [
112-
ignore_missing,
113-
unicode_safe,
114-
],
115-
"ckanext.matolabtheme.clear_attribution_logo_upload": [
116-
ignore_missing,
117-
unicode_safe,
118-
],
11987
}
12088
)
12189
return schema

ckanext/matolabtheme/views.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def post(self) -> Union[str, Response]:
4040
try:
4141
req = request.form.copy()
4242
req.update(request.files.to_dict())
43-
log.debug(req)
4443
data_dict = logic.clean_dict(
4544
dict_fns.unflatten(
4645
logic.tuplize_dict(
@@ -57,25 +56,35 @@ def post(self) -> Union[str, Response]:
5756
del data_dict["save"]
5857

5958
# Handle uploads
60-
upload = uploader.get_uploader("admin")
61-
log.debug(data_dict)
62-
upload_fields=["ckanext.matolabtheme.banner_top","ckanext.matolabtheme.banner_bottom", "ckanext.matolabtheme.favicon", "ckanext.matolabtheme.attribution_logo"]
59+
upload_fields=["banner_top","banner_bottom", "favicon", "attribution_logo"]
60+
#upload_fields=["ckanext.matolabtheme.banner_top"]
61+
extention_prefix="ckanext.matolabtheme."
6362
for key in upload_fields:
64-
if key in data_dict.keys():
63+
config_key=extention_prefix+key
64+
if config_key in data_dict.keys():
65+
upload = uploader.get_uploader("admin")
6566
upload.update_data_dict(
6667
data_dict,
67-
key,
68-
key+"_upload",
69-
"ckanext.matolabtheme.clear_banner_top_upload",
68+
config_key,
69+
config_key+"_upload",
70+
extention_prefix+"clear_"+key+"_upload",
7071
)
7172
upload.upload(uploader.get_max_image_size())
72-
value = data_dict[key]
73-
# Set full Logo url
73+
value = data_dict[config_key]
74+
# # Set full Logo url
7475
if value and not value.startswith('http') and not value.startswith('/'):
7576
image_path = 'uploads/admin/'
7677
value = h.url_for_static('{0}{1}'.format(image_path, value))
77-
data_dict[key]=value
78-
log.debug(data_dict)
78+
data_dict[config_key]=value
79+
#set defaults if empty
80+
if "ckanext.matolabtheme.banner_top" in data_dict.keys() and not data_dict["ckanext.matolabtheme.banner_top"]:
81+
data_dict["ckanext.matolabtheme.banner_top"]="/static/banner_top.png"
82+
if "ckanext.matolabtheme.banner_bottom" in data_dict.keys() and not data_dict["ckanext.matolabtheme.banner_bottom"]:
83+
data_dict["ckanext.matolabtheme.banner_bottom"]="/static/banner_bottom.png"
84+
if "ckanext.matolabtheme.favicon" in data_dict.keys() and not data_dict["ckanext.matolabtheme.favicon"]:
85+
data_dict["ckanext.matolabtheme.favicon"]="/static/favicon.png"
86+
if "ckanext.matolabtheme.attribution_logo" in data_dict.keys() and not data_dict["ckanext.matolabtheme.attribution_logo"]:
87+
data_dict["ckanext.matolabtheme.attribution_logo"]="/static/favicon.png"
7988
data = logic.get_action("config_option_update")(
8089
{"user": current_user.name}, data_dict
8190
)

0 commit comments

Comments
 (0)