Skip to content

Commit

Permalink
dashboard: added list of managed projects
Browse files Browse the repository at this point in the history
Fixes #8631
  • Loading branch information
nijel committed Apr 23, 2024
1 parent 9739e91 commit dcd6c9f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Not yet released.
* Display more details on source string change in history.
* :ref:`mt-microsoft-translator` now supports using custom translators.
* Improved error handling in :ref:`invite-user`.
* Added list of managed projects to the dashboard view.

**Bug fixes**

Expand Down
31 changes: 31 additions & 0 deletions weblate/accounts/migrations/0009_alter_profile_dashboard_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright © Michal Čihař <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Generated by Django 5.0.3 on 2024-04-23 11:46

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("accounts", "0008_alter_auditlog_activity"),
]

operations = [
migrations.AlterField(
model_name="profile",
name="dashboard_view",
field=models.IntegerField(
choices=[
(1, "Watched translations"),
(6, "Component lists"),
(4, "Component list"),
(5, "Suggested translations"),
(7, "Managed projects"),
],
default=1,
verbose_name="Default dashboard view",
),
),
]
3 changes: 3 additions & 0 deletions weblate/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,19 +510,22 @@ class Profile(models.Model):
DASHBOARD_COMPONENT_LIST = 4
DASHBOARD_SUGGESTIONS = 5
DASHBOARD_COMPONENT_LISTS = 6
DASHBOARD_MANAGED = 7

DASHBOARD_CHOICES = (
(DASHBOARD_WATCHED, gettext_lazy("Watched translations")),
(DASHBOARD_COMPONENT_LISTS, gettext_lazy("Component lists")),
(DASHBOARD_COMPONENT_LIST, gettext_lazy("Component list")),
(DASHBOARD_SUGGESTIONS, gettext_lazy("Suggested translations")),
(DASHBOARD_MANAGED, gettext_lazy("Managed projects")),
)

DASHBOARD_SLUGS = {
DASHBOARD_WATCHED: "your-subscriptions",
DASHBOARD_COMPONENT_LIST: "list",
DASHBOARD_SUGGESTIONS: "suggestions",
DASHBOARD_COMPONENT_LISTS: "componentlists",
DASHBOARD_MANAGED: "managed",
}

dashboard_view = models.IntegerField(
Expand Down
12 changes: 12 additions & 0 deletions weblate/templates/dashboard/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<li {% active_link "componentlists" %}><a href="#componentlists" data-toggle="tab">{% trans "Component lists" %} <span class="badge">{{ all_componentlists|length }}</span></a></li>
{% endif %}
<li {% active_link "suggestions" %}><a href="#suggestions" data-toggle="tab">{% trans "Suggested translations" %} <span class="badge">{{ suggestions|length }}</span></a></li>
{% if owned_projects %}
<li {% active_link "managed" %}><a href="#managed" data-toggle="tab">{% trans "Managed projects" %} <span class="badge">{{ all_owned_projects|length }}</span></a></li>
{% endif %}
{% for componentlist in componentlists %}
<li {% active_link componentlist.tab_slug %}><a href="#{{ componentlist.tab_slug }}" data-toggle="tab">{{ componentlist.name }} <span class="badge">{{ componentlist.translations|length }}</span></a></li>
{% endfor %}
Expand Down Expand Up @@ -60,6 +63,15 @@
</div>
{% endif %}

{% if owned_projects %}
<div {% active_tab "managed" %}>
{% include "snippets/list-objects.html" with objects=owned_projects label=_("Project") %}
{% if all_owned_projects|length > 10 %}
<a href="{% url 'projects' %}?owned={{user.username}}" class="btn btn-primary">{% trans "Browse all managed projects" %}</a>
{% endif %}
</div>
{% endif %}

{# Suggested translations #}
<div {% active_tab "suggestions" %}>
{% if suggestions %}
Expand Down
5 changes: 5 additions & 0 deletions weblate/trans/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ def dashboard_user(request: AuthenticatedHttpRequest):

usersubscriptions = get_paginator(request, usersubscriptions)
usersubscriptions = translation_prefetch_tasks(usersubscriptions)
owned = user.owned_projects.order()
else:
owned = Project.objects.none()

return render(
request,
Expand All @@ -282,6 +285,8 @@ def dashboard_user(request: AuthenticatedHttpRequest):
),
"active_tab_slug": active_tab_slug,
"reports_form": ReportsForm({}),
"all_owned_projects": owned,
"owned_projects": prefetch_project_flags(prefetch_stats(owned[:10])),
},
)

Expand Down

0 comments on commit dcd6c9f

Please sign in to comment.