Add organization edit view
This commit is contained in:
parent
7f3bd159cb
commit
b6571ede2c
7 changed files with 101 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
||||||
from .organization import OrganizationCreateForm
|
from .organization import OrganizationForm
|
||||||
from .profile import UserProfileForm
|
from .profile import UserProfileForm
|
||||||
|
|
||||||
__all__ = ["OrganizationCreateForm", "UserProfileForm"]
|
__all__ = ["OrganizationForm", "UserProfileForm"]
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
from django.forms import ModelForm
|
from django.forms import ModelForm
|
||||||
|
|
||||||
from servala.core.models import Organization
|
from servala.core.models import Organization
|
||||||
|
from servala.frontend.forms.mixins import HtmxMixin
|
||||||
|
|
||||||
|
|
||||||
class OrganizationCreateForm(ModelForm):
|
class OrganizationForm(HtmxMixin, ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Organization
|
model = Organization
|
||||||
fields = ("name",)
|
fields = ("name",)
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
{% extends "frontend/base.html" %}
|
||||||
|
{% load i18n static %}
|
||||||
|
{% load partials %}
|
||||||
|
{% block html_title %}
|
||||||
|
{% block page_title %}
|
||||||
|
{% translate "Organization Details" %}
|
||||||
|
{% endblock page_title %}
|
||||||
|
{% endblock html_title %}
|
||||||
|
{% partialdef org-name %}
|
||||||
|
<td>
|
||||||
|
{{ form.instance.name }}
|
||||||
|
<button class="btn btn-primary"
|
||||||
|
hx-get="{{ request.path }}?fragment=org-name-edit&hx-single-field=name"
|
||||||
|
hx-target="closest td"
|
||||||
|
hx-swap="outerHTML">{% translate "Edit" %}</button>
|
||||||
|
</td>
|
||||||
|
{% endpartialdef org-name %}
|
||||||
|
{% partialdef org-name-edit %}
|
||||||
|
<td>
|
||||||
|
<form hx-target="closest td"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
hx-post="{{ request.url }}">
|
||||||
|
<div class="d-flex align-items-baseline">
|
||||||
|
{{ form.name.as_field_group }}
|
||||||
|
<input type="hidden" name="hx-single-field" value="name">
|
||||||
|
<input type="hidden" name="fragment" value="org-name">
|
||||||
|
<button type="submit" class="btn btn-primary mx-1">{% translate "Save" %}</button>
|
||||||
|
<button type="button"
|
||||||
|
class="btn btn-secondary"
|
||||||
|
hx-get="{{ request.path }}?fragment=org-name"
|
||||||
|
hx-target="closest td"
|
||||||
|
hx-swap="outerHTML">{% translate "Cancel" %}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
{% endpartialdef org-name-edit %}
|
||||||
|
{% block card_content %}
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-lg">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th class="w-25">
|
||||||
|
<span class="d-flex mt-2">{% translate "Name" %}</span>
|
||||||
|
</th>
|
||||||
|
{% partial org-name %}
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endblock card_content %}
|
|
@ -103,12 +103,18 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if request.organization %}
|
{% if request.organization %}
|
||||||
<li class="sidebar-item">
|
<li class="sidebar-item">
|
||||||
<a href="{{ request.organization.get_absolute_url }}"
|
<a href="{{ request.organization.urls.base }}" class='sidebar-link'>
|
||||||
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>
|
||||||
|
<li class="sidebar-title">{% translate 'Organization' %}</li>
|
||||||
|
<li class="sidebar-item">
|
||||||
|
<a href="{{ request.organization.urls.details }}" class='sidebar-link'>
|
||||||
|
<i class="bi bi-grid-fill"></i>
|
||||||
|
<span>{% translate 'Details' %}</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li class="sidebar-title">{% translate 'Account' %}</li>
|
<li class="sidebar-title">{% translate 'Account' %}</li>
|
||||||
<li class="sidebar-item">
|
<li class="sidebar-item">
|
||||||
|
|
|
@ -15,6 +15,11 @@ urlpatterns = [
|
||||||
"org/<slug:organization>/",
|
"org/<slug:organization>/",
|
||||||
include(
|
include(
|
||||||
[
|
[
|
||||||
|
path(
|
||||||
|
"details/",
|
||||||
|
views.OrganizationUpdateView.as_view(),
|
||||||
|
name="organization.details",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"",
|
"",
|
||||||
views.OrganizationDashboardView.as_view(),
|
views.OrganizationDashboardView.as_view(),
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
from .auth import LogoutView
|
from .auth import LogoutView
|
||||||
from .generic import IndexView, ProfileView
|
from .generic import IndexView, ProfileView
|
||||||
from .organization import OrganizationCreateView, OrganizationDashboardView
|
from .organization import (
|
||||||
|
OrganizationCreateView,
|
||||||
|
OrganizationDashboardView,
|
||||||
|
OrganizationUpdateView,
|
||||||
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"IndexView",
|
"IndexView",
|
||||||
"LogoutView",
|
"LogoutView",
|
||||||
"OrganizationCreateView",
|
"OrganizationCreateView",
|
||||||
"OrganizationDashboardView",
|
"OrganizationDashboardView",
|
||||||
|
"OrganizationUpdateView",
|
||||||
"ProfileView",
|
"ProfileView",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.views.generic import FormView, TemplateView
|
from django.utils.functional import cached_property
|
||||||
|
from django.views.generic import FormView, TemplateView, UpdateView
|
||||||
|
|
||||||
from servala.frontend.forms import OrganizationCreateForm
|
from servala.core.models import Organization
|
||||||
|
from servala.frontend.forms import OrganizationForm
|
||||||
|
from servala.frontend.views.mixins import HtmxMixin
|
||||||
|
|
||||||
|
|
||||||
class OrganizationCreateView(FormView):
|
class OrganizationCreateView(FormView):
|
||||||
form_class = OrganizationCreateForm
|
form_class = OrganizationForm
|
||||||
template_name = "frontend/organizations/create.html"
|
template_name = "frontend/organizations/create.html"
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
@ -17,3 +20,25 @@ class OrganizationCreateView(FormView):
|
||||||
|
|
||||||
class OrganizationDashboardView(TemplateView):
|
class OrganizationDashboardView(TemplateView):
|
||||||
template_name = "frontend/organizations/dashboard.html"
|
template_name = "frontend/organizations/dashboard.html"
|
||||||
|
|
||||||
|
|
||||||
|
class OrganizationUpdateView(HtmxMixin, UpdateView):
|
||||||
|
template_name = "frontend/organizations/update.html"
|
||||||
|
form_class = OrganizationForm
|
||||||
|
fragments = ("org-name", "org-name-edit")
|
||||||
|
model = Organization
|
||||||
|
context_object_name = "organization"
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return self.request.path
|
||||||
|
|
||||||
|
def get_object(self):
|
||||||
|
return self.request.organization
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def object(self):
|
||||||
|
return self.get_object()
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
form.save()
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue