Skip to content

Commit

Permalink
Merge pull request #2767 from digitalfabrik/feature/add_draft_row_to_…
Browse files Browse the repository at this point in the history
…dashboard

Add row for drafted pages to to-do-board
  • Loading branch information
JoeyStk committed May 16, 2024
2 parents e567be8 + fef84b5 commit e9c7ea4
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% endblock collapsible_box_title %}
{% block collapsible_box_content %}
<div class="flex flex-wrap gap-2">
<p class="pt-2 px-4">
<p class="px-4 pt-2">
{% blocktranslate trimmed %}
Every day you can find a list of ideas on how you can improve the content of your pages.
{% endblocktranslate %}
Expand All @@ -30,6 +30,7 @@
{% if perms.cms.change_page %}
{% include "dashboard/todo_dashboard_rows/_unreviewed_pages_row.html" %}
{% include "dashboard/todo_dashboard_rows/_automatically_saved_pages_row.html" %}
{% include "dashboard/todo_dashboard_rows/_drafted_pages_row.html" %}
{% endif %}
</div>
{% endblock collapsible_box_content %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends "../_todo_dashboard_row.html" %}
{% load i18n %}
{% block todo_dashboard_icon %}
notepad-text-dashed
{% endblock todo_dashboard_icon %}
{% block todo_dashboard_title_link %}
{% url 'pages' region_slug=request.region.slug language_slug=default_language_slug %}?status=DRAFT
{% endblock todo_dashboard_title_link %}
{% block todo_dashboard_title %}
{% translate "Drafted pages" %}
{% endblock todo_dashboard_title %}
{% block todo_dashboard_number %}
{% with total=drafted_pages|length %}
{{ block.super }}
{% endwith %}
{% endblock todo_dashboard_number %}
{% block todo_dashboard_description %}
{% if drafted_pages %}
{% blocktranslate trimmed %}
The page <b>{{ single_drafted_page }}</b> was saved as draft. User can't see your drafted pages. Please don't forget to publish the page once it's ready.
{% endblocktranslate %}
{% else %}
{% blocktranslate trimmed %}
At the moment there is no drafted page. Good job!
{% endblocktranslate %}
{% endif %}
{% endblock todo_dashboard_description %}
{% block todo_dashboard_button_link %}
{% if drafted_pages %}
<a class="btn !rounded-full"
href="{% url 'edit_page' region_slug=request.region.slug language_slug=default_language_slug page_id=single_drafted_page.page_id %}">
{% translate "Go to page" %}
</a>
{% else %}
<i class="w-8 h-8 text-green-500" icon-name="check-circle-2"></i>
{% endif %}
{% endblock todo_dashboard_button_link %}
20 changes: 20 additions & 0 deletions integreat_cms/cms/views/dashboard/dashboard_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
# context.update(self.get_broken_links_context())
context.update(self.get_low_hix_value_context())
context.update(self.get_outdated_pages_context())
context.update(self.get_drafted_pages())

return context

Expand Down Expand Up @@ -226,3 +227,22 @@ def get_outdated_pages_context(
"days_since_last_updated": days_since_last_updated,
"outdated_threshold_date": outdated_threshold_date_str,
}

def get_drafted_pages(
self,
) -> dict[str, QuerySet]:
r"""
Extend context by info on drafted pages
:return: Dictionary containing the context for drafted pages for one region.
"""
drafted_pages = PageTranslation.objects.filter(
id__in=self.latest_version_ids,
status=status.DRAFT,
language__slug=self.request.region.default_language.slug,
)
single_drafted_page = drafted_pages.first()
return {
"drafted_pages": drafted_pages,
"single_drafted_page": single_drafted_page,
}
19 changes: 19 additions & 0 deletions integreat_cms/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -4943,6 +4943,7 @@ msgid "At the moment there are no automatically saved pages. Good job!"
msgstr "Aktuell gibt es keine automatisch gespeicherte Seite. Gute Arbeit!"

#: cms/templates/dashboard/todo_dashboard_rows/_automatically_saved_pages_row.html
#: cms/templates/dashboard/todo_dashboard_rows/_drafted_pages_row.html
#: cms/templates/dashboard/todo_dashboard_rows/_low_hix_row.html
#: cms/templates/dashboard/todo_dashboard_rows/_outdated_pages_row.html
#: cms/templates/dashboard/todo_dashboard_rows/_unreviewed_pages_row.html
Expand Down Expand Up @@ -4971,6 +4972,24 @@ msgstr "Aktuell gibt es keine fehlerhaften Links. Gute Arbeit!"
msgid "Go to link"
msgstr "Zum Link"

#: cms/templates/dashboard/todo_dashboard_rows/_drafted_pages_row.html
msgid "Drafted pages"
msgstr "Seiten im Entwurf"

#: cms/templates/dashboard/todo_dashboard_rows/_drafted_pages_row.html
#, python-format
msgid ""
"The page <b>%(single_drafted_page)s</b> was saved as draft. User can't see "
"your drafted pages. Please don't forget to publish the page once it's ready."
msgstr ""
"Die Seite <b>%(single_drafted_page)s</b> liegt nur im Entwurf vor. Nutzer:"
"innen können die Inhalte nicht sehen. Bitte vergessen Sie nicht, die Seite "
"zu veröffentlichen, sobald diese fertig ist."

#: cms/templates/dashboard/todo_dashboard_rows/_drafted_pages_row.html
msgid "At the moment there is no drafted page. Good job!"
msgstr "Aktuell gibt es keine Seiten im Entwurf. Gute Arbeit!"

#: cms/templates/dashboard/todo_dashboard_rows/_low_hix_row.html
msgid "Pages with low hix score"
msgstr "Seiten mit niedrigem HIX-Wert"
Expand Down
2 changes: 2 additions & 0 deletions integreat_cms/release_notes/current/unreleased/2765.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
en: Add draft row to to-do-board
de: Entwurfszeile zur Aufgabenliste hinzufügen
59 changes: 59 additions & 0 deletions tests/cms/views/dashboard/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,62 @@ def assert_button_leads_to_valid_page(client: Client) -> None:
)
response = client.get(target_page)
assert response.status_code == 200


@pytest.mark.parametrize(
"login_role_user", PRIV_STAFF_ROLES + [MANAGEMENT, EDITOR, AUTHOR], indirect=True
)
@pytest.mark.django_db
def test_number_of_drafted_pages_is_correct(
load_test_data: None,
login_role_user: tuple[Client, str],
) -> None:
client, role = login_role_user
expected_number_of_pages = 1

pages = reverse(
"pages",
kwargs={"region_slug": "augsburg", "language_slug": "de"},
)

dashboard = reverse(
"dashboard",
kwargs={"region_slug": "augsburg"},
)

response = client.get(dashboard)

assert response.status_code == 200
match = re.search(
rf'<a href="{pages}\?(|[^"]+&)status=DRAFT(|&[^"]+)"[^<>]*>Seiten im Entwurf</a>\s*<span>\(Insgesamt ([0-9]+)\)</span>',
response.content.decode("utf-8"),
)
assert match, "Number of drafted pages not displayed"
assert (
int(match.group(3)) == expected_number_of_pages
), "Wrong number of pages displayed as outdated"


@pytest.mark.parametrize(
"login_role_user", PRIV_STAFF_ROLES + [MANAGEMENT, EDITOR, AUTHOR], indirect=True
)
@pytest.mark.django_db
def test_single_drafted_page_is_correct(
load_test_data: None,
login_role_user: tuple[Client, str],
) -> None:
client, role = login_role_user

dashboard = reverse(
"dashboard",
kwargs={"region_slug": "augsburg"},
)

response = client.get(dashboard)

assert response.status_code == 200
match = re.search(
r"Die Seite <b>Über die App Integreat Augsburg</b> liegt nur im Entwurf vor.",
response.content.decode("utf-8"),
)
assert match, "Not updated message missing"

0 comments on commit e9c7ea4

Please sign in to comment.