Login and registration #10

Merged
rixx merged 38 commits from 5-authentication into main 2025-03-20 09:20:55 +00:00
8 changed files with 58 additions and 1 deletions
Showing only changes of commit 2baa3fd5ec - Show all commits

View file

@ -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")

View file

@ -0,0 +1,3 @@
from .organization import OrganizationCreateForm
__all__ = ["OrganizationCreateForm"]

View 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",)

View file

@ -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 %}

View file

@ -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>

View file

@ -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"),
] ]

View file

@ -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",
] ]

View 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 "/"