From 17e0497ed86b5b198a5a22fa0d1747d604365144 Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Wed, 19 Jun 2024 13:41:34 +0200 Subject: [PATCH] musician new dashborad --- orchestra/contrib/musician/mixins.py | 3 +- .../templates/musician/dashboard.html | 214 +++++++----------- .../templates/musician/dashboard2.html | 111 --------- .../templates/musician/domain_detail.html | 2 +- .../templates/musician/domain_list.html | 133 +++++++++++ orchestra/contrib/musician/urls.py | 2 +- orchestra/contrib/musician/utils.py | 2 +- orchestra/contrib/musician/views.py | 51 +---- 8 files changed, 224 insertions(+), 294 deletions(-) delete mode 100644 orchestra/contrib/musician/templates/musician/dashboard2.html create mode 100644 orchestra/contrib/musician/templates/musician/domain_list.html diff --git a/orchestra/contrib/musician/mixins.py b/orchestra/contrib/musician/mixins.py index 4f018e48..a6baf22f 100644 --- a/orchestra/contrib/musician/mixins.py +++ b/orchestra/contrib/musician/mixins.py @@ -14,7 +14,8 @@ class CustomContextMixin(ContextMixin): context = super().get_context_data(**kwargs) # generate services menu items services_menu = [ - {'icon': 'globe-europe', 'pattern_name': 'musician:dashboard', 'title': _('Domains')}, + {'icon': 'home', 'pattern_name': 'musician:dashboard', 'title': _('Dashboard')}, + {'icon': 'globe-europe', 'pattern_name': 'musician:domain-list', 'title': _('Domains')}, {'icon': 'envelope', 'pattern_name': 'musician:address-list', 'title': _('Mails')}, {'icon': 'mail-bulk', 'pattern_name': 'musician:mailing-lists', 'title': _('Mailing lists')}, {'icon': 'database', 'pattern_name': 'musician:database-list', 'title': _('Databases')}, diff --git a/orchestra/contrib/musician/templates/musician/dashboard.html b/orchestra/contrib/musician/templates/musician/dashboard.html index fd390596..e2b9cfa2 100644 --- a/orchestra/contrib/musician/templates/musician/dashboard.html +++ b/orchestra/contrib/musician/templates/musician/dashboard.html @@ -10,157 +10,97 @@

{% trans "It's the first time you log into the system, welcome on board!" %}

{% endif %} + + +
+ +
+ + +
+ {% for resource, usage in resource_usage.items %}
-
+
{{ usage.verbose_name }}
- {% include "musician/components/usage_progress_bar.html" with detail=usage.data %} +
+ {% if usage.data and usage.data.used %} + {{ usage.data.used|floatformat }} {{ usage.data.unit }} + {% endif %} +
+ {% if usage.data.progres_bar %} +
+
+
+ {% endif %} {% if usage.data.alert %}
{{ usage.data.alert }}
{% endif %}
+ +
+
    + {% for obj_data in usage.objects %} +
  • + {{ obj_data }} + {{ obj_data.used }} {{ obj_data.resource.unit }} +
  • + {% endfor %} +
+
{% endfor %} -
-
-
{% trans "Notifications" %}
- {% for message in notifications %} -

{{ message }}

- {% empty %} -

{% trans "There is no notifications at this time." %}

- {% endfor %} + + +
+
+
{% trans "Domains" %}
+
{{ domains|length }} {% trans "Domains" %}
+
+
+
    + {% for domain in domains %} +
  • + {{ domain }} + +
  • + {% endfor %} +
+
- - -

{% trans "Your domains and websites" %}

-

{% trans "Dashboard page description." %}

- -{% for domain in domains %} -
-
-
-
- {{ domain.name }} -
-
- {% with domain.websites.0 as website %} - {% with website.contents.0 as content %} - {% trans "View DNS records" %} - - {% endwith %} - {% endwith %} -
-
- {% comment "@slamora: orchestra doesn't have this information [won't fix] See issue #2" %} - {% trans "Expiration date" %}: {{ domain.expiration_date|date:"SHORT_DATE_FORMAT" }} - {% endcomment %} -
-
-
-
-
-

{% trans "Mail" %}

-

-

- {{ domain.addresses.count }} {% trans "mail addresses created" %} -

- -
-
-

{% trans "Mail list" %}

-

- -
-
-

{% trans "Software as a Service" %}

-

-

{% trans "Nothing installed" %}

- -
-
- -
-
-
- -{% endfor %} - - - {% endblock %} -{% block extrascript %} - -{% endblock %} diff --git a/orchestra/contrib/musician/templates/musician/dashboard2.html b/orchestra/contrib/musician/templates/musician/dashboard2.html deleted file mode 100644 index 927c8609..00000000 --- a/orchestra/contrib/musician/templates/musician/dashboard2.html +++ /dev/null @@ -1,111 +0,0 @@ -{% extends "musician/base.html" %} -{% load i18n %} - -{% block content %} - -

{% trans "Welcome back" %} {{ profile.username }}

-{% if profile.last_login %} -

{% blocktrans with last_login=profile.last_login|date:"SHORT_DATE_FORMAT" %}Last time you logged in was: {{ last_login }}{% endblocktrans %}

-{% else %} -

{% trans "It's the first time you log into the system, welcome on board!" %}

-{% endif %} - - -
- -
- - -
- - {% for resource, usage in resource_usage.items %} -
-
-
{{ usage.verbose_name }}
-
- {% if usage.data and usage.data.used %} - {{ usage.data.used|floatformat }} {{ usage.data.unit }} - {% endif %} -
- {% if usage.data.progres_bar %} -
-
-
- {% endif %} - {% if usage.data.alert %} -
- {{ usage.data.alert }} -
- {% endif %} -
- -
-
    - {% for obj_data in usage.objects %} -
  • - {{ obj_data }} - {{ obj_data.used }} {{ obj_data.resource.unit }} -
  • - {% endfor %} -
-
-
- {% endfor %} - - -
-
-
{% trans "Domains" %}
-
{{ domains|length }} {% trans "Domains" %}
-
-
-
    - {% for domain in domains %} -
  • - {{ domain }} - -
  • - {% endfor %} -
-
-
- -
- - - -{% endblock %} - diff --git a/orchestra/contrib/musician/templates/musician/domain_detail.html b/orchestra/contrib/musician/templates/musician/domain_detail.html index 5efc9ce7..be488b33 100644 --- a/orchestra/contrib/musician/templates/musician/domain_detail.html +++ b/orchestra/contrib/musician/templates/musician/domain_detail.html @@ -2,7 +2,7 @@ {% load i18n %} {% block content %} -{% trans "Go back" %} +{% trans "Go back" %}

{% trans "DNS settings for" %} {{ object.name }} diff --git a/orchestra/contrib/musician/templates/musician/domain_list.html b/orchestra/contrib/musician/templates/musician/domain_list.html new file mode 100644 index 00000000..81fd9e97 --- /dev/null +++ b/orchestra/contrib/musician/templates/musician/domain_list.html @@ -0,0 +1,133 @@ +{% extends "musician/base.html" %} +{% load i18n %} + +{% block content %} + + +

{% trans "Your domains" %}

+ + +{% for domain in domains %} +
+
+
+
+ {{ domain.name }} +
+
+ {% with domain.websites.0 as website %} + {% with website.contents.0 as content %} + {% trans "View DNS records" %} + + {% endwith %} + {% endwith %} +
+
+ {% comment "@slamora: orchestra doesn't have this information [won't fix] See issue #2" %} + {% trans "Expiration date" %}: {{ domain.expiration_date|date:"SHORT_DATE_FORMAT" }} + {% endcomment %} +
+
+
+
+
+

{% trans "Mail" %}

+

+

+ {{ domain.addresses.count }} {% trans "mail addresses created" %} +

+ +
+
+

{% trans "Mail list" %}

+

+ +
+
+

{% trans "Software as a Service" %}

+

+

{% trans "Nothing installed" %}

