@@ -1152,16 +1152,14 @@ class NewsletterSettingsForm(Form):
1152
1152
label = _ ('Newsletter categories' ),
1153
1153
description = _ (
1154
1154
'Example for newsletter topics with subtopics in yaml format. '
1155
- 'Note: Deeper structures are not supported.'
1156
- '\n '
1155
+ 'Note: Deeper structures are not supported.\n '
1157
1156
'```\n '
1158
- 'Organisation:\n '
1159
- ' - Topic 1:\n '
1160
- ' - Subtopic 1.1\n '
1161
- ' - Subtopic 1.2\n '
1162
- ' - Topic 2\n '
1163
- ' - Topic 3:\n '
1164
- ' - Subtopic 3.1\n '
1157
+ '- Topic 1\n '
1158
+ '- Topic 2:\n '
1159
+ ' - Subtopic 2.1\n '
1160
+ '- Topic 3:\n '
1161
+ ' - Subtopic 3.1\n '
1162
+ ' - Subtopic 3.2\n '
1165
1163
'```'
1166
1164
),
1167
1165
render_kw = {
@@ -1190,60 +1188,55 @@ def ensure_categories(self) -> bool | None:
1190
1188
return False
1191
1189
1192
1190
if data :
1193
- if not isinstance (data , dict ):
1191
+ if not isinstance (data , list ):
1194
1192
self .newsletter_categories .errors .append (
1195
- _ ('Invalid format. Please define an organisation name '
1193
+ _ ('Invalid format. Please define a list '
1196
1194
'with topics and subtopics according the example.' )
1197
1195
)
1198
1196
return False
1199
- for items in data . values () :
1200
- if not isinstance (items , list ):
1197
+ for item in data :
1198
+ if not isinstance (item , ( str , dict ) ):
1201
1199
self .newsletter_categories .errors .append (
1202
1200
_ ('Invalid format. Please define topics and '
1203
1201
'subtopics according to the example.' )
1204
1202
)
1205
1203
return False
1206
- for item in items :
1207
- if not isinstance (item , (dict , str )):
1204
+
1205
+ if isinstance (item , str ):
1206
+ continue
1207
+
1208
+ for topic , sub_topic in item .items ():
1209
+ if not isinstance (sub_topic , list ):
1208
1210
self .newsletter_categories .errors .append (
1209
- _ ('Invalid format. Please define topics and '
1210
- 'subtopics according to the example.' )
1211
+ _ (f'Invalid format. Please define '
1212
+ f"subtopic(s) for '{ topic } ' "
1213
+ f"or remove the ':'." )
1211
1214
)
1212
1215
return False
1213
1216
1214
- if isinstance (item , dict ):
1215
- for topic , sub_topic in item .items ():
1216
- if not isinstance (sub_topic , list ):
1217
- self .newsletter_categories .errors .append (
1218
- _ (f'Invalid format. Please define '
1219
- f"subtopic(s) for '{ topic } ' "
1220
- f"or remove the ':'." )
1221
- )
1222
- return False
1223
- if not all (isinstance (sub , str )
1224
- for sub in sub_topic ):
1225
- self .newsletter_categories .errors .append (
1226
- _ ('Invalid format. Only topics '
1227
- 'and subtopics are allowed - no '
1228
- 'deeper structures supported.' )
1229
- )
1230
- return False
1217
+ if not all (isinstance (sub , str ) for sub in sub_topic ):
1218
+ self .newsletter_categories .errors .append (
1219
+ _ ('Invalid format. Only topics '
1220
+ 'and subtopics are allowed - no '
1221
+ 'deeper structures supported.' )
1222
+ )
1223
+ return False
1231
1224
1232
1225
return None
1233
1226
1234
1227
def populate_obj (self , model : Organisation ) -> None : # type:ignore
1235
1228
super ().populate_obj (model )
1236
1229
1237
1230
yaml_data = self .newsletter_categories .data
1238
- data = yaml .safe_load (yaml_data ) if yaml_data else {}
1231
+ data = yaml .safe_load (yaml_data ) if yaml_data else []
1239
1232
model .newsletter_categories = data
1240
1233
1241
1234
model .notify_on_unsubscription = self .notify_on_unsubscription .data
1242
1235
1243
1236
def process_obj (self , model : Organisation ) -> None : # type:ignore
1244
1237
super ().process_obj (model )
1245
1238
1246
- categories = model .newsletter_categories or {}
1239
+ categories = model .newsletter_categories or []
1247
1240
if not categories :
1248
1241
self .newsletter_categories .data = ''
1249
1242
return
0 commit comments