Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ogc 2128 newsletter categories remove org name #1733

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 29 additions & 36 deletions src/onegov/org/forms/settings.py
Original file line number Diff line number Diff line change
@@ -1152,16 +1152,14 @@
label=_('Newsletter categories'),
description=_(
'Example for newsletter topics with subtopics in yaml format. '
'Note: Deeper structures are not supported.'
'\n'
'Note: Deeper structures are not supported.\n'
'```\n'
'Organisation:\n'
' - Topic 1:\n'
' - Subtopic 1.1\n'
' - Subtopic 1.2\n'
' - Topic 2\n'
' - Topic 3:\n'
' - Subtopic 3.1\n'
'- Topic 1\n'
'- Topic 2:\n'
' - Subtopic 2.1\n'
'- Topic 3:\n'
' - Subtopic 3.1\n'
' - Subtopic 3.2\n'
'```'
),
render_kw={
@@ -1190,60 +1188,55 @@
return False

if data:
if not isinstance(data, dict):
if not isinstance(data, list):
self.newsletter_categories.errors.append(
_('Invalid format. Please define an organisation name '
_('Invalid format. Please define a list'
'with topics and subtopics according the example.')
)
return False
for items in data.values():
if not isinstance(items, list):
for item in data:
if not isinstance(item, (str, dict)):
self.newsletter_categories.errors.append(
_('Invalid format. Please define topics and '
'subtopics according to the example.')
)
return False
for item in items:
if not isinstance(item, (dict, str)):

if isinstance(item, str):
continue

for topic, sub_topic in item.items():
if not isinstance(sub_topic, list):
self.newsletter_categories.errors.append(
_('Invalid format. Please define topics and '
'subtopics according to the example.')
_(f'Invalid format. Please define '
f"subtopic(s) for '{topic}' "
f"or remove the ':'.")
)
return False

if isinstance(item, dict):
for topic, sub_topic in item.items():
if not isinstance(sub_topic, list):
self.newsletter_categories.errors.append(
_(f'Invalid format. Please define '
f"subtopic(s) for '{topic}' "
f"or remove the ':'.")
)
return False
if not all(isinstance(sub, str)
for sub in sub_topic):
self.newsletter_categories.errors.append(
_('Invalid format. Only topics '
'and subtopics are allowed - no '
'deeper structures supported.')
)
return False
if not all(isinstance(sub, str) for sub in sub_topic):
self.newsletter_categories.errors.append(

Check warning on line 1218 in src/onegov/org/forms/settings.py

Codecov / codecov/patch

src/onegov/org/forms/settings.py#L1218

Added line #L1218 was not covered by tests
_('Invalid format. Only topics '
'and subtopics are allowed - no '
'deeper structures supported.')
)
return False

Check warning on line 1223 in src/onegov/org/forms/settings.py

Codecov / codecov/patch

src/onegov/org/forms/settings.py#L1223

Added line #L1223 was not covered by tests

return None

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

yaml_data = self.newsletter_categories.data
data = yaml.safe_load(yaml_data) if yaml_data else {}
data = yaml.safe_load(yaml_data) if yaml_data else []
model.newsletter_categories = data

model.notify_on_unsubscription = self.notify_on_unsubscription.data

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

categories = model.newsletter_categories or {}
categories = model.newsletter_categories or []
if not categories:
self.newsletter_categories.data = ''
return
4 changes: 2 additions & 2 deletions src/onegov/org/forms/signup.py
Original file line number Diff line number Diff line change
@@ -53,8 +53,8 @@ def on_request(self) -> None:
data.extend(sub)
choices.extend((s, f'\xa0\xa0\xa0{s}') for s in sub)

self.subscribed_categories.choices = choices
self.subscribed_categories.data = data
self.subscribed_categories.choices = choices
self.subscribed_categories.data = data

if len(choices) == 0:
self.delete_field('subscribed_categories')
26 changes: 12 additions & 14 deletions src/onegov/org/locale/de_CH/LC_MESSAGES/onegov.org.po
Original file line number Diff line number Diff line change
@@ -1978,25 +1978,23 @@ msgid ""
"Example for newsletter topics with subtopics in yaml format. Note: Deeper "
"structures are not supported.\n"
"```\n"
"Organisation:\n"
" - Topic 1:\n"
" - Subtopic 1.1\n"
" - Subtopic 1.2\n"
" - Topic 2\n"
" - Topic 3:\n"
" - Subtopic 3.1\n"
"- Topic 1\n"
"- Topic 2:\n"
" - Subtopic 2.1\n"
"- Topic 3:\n"
" - Subtopic 3.1\n"
" - Subtopic 3.2\n"
"```"
msgstr ""
"Beispiel für Newsletter-Themen mit Unterthemen im yaml-Format. Hinweis: "
"Tiefere Strukturen werden nicht unterstützt.\n"
"```\n"
"Organisation:\n"
" - Thema 1:\n"
" - Unterthema 1.1\n"
" - Unterthema 1.2\n"
" - Thema 2\n"
" - Thema 3:\n"
" - Unterthema 3.1\n"
"- Thema 1\n"
"- Thema 2:\n"
" - Unterthema 2.1\n"
"- Thema 3:\n"
" - Unterthema 3.1\n"
" - Unterthema 3.2\n"
"```"

msgid "Notify on newsletter unsubscription"
27 changes: 13 additions & 14 deletions src/onegov/org/locale/fr_CH/LC_MESSAGES/onegov.org.po
Original file line number Diff line number Diff line change
@@ -1986,25 +1986,24 @@ msgid ""
"Example for newsletter topics with subtopics in yaml format. Note: Deeper "
"structures are not supported.\n"
"```\n"
"Organisation:\n"
" - Topic 1:\n"
" - Subtopic 1.1\n"
" - Subtopic 1.2\n"
" - Topic 2\n"
" - Topic 3:\n"
" - Subtopic 3.1\n"
"- Topic 1\n"
"- Topic 2:\n"
" - Subtopic 2.1\n"
"- Topic 3:\n"
" - Subtopic 3.1\n"
" - Subtopic 3.2\n"
"```"
msgstr ""
"Exemple de sujets de newsletter avec des sous-sujets au format yaml. Note : "
"Les structures plus profondes ne sont pas prises en charge. \n"
"```\n"
"Organisation:\n"
" - Thème 1:\n"
" - Sous-thème 1.1\n"
" - Sous-thème 1.2\n"
" - Thème 2\n"
" - Thème 3:\n"
" - Sous-thème 3.1```"
"- Thème 1\n"
"- Thème 2:\n"
" - Sous-thème 2.1\n"
"- Thème 3:\n"
" - Sous-thème 3.1\n"
" - Sous-thème 3.2\n"
"```"

msgid "Notify on newsletter unsubscription"
msgstr "Notifier le désabonnement à la lettre d'information"
26 changes: 12 additions & 14 deletions src/onegov/org/locale/it_CH/LC_MESSAGES/onegov.org.po
Original file line number Diff line number Diff line change
@@ -1990,25 +1990,23 @@ msgid ""
"Example for newsletter topics with subtopics in yaml format. Note: Deeper "
"structures are not supported.\n"
"```\n"
"Organisation:\n"
" - Topic 1:\n"
" - Subtopic 1.1\n"
" - Subtopic 1.2\n"
" - Topic 2\n"
" - Topic 3:\n"
" - Subtopic 3.1\n"
"- Topic 1\n"
"- Topic 2:\n"
" - Subtopic 2.1\n"
"- Topic 3:\n"
" - Subtopic 3.1\n"
" - Subtopic 3.2\n"
"```"
msgstr ""
"Esempio di argomenti di newsletter con sottoargomenti in formato yaml. Nota: "
"Le strutture più profonde non sono supportate.\n"
"```\n"
"Organizzazione:\n"
" - Argomento 1:\n"
" - Sottotema 1.1\n"
" - Sottotema 1.2\n"
" - Argomento 2\n"
" - Argomento 3:\n"
" - Sottotema 3.1\n"
"- Argomento 1\n"
"- Argomento 2:\n"
" - Sottotema 2.1\n"
"- Argomento 3:\n"
" - Sottotema 3.1\n"
" - Sottotema 3.2\n"
"```"

msgid "Notify on newsletter unsubscription"
6 changes: 3 additions & 3 deletions src/onegov/org/models/organisation.py
Original file line number Diff line number Diff line change
@@ -211,9 +211,9 @@ class Organisation(Base, TimestampMixin):
# Newsletter settings
show_newsletter: dict_property[bool] = meta_property(default=False)
secret_content_allowed: dict_property[bool] = meta_property(default=False)
newsletter_categories: (
dict_property)[dict[str, list[dict[str, list[str]] | str]]] = (
meta_property(default=dict))
newsletter_categories: dict_property[list[dict[str, list[str]] | str]] = (
meta_property(default=list)
)
notify_on_unsubscription: dict_property[list[str] | None] = meta_property()

# Chat Settings
32 changes: 32 additions & 0 deletions src/onegov/org/theme/styles/org.scss
Original file line number Diff line number Diff line change
@@ -6831,3 +6831,35 @@ a#results {
}


/*
Code Block, Code Inline, Code

<pre><code>...</code></pre>
*/

$code-background: #f5f5f5;
$code-border-radius: 4px;
$code-padding-block: 0.5rem;
$code-padding-inline: 0.125rem;
$code-block-margin-bottom: 0.8rem;

pre code,
.code-block,
.code-inline,
code {
background: $code-background;
border-radius: $code-border-radius;
}

pre code,
.code-block {
padding: $code-padding-block;
margin-bottom: $code-block-margin-bottom;
display: block;
}

.code-inline,
code {
padding: $code-padding-inline;
display: inline;
}
46 changes: 22 additions & 24 deletions src/onegov/org/utils.py
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@


from typing import overload, Any, Literal, TYPE_CHECKING

if TYPE_CHECKING:
from _typeshed import SupportsRichComparison
from collections.abc import Callable, Iterable, Iterator, Sequence
@@ -1194,32 +1195,30 @@ def widest_access(*accesses: str) -> str:

@overload
def extract_categories_and_subcategories(
categories: dict[str, list[dict[str, list[str]] | str]],
categories: list[dict[str, list[str]] | str],
flattened: Literal[False] = False
) -> tuple[list[str], list[list[str]]]: ...

@overload
def extract_categories_and_subcategories(
categories: dict[str, list[dict[str, list[str]] | str]],
categories: list[dict[str, list[str]] | str],
flattened: Literal[True]
) -> list[str]: ...


def extract_categories_and_subcategories(
categories: dict[str, list[dict[str, list[str]] | str]],
categories: list[dict[str, list[str]] | str],
flattened: bool = False
) -> tuple[list[str], list[list[str]]] | list[str]:
"""
Extracts categories and subcategories from the `newsletter categories`
dictionary in `newsletter settings`.

Example for categories dict:
{
'org_name': [
{'main_category_1'},
{'main_category_2': ['sub_category_21', 'sub_category_22']}
]
}
[
{'main_category_1'},
{'main_category_2': ['sub_category_21', 'sub_category_22']}
]
returning a tuple of lists:
['main_category_1', 'main_category_2'],
[[], ['sub_category_21', 'sub_category_22']]
@@ -1229,26 +1228,25 @@ def extract_categories_and_subcategories(

"""
cats: list[str] = []
subcats: list[list[str]] = []
sub_cats: list[list[str]] = []

if not categories:
return cats, subcats

for items in categories.values():
for item in items:
if isinstance(item, dict):
for topic, subs in item.items():
cats.append(topic)
subcats.append(subs)
else:
cats.append(item)
subcats.append([])
return cats, sub_cats

for item in categories:
if isinstance(item, dict):
for topic, subs in item.items():
cats.append(topic)
sub_cats.append(subs or [])
else:
cats.append(item)
sub_cats.append([])

if flattened:
cats.extend([item for sublist in subcats for item in sublist])
return cats
return (cats +
[item for sublist in sub_cats if sublist for item in sublist])

return cats, subcats
return cats, sub_cats


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