Add organization dashboard and redirects
This commit is contained in:
parent
1b69310c77
commit
7f389434a4
6 changed files with 54 additions and 15 deletions
|
@ -1,5 +1,8 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils.functional import cached_property
|
||||||
|
from django.utils.text import slugify
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from .mixins import ServalaModelMixin
|
from .mixins import ServalaModelMixin
|
||||||
|
@ -29,6 +32,15 @@ class Organization(ServalaModelMixin, models.Model):
|
||||||
verbose_name=_("Members"),
|
verbose_name=_("Members"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def slug(self):
|
||||||
|
return f"{slugify(self.name)}-{self.id}"
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse(
|
||||||
|
"frontend:organization.dashboard", kwargs={"organization": self.slug}
|
||||||
|
)
|
||||||
|
|
||||||
def set_owner(self, user):
|
def set_owner(self, user):
|
||||||
OrganizationMembership.objects.filter(user=user, organization=self).delete()
|
OrganizationMembership.objects.filter(user=user, organization=self).delete()
|
||||||
OrganizationMembership.objects.create(
|
OrganizationMembership.objects.create(
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<div class="sidebar-header position-relative">
|
<div class="sidebar-header position-relative">
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
<a href="index.html">
|
<a href="{% if current_organization %}{{ current_organization.get_absolute_url }}{% else %}/{% endif %}">
|
||||||
<img src="" alt="{% translate 'Logo' %}" srcset="">
|
<img src="" alt="{% translate 'Logo' %}" srcset="">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
{# request.user.is_authenticated #}
|
{# request.user.is_authenticated #}
|
||||||
<li class="sidebar-item">
|
<li class="sidebar-item">
|
||||||
{% if user_organizations.count > 1 %}
|
{% if user_organizations.count %}
|
||||||
<button class="btn btn-primary dropdown-toggle me-1"
|
<button class="btn btn-primary dropdown-toggle me-1"
|
||||||
type="button"
|
type="button"
|
||||||
id="organizationDropdown"
|
id="organizationDropdown"
|
||||||
|
@ -81,11 +81,17 @@
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu" aria-labelledby="organizationDropdown">
|
<div class="dropdown-menu" aria-labelledby="organizationDropdown">
|
||||||
{% for organization in user_organizations %}
|
{% for organization in user_organizations %}
|
||||||
<a class="dropdown-item" href="#TODO">{{ organization.name }}</a>
|
<a class="dropdown-item{% if organization == current_organization %} active{% endif %}"
|
||||||
|
href="{{ organization.get_absolute_url }}">
|
||||||
|
<i class="bi bi-building-fill me-1"></i>
|
||||||
|
{{ organization.name }}
|
||||||
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<a href="{% url 'frontend:organization.create' %}" class="dropdown-item">
|
||||||
|
<i class="bi bi-building-add me-1"></i>
|
||||||
|
<span>{% translate "Create organization" %}</span>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% elif current_organization %}
|
|
||||||
{% translate "Organization" %}: {{ current_organization.name }}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{% url 'frontend:organization.create' %}" class="sidebar-link">
|
<a href="{% url 'frontend:organization.create' %}" class="sidebar-link">
|
||||||
<i class="bi bi-plus-square"></i>
|
<i class="bi bi-plus-square"></i>
|
||||||
|
@ -93,12 +99,15 @@
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
|
{% if current_organization %}
|
||||||
<li class="sidebar-item">
|
<li class="sidebar-item">
|
||||||
<a href="index.html" class='sidebar-link'>
|
<a href="{{ current_organization.get_absolute_url }}"
|
||||||
|
class='sidebar-link'>
|
||||||
<i class="bi bi-grid-fill"></i>
|
<i class="bi bi-grid-fill"></i>
|
||||||
<span>{% translate 'Dashboard' %}</span>
|
<span>{% translate 'Dashboard' %}</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
<li class="sidebar-title">{% translate 'Account' %}</li>
|
<li class="sidebar-title">{% translate 'Account' %}</li>
|
||||||
<li class="sidebar-item">
|
<li class="sidebar-item">
|
||||||
<a href="{% url 'frontend:profile' %}" class='sidebar-link'>
|
<a href="{% url 'frontend:profile' %}" class='sidebar-link'>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from django.urls import path
|
from django.urls import include, path
|
||||||
|
from django.views.generic import RedirectView
|
||||||
|
|
||||||
from servala.frontend import views
|
from servala.frontend import views
|
||||||
|
|
||||||
|
@ -10,5 +11,17 @@ urlpatterns = [
|
||||||
views.OrganizationCreateView.as_view(),
|
views.OrganizationCreateView.as_view(),
|
||||||
name="organization.create",
|
name="organization.create",
|
||||||
),
|
),
|
||||||
path("", views.IndexView.as_view(), name="index"),
|
path(
|
||||||
|
"<slug:organization>/",
|
||||||
|
include(
|
||||||
|
[
|
||||||
|
path(
|
||||||
|
"",
|
||||||
|
views.OrganizationDashboardView.as_view(),
|
||||||
|
name="organization.dashboard",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
|
path("", RedirectView.as_view(pattern_name="frontend:profile"), name="index"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
from .auth import LogoutView
|
from .auth import LogoutView
|
||||||
from .generic import IndexView, ProfileView
|
from .generic import IndexView, ProfileView
|
||||||
from .organization import OrganizationCreateView
|
from .organization import OrganizationCreateView, OrganizationDashboardView
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"IndexView",
|
"IndexView",
|
||||||
"LogoutView",
|
"LogoutView",
|
||||||
"OrganizationCreateView",
|
"OrganizationCreateView",
|
||||||
|
"OrganizationDashboardView",
|
||||||
"ProfileView",
|
"ProfileView",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from django.views.generic import FormView
|
from django.views.generic import FormView, TemplateView
|
||||||
|
|
||||||
from servala.frontend.forms import OrganizationCreateForm
|
from servala.frontend.forms import OrganizationCreateForm
|
||||||
|
|
||||||
|
@ -13,3 +13,7 @@ class OrganizationCreateView(FormView):
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return "/"
|
return "/"
|
||||||
|
|
||||||
|
|
||||||
|
class OrganizationDashboardView(TemplateView):
|
||||||
|
template_name = "frontend/organizations/dashboard.html"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue