Skip to content

Commit 604e3c2

Browse files
authored
Newsletter: Remove org_name from Newsletter Category Definition
TYPE: Feature LINK: ogc-2128
1 parent 2c092fb commit 604e3c2

File tree

12 files changed

+184
-138
lines changed

12 files changed

+184
-138
lines changed

src/onegov/org/forms/settings.py

+29-36
Original file line numberDiff line numberDiff line change
@@ -1152,16 +1152,14 @@ class NewsletterSettingsForm(Form):
11521152
label=_('Newsletter categories'),
11531153
description=_(
11541154
'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'
11571156
'```\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'
11651163
'```'
11661164
),
11671165
render_kw={
@@ -1190,60 +1188,55 @@ def ensure_categories(self) -> bool | None:
11901188
return False
11911189

11921190
if data:
1193-
if not isinstance(data, dict):
1191+
if not isinstance(data, list):
11941192
self.newsletter_categories.errors.append(
1195-
_('Invalid format. Please define an organisation name '
1193+
_('Invalid format. Please define a list'
11961194
'with topics and subtopics according the example.')
11971195
)
11981196
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)):
12011199
self.newsletter_categories.errors.append(
12021200
_('Invalid format. Please define topics and '
12031201
'subtopics according to the example.')
12041202
)
12051203
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):
12081210
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 ':'.")
12111214
)
12121215
return False
12131216

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
12311224

12321225
return None
12331226

12341227
def populate_obj(self, model: Organisation) -> None: # type:ignore
12351228
super().populate_obj(model)
12361229

12371230
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 []
12391232
model.newsletter_categories = data
12401233

12411234
model.notify_on_unsubscription = self.notify_on_unsubscription.data
12421235

12431236
def process_obj(self, model: Organisation) -> None: # type:ignore
12441237
super().process_obj(model)
12451238

1246-
categories = model.newsletter_categories or {}
1239+
categories = model.newsletter_categories or []
12471240
if not categories:
12481241
self.newsletter_categories.data = ''
12491242
return

src/onegov/org/forms/signup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def on_request(self) -> None:
5353
data.extend(sub)
5454
choices.extend((s, f'\xa0\xa0\xa0{s}') for s in sub)
5555

56-
self.subscribed_categories.choices = choices
57-
self.subscribed_categories.data = data
56+
self.subscribed_categories.choices = choices
57+
self.subscribed_categories.data = data
5858

5959
if len(choices) == 0:
6060
self.delete_field('subscribed_categories')

src/onegov/org/locale/de_CH/LC_MESSAGES/onegov.org.po

+12-14
Original file line numberDiff line numberDiff line change
@@ -1978,25 +1978,23 @@ msgid ""
19781978
"Example for newsletter topics with subtopics in yaml format. Note: Deeper "
19791979
"structures are not supported.\n"
19801980
"```\n"
1981-
"Organisation:\n"
1982-
" - Topic 1:\n"
1983-
" - Subtopic 1.1\n"
1984-
" - Subtopic 1.2\n"
1985-
" - Topic 2\n"
1986-
" - Topic 3:\n"
1987-
" - Subtopic 3.1\n"
1981+
"- Topic 1\n"
1982+
"- Topic 2:\n"
1983+
" - Subtopic 2.1\n"
1984+
"- Topic 3:\n"
1985+
" - Subtopic 3.1\n"
1986+
" - Subtopic 3.2\n"
19881987
"```"
19891988
msgstr ""
19901989
"Beispiel für Newsletter-Themen mit Unterthemen im yaml-Format. Hinweis: "
19911990
"Tiefere Strukturen werden nicht unterstützt.\n"
19921991
"```\n"
1993-
"Organisation:\n"
1994-
" - Thema 1:\n"
1995-
" - Unterthema 1.1\n"
1996-
" - Unterthema 1.2\n"
1997-
" - Thema 2\n"
1998-
" - Thema 3:\n"
1999-
" - Unterthema 3.1\n"
1992+
"- Thema 1\n"
1993+
"- Thema 2:\n"
1994+
" - Unterthema 2.1\n"
1995+
"- Thema 3:\n"
1996+
" - Unterthema 3.1\n"
1997+
" - Unterthema 3.2\n"
20001998
"```"
20011999

20022000
msgid "Notify on newsletter unsubscription"

src/onegov/org/locale/fr_CH/LC_MESSAGES/onegov.org.po

+13-14
Original file line numberDiff line numberDiff line change
@@ -1986,25 +1986,24 @@ msgid ""
19861986
"Example for newsletter topics with subtopics in yaml format. Note: Deeper "
19871987
"structures are not supported.\n"
19881988
"```\n"
1989-
"Organisation:\n"
1990-
" - Topic 1:\n"
1991-
" - Subtopic 1.1\n"
1992-
" - Subtopic 1.2\n"
1993-
" - Topic 2\n"
1994-
" - Topic 3:\n"
1995-
" - Subtopic 3.1\n"
1989+
"- Topic 1\n"
1990+
"- Topic 2:\n"
1991+
" - Subtopic 2.1\n"
1992+
"- Topic 3:\n"
1993+
" - Subtopic 3.1\n"
1994+
" - Subtopic 3.2\n"
19961995
"```"
19971996
msgstr ""
19981997
"Exemple de sujets de newsletter avec des sous-sujets au format yaml. Note : "
19991998
"Les structures plus profondes ne sont pas prises en charge. \n"
20001999
"```\n"
2001-
"Organisation:\n"
2002-
" - Thème 1:\n"
2003-
" - Sous-thème 1.1\n"
2004-
" - Sous-thème 1.2\n"
2005-
" - Thème 2\n"
2006-
" - Thème 3:\n"
2007-
" - Sous-thème 3.1```"
2000+
"- Thème 1\n"
2001+
"- Thème 2:\n"
2002+
" - Sous-thème 2.1\n"
2003+
"- Thème 3:\n"
2004+
" - Sous-thème 3.1\n"
2005+
" - Sous-thème 3.2\n"
2006+
"```"
20082007

20092008
msgid "Notify on newsletter unsubscription"
20102009
msgstr "Notifier le désabonnement à la lettre d'information"

src/onegov/org/locale/it_CH/LC_MESSAGES/onegov.org.po

+12-14
Original file line numberDiff line numberDiff line change
@@ -1990,25 +1990,23 @@ msgid ""
19901990
"Example for newsletter topics with subtopics in yaml format. Note: Deeper "
19911991
"structures are not supported.\n"
19921992
"```\n"
1993-
"Organisation:\n"
1994-
" - Topic 1:\n"
1995-
" - Subtopic 1.1\n"
1996-
" - Subtopic 1.2\n"
1997-
" - Topic 2\n"
1998-
" - Topic 3:\n"
1999-
" - Subtopic 3.1\n"
1993+
"- Topic 1\n"
1994+
"- Topic 2:\n"
1995+
" - Subtopic 2.1\n"
1996+
"- Topic 3:\n"
1997+
" - Subtopic 3.1\n"
1998+
" - Subtopic 3.2\n"
20001999
"```"
20012000
msgstr ""
20022001
"Esempio di argomenti di newsletter con sottoargomenti in formato yaml. Nota: "
20032002
"Le strutture più profonde non sono supportate.\n"
20042003
"```\n"
2005-
"Organizzazione:\n"
2006-
" - Argomento 1:\n"
2007-
" - Sottotema 1.1\n"
2008-
" - Sottotema 1.2\n"
2009-
" - Argomento 2\n"
2010-
" - Argomento 3:\n"
2011-
" - Sottotema 3.1\n"
2004+
"- Argomento 1\n"
2005+
"- Argomento 2:\n"
2006+
" - Sottotema 2.1\n"
2007+
"- Argomento 3:\n"
2008+
" - Sottotema 3.1\n"
2009+
" - Sottotema 3.2\n"
20122010
"```"
20132011

20142012
msgid "Notify on newsletter unsubscription"

src/onegov/org/models/organisation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ class Organisation(Base, TimestampMixin):
211211
# Newsletter settings
212212
show_newsletter: dict_property[bool] = meta_property(default=False)
213213
secret_content_allowed: dict_property[bool] = meta_property(default=False)
214-
newsletter_categories: (
215-
dict_property)[dict[str, list[dict[str, list[str]] | str]]] = (
216-
meta_property(default=dict))
214+
newsletter_categories: dict_property[list[dict[str, list[str]] | str]] = (
215+
meta_property(default=list)
216+
)
217217
notify_on_unsubscription: dict_property[list[str] | None] = meta_property()
218218

219219
# Chat Settings

src/onegov/org/theme/styles/org.scss

+32
Original file line numberDiff line numberDiff line change
@@ -6831,3 +6831,35 @@ a#results {
68316831
}
68326832

68336833

6834+
/*
6835+
Code Block, Code Inline, Code
6836+
6837+
<pre><code>...</code></pre>
6838+
*/
6839+
6840+
$code-background: #f5f5f5;
6841+
$code-border-radius: 4px;
6842+
$code-padding-block: 0.5rem;
6843+
$code-padding-inline: 0.125rem;
6844+
$code-block-margin-bottom: 0.8rem;
6845+
6846+
pre code,
6847+
.code-block,
6848+
.code-inline,
6849+
code {
6850+
background: $code-background;
6851+
border-radius: $code-border-radius;
6852+
}
6853+
6854+
pre code,
6855+
.code-block {
6856+
padding: $code-padding-block;
6857+
margin-bottom: $code-block-margin-bottom;
6858+
display: block;
6859+
}
6860+
6861+
.code-inline,
6862+
code {
6863+
padding: $code-padding-inline;
6864+
display: inline;
6865+
}

src/onegov/org/utils.py

+22-24
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333

3434
from typing import overload, Any, Literal, TYPE_CHECKING
35+
3536
if TYPE_CHECKING:
3637
from _typeshed import SupportsRichComparison
3738
from collections.abc import Callable, Iterable, Iterator, Sequence
@@ -1194,32 +1195,30 @@ def widest_access(*accesses: str) -> str:
11941195

11951196
@overload
11961197
def extract_categories_and_subcategories(
1197-
categories: dict[str, list[dict[str, list[str]] | str]],
1198+
categories: list[dict[str, list[str]] | str],
11981199
flattened: Literal[False] = False
11991200
) -> tuple[list[str], list[list[str]]]: ...
12001201

12011202
@overload
12021203
def extract_categories_and_subcategories(
1203-
categories: dict[str, list[dict[str, list[str]] | str]],
1204+
categories: list[dict[str, list[str]] | str],
12041205
flattened: Literal[True]
12051206
) -> list[str]: ...
12061207

12071208

12081209
def extract_categories_and_subcategories(
1209-
categories: dict[str, list[dict[str, list[str]] | str]],
1210+
categories: list[dict[str, list[str]] | str],
12101211
flattened: bool = False
12111212
) -> tuple[list[str], list[list[str]]] | list[str]:
12121213
"""
12131214
Extracts categories and subcategories from the `newsletter categories`
12141215
dictionary in `newsletter settings`.
12151216
12161217
Example for categories dict:
1217-
{
1218-
'org_name': [
1219-
{'main_category_1'},
1220-
{'main_category_2': ['sub_category_21', 'sub_category_22']}
1221-
]
1222-
}
1218+
[
1219+
{'main_category_1'},
1220+
{'main_category_2': ['sub_category_21', 'sub_category_22']}
1221+
]
12231222
returning a tuple of lists:
12241223
['main_category_1', 'main_category_2'],
12251224
[[], ['sub_category_21', 'sub_category_22']]
@@ -1229,26 +1228,25 @@ def extract_categories_and_subcategories(
12291228
12301229
"""
12311230
cats: list[str] = []
1232-
subcats: list[list[str]] = []
1231+
sub_cats: list[list[str]] = []
12331232

12341233
if not categories:
1235-
return cats, subcats
1236-
1237-
for items in categories.values():
1238-
for item in items:
1239-
if isinstance(item, dict):
1240-
for topic, subs in item.items():
1241-
cats.append(topic)
1242-
subcats.append(subs)
1243-
else:
1244-
cats.append(item)
1245-
subcats.append([])
1234+
return cats, sub_cats
1235+
1236+
for item in categories:
1237+
if isinstance(item, dict):
1238+
for topic, subs in item.items():
1239+
cats.append(topic)
1240+
sub_cats.append(subs or [])
1241+
else:
1242+
cats.append(item)
1243+
sub_cats.append([])
12461244

12471245
if flattened:
1248-
cats.extend([item for sublist in subcats for item in sublist])
1249-
return cats
1246+
return (cats +
1247+
[item for sublist in sub_cats if sublist for item in sublist])
12501248

1251-
return cats, subcats
1249+
return cats, sub_cats
12521250

12531251

12541252
def format_phone_number(phone_number: str) -> str:

0 commit comments

Comments
 (0)