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.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 .mixins import ServalaModelMixin
|
||||
|
@ -29,6 +32,15 @@ class Organization(ServalaModelMixin, models.Model):
|
|||
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):
|
||||
OrganizationMembership.objects.filter(user=user, organization=self).delete()
|
||||
OrganizationMembership.objects.create(
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<div class="sidebar-header position-relative">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<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="">
|
||||
</a>
|
||||
</div>
|
||||
|
@ -66,7 +66,7 @@
|
|||
{% else %}
|
||||
{# request.user.is_authenticated #}
|
||||
<li class="sidebar-item">
|
||||
{% if user_organizations.count > 1 %}
|
||||
{% if user_organizations.count %}
|
||||
<button class="btn btn-primary dropdown-toggle me-1"
|
||||
type="button"
|
||||
id="organizationDropdown"
|
||||
|
@ -81,11 +81,17 @@
|
|||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="organizationDropdown">
|
||||
{% 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 %}
|
||||
<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>
|
||||
{% elif current_organization %}
|
||||
{% translate "Organization" %}: {{ current_organization.name }}
|
||||
{% else %}
|
||||
<a href="{% url 'frontend:organization.create' %}" class="sidebar-link">
|
||||
<i class="bi bi-plus-square"></i>
|
||||
|
@ -93,12 +99,15 @@
|
|||
</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% if current_organization %}
|
||||
<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>
|
||||
<span>{% translate 'Dashboard' %}</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="sidebar-title">{% translate 'Account' %}</li>
|
||||
<li class="sidebar-item">
|
||||
<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
|
||||
|
||||
|
@ -10,5 +11,17 @@ urlpatterns = [
|
|||
views.OrganizationCreateView.as_view(),
|
||||
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 .generic import IndexView, ProfileView
|
||||
from .organization import OrganizationCreateView
|
||||
from .organization import OrganizationCreateView, OrganizationDashboardView
|
||||
|
||||
__all__ = [
|
||||
"IndexView",
|
||||
"LogoutView",
|
||||
"OrganizationCreateView",
|
||||
"OrganizationDashboardView",
|
||||
"ProfileView",
|
||||
]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from django.views.generic import FormView
|
||||
from django.views.generic import FormView, TemplateView
|
||||
|
||||
from servala.frontend.forms import OrganizationCreateForm
|
||||
|
||||
|
@ -13,3 +13,7 @@ class OrganizationCreateView(FormView):
|
|||
|
||||
def get_success_url(self):
|
||||
return "/"
|
||||
|
||||
|
||||
class OrganizationDashboardView(TemplateView):
|
||||
template_name = "frontend/organizations/dashboard.html"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue