@@ -40,7 +40,6 @@ def post(self) -> Union[str, Response]:
40
40
try :
41
41
req = request .form .copy ()
42
42
req .update (request .files .to_dict ())
43
- log .debug (req )
44
43
data_dict = logic .clean_dict (
45
44
dict_fns .unflatten (
46
45
logic .tuplize_dict (
@@ -57,25 +56,35 @@ def post(self) -> Union[str, Response]:
57
56
del data_dict ["save" ]
58
57
59
58
# 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."
63
62
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" )
65
66
upload .update_data_dict (
66
67
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 " ,
70
71
)
71
72
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
74
75
if value and not value .startswith ('http' ) and not value .startswith ('/' ):
75
76
image_path = 'uploads/admin/'
76
77
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"
79
88
data = logic .get_action ("config_option_update" )(
80
89
{"user" : current_user .name }, data_dict
81
90
)
0 commit comments