+ +
+
+ +
+
+
+ +{% endfor %} + + + +{% endblock %} +{% block extrascript %} + +{% endblock %} diff --git a/orchestra/contrib/musician/urls.py b/orchestra/contrib/musician/urls.py index 09775f12..949ac879 100644 --- a/orchestra/contrib/musician/urls.py +++ b/orchestra/contrib/musician/urls.py @@ -17,8 +17,8 @@ urlpatterns = [ path('auth/login/', views.LoginView.as_view(), name='login'), path('auth/logout/', views.LogoutView.as_view(), name='logout'), path('dashboard/', views.DashboardView.as_view(), name='dashboard'), - path('dashboard2/', views.DashboardView2.as_view(), name='dashboard2'), + path('domains/', views.DomainListView.as_view(), name='domain-list'), path('domains//', views.DomainDetailView.as_view(), name='domain-detail'), path('domains//add-record/', views.DomainAddRecordView.as_view(), name='domain-add-record'), path('domains//records//update/', views.DomainUpdateRecordView.as_view(), name='domain-update-record'), diff --git a/orchestra/contrib/musician/utils.py b/orchestra/contrib/musician/utils.py index d35d2751..f9c9efd8 100644 --- a/orchestra/contrib/musician/utils.py +++ b/orchestra/contrib/musician/utils.py @@ -22,4 +22,4 @@ def get_bootstraped_percent_exact(value, total): percent = 100 * float(value)/float(total) except (TypeError, ZeroDivisionError): return 0 - return percent \ No newline at end of file + return int(percent) \ No newline at end of file diff --git a/orchestra/contrib/musician/views.py b/orchestra/contrib/musician/views.py index bed29bb7..b25ffc27 100644 --- a/orchestra/contrib/musician/views.py +++ b/orchestra/contrib/musician/views.py @@ -24,6 +24,9 @@ from django.views.generic.edit import (CreateView, DeleteView, FormView, from django.views.generic.list import ListView from requests.exceptions import HTTPError +from django.urls import reverse +from django.db.models import Q + from orchestra import get_version from orchestra.contrib.bills.models import Bill from orchestra.contrib.databases.models import Database @@ -57,10 +60,9 @@ from .lists.views import * logger = logging.getLogger(__name__) -from django.urls import reverse -from django.db.models import Q -class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): - template_name = "musician/dashboard2.html" + +class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): + template_name = "musician/dashboard.html" extra_context = { # Translators: This message appears on the page title 'title': _('Dashboard'), @@ -193,28 +195,17 @@ class DashboardView2(CustomContextMixin, UserTokenRequiredMixin, TemplateView): } -class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): - template_name = "musician/dashboard.html" +class DomainListView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): + template_name = "musician/domain_list.html" extra_context = { # Translators: This message appears on the page title - 'title': _('Dashboard'), + 'title': _('Domains'), } def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) domains = self.orchestra.retrieve_domain_list() - # TODO(@slamora) update when backend supports notifications - notifications = [] - - # show resource usage based on plan definition - profile_type = context['profile'].type - - # TODO(@slamora) update when backend provides resource usage data - resource_usage = { - 'mailbox': self.get_mailbox_usage(profile_type), - } - support_email = getattr(settings, "USER_SUPPORT_EMAIL", "suport@pangea.org") support_email_anchor = format_html( "{}", @@ -223,35 +214,11 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): ) context.update({ 'domains': domains, - 'resource_usage': resource_usage, - 'notifications': notifications, "support_email_anchor": support_email_anchor, }) return context - def get_mailbox_usage(self, profile_type): - allowed_mailboxes = ALLOWED_RESOURCES[profile_type]['mailbox'] - total_mailboxes = len(self.orchestra.retrieve_mailbox_list()) - mailboxes_left = allowed_mailboxes - total_mailboxes - - alert = '' - if mailboxes_left < 0: - alert = format_html("{} extra mailboxes", mailboxes_left * -1) - elif mailboxes_left <= 1: - alert = format_html("{} mailbox left", mailboxes_left) - - return { - 'verbose_name': _('Mailboxes'), - 'data': { - 'used': total_mailboxes, - 'total': allowed_mailboxes, - 'alert': alert, - 'unit': 'mailboxes', - 'percent': get_bootstraped_percent(total_mailboxes, allowed_mailboxes), - }, - } - class ProfileView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): template_name = "musician/profile.html"