First draft of organization creation
This commit is contained in:
parent
325e767b0e
commit
2baa3fd5ec
8 changed files with 58 additions and 1 deletions
|
@ -27,6 +27,12 @@ class Organization(ServalaModelMixin, models.Model):
|
||||||
verbose_name=_("Members"),
|
verbose_name=_("Members"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def set_owner(self, user):
|
||||||
|
OrganizationMembership.objects.filter(user=user, organization=self).delete()
|
||||||
|
OrganizationMembership.objects.create(
|
||||||
|
user=user, organization=self, role=OrganizationRole.OWNER
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("Organization")
|
verbose_name = _("Organization")
|
||||||
verbose_name_plural = _("Organizations")
|
verbose_name_plural = _("Organizations")
|
||||||
|
|
3
src/servala/frontend/forms/__init__.py
Normal file
3
src/servala/frontend/forms/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from .organization import OrganizationCreateForm
|
||||||
|
|
||||||
|
__all__ = ["OrganizationCreateForm"]
|
9
src/servala/frontend/forms/organization.py
Normal file
9
src/servala/frontend/forms/organization.py
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
from django.forms import ModelForm
|
||||||
|
|
||||||
|
from servala.core.models import Organization
|
||||||
|
|
||||||
|
|
||||||
|
class OrganizationCreateForm(ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Organization
|
||||||
|
fields = ("name",)
|
|
@ -0,0 +1,16 @@
|
||||||
|
{% extends "frontend/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% block html_title %}
|
||||||
|
{% block page_title %}
|
||||||
|
{% translate "Create a new organization" %}
|
||||||
|
{% endblock page_title %}
|
||||||
|
{% endblock html_title %}
|
||||||
|
{% block content %}
|
||||||
|
<section class="section">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-content">
|
||||||
|
<div class="card-body">{% include "includes/form.html" %}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{% endblock content %}
|
|
@ -87,7 +87,7 @@
|
||||||
{% elif current_organization %}
|
{% elif current_organization %}
|
||||||
{% translate "Organization" %}: {{ current_organization.name }}
|
{% translate "Organization" %}: {{ current_organization.name }}
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="#TODO" 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>
|
||||||
<span>{% translate "Create organization" %}</span>
|
<span>{% translate "Create organization" %}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -5,5 +5,10 @@ from servala.frontend import views
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("accounts/profile/", views.ProfileView.as_view(), name="profile"),
|
path("accounts/profile/", views.ProfileView.as_view(), name="profile"),
|
||||||
path("accounts/logout/", views.LogoutView.as_view(), name="logout"),
|
path("accounts/logout/", views.LogoutView.as_view(), name="logout"),
|
||||||
|
path(
|
||||||
|
"organizations/create",
|
||||||
|
views.OrganizationCreateView.as_view(),
|
||||||
|
name="organization.create",
|
||||||
|
),
|
||||||
path("", views.IndexView.as_view(), name="index"),
|
path("", views.IndexView.as_view(), name="index"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
from .auth import LogoutView
|
from .auth import LogoutView
|
||||||
from .generic import IndexView, ProfileView
|
from .generic import IndexView, ProfileView
|
||||||
|
from .organization import OrganizationCreateView
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"IndexView",
|
"IndexView",
|
||||||
"LogoutView",
|
"LogoutView",
|
||||||
|
"OrganizationCreateView",
|
||||||
"ProfileView",
|
"ProfileView",
|
||||||
]
|
]
|
||||||
|
|
16
src/servala/frontend/views/organization.py
Normal file
16
src/servala/frontend/views/organization.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
from django.views.generic import FormView
|
||||||
|
|
||||||
|
from servala.frontend.forms import OrganizationCreateForm
|
||||||
|
|
||||||
|
|
||||||
|
class OrganizationCreateView(FormView):
|
||||||
|
form_class = OrganizationCreateForm
|
||||||
|
template_name = "frontend/organizations/create.html"
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
form.save()
|
||||||
|
form.instance.set_owner(self.request.user)
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return "/"
|
Loading…
Add table
Add a link
Reference in a new issue