Compare commits
No commits in common. "2dcc5650a99a4400d9bbbe68e52bdab532e2b816" and "dcbf98f82951746ee9bdb0efc8d8e5e5d0fa12b3" have entirely different histories.
2dcc5650a9
...
dcbf98f829
23 changed files with 73 additions and 335 deletions
|
@ -1,22 +0,0 @@
|
||||||
from django.shortcuts import get_object_or_404
|
|
||||||
from django.urls import resolve
|
|
||||||
|
|
||||||
from servala.core.models import Organization
|
|
||||||
|
|
||||||
|
|
||||||
class OrganizationMiddleware:
|
|
||||||
|
|
||||||
def __init__(self, get_response):
|
|
||||||
self.get_response = get_response
|
|
||||||
|
|
||||||
def __call__(self, request):
|
|
||||||
url = resolve(request.path_info)
|
|
||||||
|
|
||||||
organization_slug = url.kwargs.get("organization")
|
|
||||||
if organization_slug:
|
|
||||||
pk = organization_slug.rsplit("-", maxsplit=1)[-1]
|
|
||||||
request.organization = get_object_or_404(Organization, pk=pk)
|
|
||||||
else:
|
|
||||||
request.organization = None
|
|
||||||
|
|
||||||
return self.get_response(request)
|
|
|
@ -1,25 +0,0 @@
|
||||||
# Generated by Django 5.2b1 on 2025-03-20 08:12
|
|
||||||
|
|
||||||
import django.db.models.deletion
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("core", "0002_billingentity_created_at_billingentity_updated_at_and_more"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name="organization",
|
|
||||||
name="billing_entity",
|
|
||||||
field=models.ForeignKey(
|
|
||||||
null=True,
|
|
||||||
on_delete=django.db.models.deletion.PROTECT,
|
|
||||||
related_name="organizations",
|
|
||||||
to="core.billingentity",
|
|
||||||
verbose_name="Billing entity",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,8 +1,5 @@
|
||||||
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
|
||||||
|
@ -16,7 +13,6 @@ class Organization(ServalaModelMixin, models.Model):
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
related_name="organizations",
|
related_name="organizations",
|
||||||
verbose_name=_("Billing entity"),
|
verbose_name=_("Billing entity"),
|
||||||
null=True, # TODO: billing entity should be required
|
|
||||||
)
|
)
|
||||||
origin = models.ForeignKey(
|
origin = models.ForeignKey(
|
||||||
to="OrganizationOrigin",
|
to="OrganizationOrigin",
|
||||||
|
@ -32,15 +28,6 @@ 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(
|
||||||
|
|
|
@ -2,4 +2,4 @@ def add_organizations(request):
|
||||||
if not request.user.is_authenticated:
|
if not request.user.is_authenticated:
|
||||||
return {"user_organizations": []}
|
return {"user_organizations": []}
|
||||||
|
|
||||||
return {"user_organizations": request.user.organizations.all().order_by("name")}
|
return {"user_organizations": request.user.organizations.all()}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from .organization import OrganizationCreateForm
|
from .organization import OrganizationCreateForm
|
||||||
from .profile import UserProfileForm
|
|
||||||
|
|
||||||
__all__ = ["OrganizationCreateForm", "UserProfileForm"]
|
__all__ = ["OrganizationCreateForm"]
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
from servala.frontend.forms.renderers import InlineFormRenderer
|
|
||||||
|
|
||||||
|
|
||||||
class HtmxMixin:
|
|
||||||
"""
|
|
||||||
Form mixin that retains only a single field when specified.
|
|
||||||
Useful when sending single fields with htmx.
|
|
||||||
"""
|
|
||||||
|
|
||||||
default_renderer = InlineFormRenderer
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self.single_field = kwargs.pop("single_field", None)
|
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
if self.single_field and self.single_field in self.fields:
|
|
||||||
field = self.fields[self.single_field]
|
|
||||||
self.fields.clear()
|
|
||||||
self.fields[self.single_field] = field
|
|
|
@ -1,11 +0,0 @@
|
||||||
from django import forms
|
|
||||||
|
|
||||||
from servala.core.models import User
|
|
||||||
from servala.frontend.forms.mixins import HtmxMixin
|
|
||||||
|
|
||||||
|
|
||||||
class UserProfileForm(HtmxMixin, forms.ModelForm):
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = User
|
|
||||||
fields = ("email", "company")
|
|
|
@ -1,5 +1,4 @@
|
||||||
from django.forms.renderers import TemplatesSetting
|
from django.forms.renderers import TemplatesSetting
|
||||||
from django.forms.widgets import Textarea
|
|
||||||
|
|
||||||
|
|
||||||
def inject_class(f, class_name):
|
def inject_class(f, class_name):
|
||||||
|
@ -17,31 +16,13 @@ class VerticalFormRenderer(TemplatesSetting):
|
||||||
form_template_name = "frontend/forms/form.html"
|
form_template_name = "frontend/forms/form.html"
|
||||||
field_template_name = "frontend/forms/vertical_field.html"
|
field_template_name = "frontend/forms/vertical_field.html"
|
||||||
|
|
||||||
def get_class_names(self, input_type):
|
|
||||||
if input_type == "checkbox":
|
|
||||||
return "form-check-input"
|
|
||||||
return "form-control"
|
|
||||||
|
|
||||||
def get_widget_input_type(self, widget):
|
|
||||||
if isinstance(widget, Textarea):
|
|
||||||
return "textarea"
|
|
||||||
return widget.input_type
|
|
||||||
|
|
||||||
def get_field_input_type(self, field):
|
|
||||||
widget = field.field.widget
|
|
||||||
if inner_widget := getattr(widget, "widget", None):
|
|
||||||
widget = inner_widget
|
|
||||||
return self.get_widget_input_type(widget)
|
|
||||||
|
|
||||||
def render(self, template_name, context, request=None):
|
def render(self, template_name, context, request=None):
|
||||||
if field := context.get("field"):
|
if field := context.get("field"):
|
||||||
input_type = self.get_field_input_type(field)
|
if field.field.widget.input_type == "checkbox":
|
||||||
|
class_name = "form-check-input"
|
||||||
|
else:
|
||||||
|
class_name = "form-control"
|
||||||
field.build_widget_attrs = inject_class(
|
field.build_widget_attrs = inject_class(
|
||||||
field.build_widget_attrs, self.get_class_names(input_type)
|
field.build_widget_attrs, class_name
|
||||||
)
|
)
|
||||||
return super().render(template_name, context, request)
|
return super().render(template_name, context, request)
|
||||||
|
|
||||||
|
|
||||||
class InlineFormRenderer(VerticalFormRenderer):
|
|
||||||
form_template_name = "frontend/forms/form.html"
|
|
||||||
field_template_name = "frontend/forms/inline_field.html"
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
<link rel="stylesheet"
|
<link rel="stylesheet"
|
||||||
href="{% static 'mazer/compiled/css/app-dark.css' %}">
|
href="{% static 'mazer/compiled/css/app-dark.css' %}">
|
||||||
<link rel="stylesheet" href="{% static 'mazer/compiled/css/iconly.css' %}">
|
<link rel="stylesheet" href="{% static 'mazer/compiled/css/iconly.css' %}">
|
||||||
<link rel="stylesheet" href="{% static 'css/servala.css' %}">
|
|
||||||
<script src="{% static "js/htmx.min.js" %}" defer></script>
|
<script src="{% static "js/htmx.min.js" %}" defer></script>
|
||||||
</head>
|
</head>
|
||||||
<title>
|
<title>
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
{% load i18n %}
|
|
||||||
<div class="form-group{% if field.field.required %} mandatory{% endif %}{% if errors %} is-invalid{% endif %}{% if extra_class %} {{ extra_class }}{% endif %}">
|
|
||||||
{% if not hide_label %}
|
|
||||||
{% if field.field.widget.input_type != "checkbox" or field.field.widget.allow_multiple_selected %}
|
|
||||||
<label for="{{ field.auto_id }}" class="form-label">{{ field.label }}</label>
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
{% if field.use_fieldset %}
|
|
||||||
<fieldset {% if field.help_text and field.auto_id and "aria-describedby" not in field.field.widget.attrs %} aria-describedby="{{ field.auto_id }}_helptext"{% endif %}>
|
|
||||||
{% endif %}
|
|
||||||
{{ field }}
|
|
||||||
{% if field.field.widget.input_type == "checkbox" and not field.field.widget.allow_multiple_selected %}
|
|
||||||
<label for="{{ field.auto_id }}" class="form-check-label form-label">{{ field.label }}</label>
|
|
||||||
{% endif %}
|
|
||||||
{% if field.use_fieldset %}</fieldset>{% endif %}
|
|
||||||
{% for text in field.errors %}<div class="invalid-feedback">{{ text }}</div>{% endfor %}
|
|
||||||
{% if field.help_text %}
|
|
||||||
<small class="form-text text-muted"
|
|
||||||
{% if field.auto_id %}id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</small>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
|
@ -1 +0,0 @@
|
||||||
{% include "frontend/forms/field.html" with extra_class="d-inline" hide_label=True %}
|
|
|
@ -1 +1,21 @@
|
||||||
<div class="col-12">{% include "frontend/forms/field.html" %}</div>
|
{% load i18n %}
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="form-group{% if field.field.required %} mandatory{% endif %}{% if errors %} is-invalid{% endif %}">
|
||||||
|
{% if field.field.widget.input_type != "checkbox" or field.field.widget.allow_multiple_selected %}
|
||||||
|
<label for="{{ field.auto_id }}" class="form-label">{{ field.label }}</label>
|
||||||
|
{% endif %}
|
||||||
|
{% if field.use_fieldset %}
|
||||||
|
<fieldset {% if field.help_text and field.auto_id and "aria-describedby" not in field.field.widget.attrs %} aria-describedby="{{ field.auto_id }}_helptext"{% endif %}>
|
||||||
|
{% endif %}
|
||||||
|
{{ field }}
|
||||||
|
{% if field.field.widget.input_type == "checkbox" and not field.field.widget.allow_multiple_selected %}
|
||||||
|
<label for="{{ field.auto_id }}" class="form-check-label form-label">{{ field.label }}</label>
|
||||||
|
{% endif %}
|
||||||
|
{% if field.use_fieldset %}</fieldset>{% endif %}
|
||||||
|
{% for text in field.errors %}<div class="invalid-feedback">{{ text }}</div>{% endfor %}
|
||||||
|
{% if field.help_text %}
|
||||||
|
<small class="form-text text-muted"
|
||||||
|
{% if field.auto_id %}id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</small>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
{% extends "frontend/base.html" %}
|
{% extends "frontend/base.html" %}
|
||||||
{% load i18n static %}
|
{% load i18n static %}
|
||||||
{% load partials %}
|
|
||||||
{% block html_title %}
|
{% block html_title %}
|
||||||
{% block page_title %}
|
{% block page_title %}
|
||||||
{% translate "Profile" %}
|
{% translate "Profile" %}
|
||||||
|
@ -11,62 +10,6 @@
|
||||||
<h4 class="card-title">{% translate "Account" %}</h4>
|
<h4 class="card-title">{% translate "Account" %}</h4>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% partialdef user-email %}
|
|
||||||
<td>
|
|
||||||
{{ request.user.email }}
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
hx-get="{% url 'frontend:profile' %}?fragment=user-email-edit"
|
|
||||||
hx-target="closest td"
|
|
||||||
hx-swap="outerHTML">{% translate "Edit" %}</button>
|
|
||||||
</td>
|
|
||||||
{% endpartialdef user-email %}
|
|
||||||
{% partialdef user-company %}
|
|
||||||
<td>
|
|
||||||
{{ request.user.company|default:"–" }}
|
|
||||||
<button class="btn btn-primary"
|
|
||||||
hx-get="{% url 'frontend:profile' %}?fragment=user-company-edit"
|
|
||||||
hx-target="closest td"
|
|
||||||
hx-swap="outerHTML">{% translate "Edit" %}</button>
|
|
||||||
</td>
|
|
||||||
{% endpartialdef user-company %}
|
|
||||||
{% partialdef user-email-edit %}
|
|
||||||
<td>
|
|
||||||
<form hx-target="closest td"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
hx-post="{{ request.url }}">
|
|
||||||
<div class="d-flex align-items-baseline">
|
|
||||||
{{ form.email.as_field_group }}
|
|
||||||
<input type="hidden" name="hx-single-field" value="email">
|
|
||||||
<input type="hidden" name="fragment" value="user-email">
|
|
||||||
<button type="submit" class="btn btn-primary mx-1">{% translate "Save" %}</button>
|
|
||||||
<button type="button"
|
|
||||||
class="btn btn-secondary"
|
|
||||||
hx-get="{{ request.path }}?fragment=user-email"
|
|
||||||
hx-target="closest td"
|
|
||||||
hx-swap="outerHTML">{% translate "Cancel" %}</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</td>
|
|
||||||
{% endpartialdef %}
|
|
||||||
{% partialdef user-company-edit %}
|
|
||||||
<td>
|
|
||||||
<form hx-target="closest td"
|
|
||||||
hx-swap="outerHTML"
|
|
||||||
hx-post="{{ request.url }}">
|
|
||||||
<div class="d-flex align-items-baseline">
|
|
||||||
{{ form.company.as_field_group }}
|
|
||||||
<input type="hidden" name="hx-single-field" value="company">
|
|
||||||
<input type="hidden" name="fragment" value="user-company">
|
|
||||||
<button type="submit" class="btn mx-1 btn-primary">{% translate "Save" %}</button>
|
|
||||||
<button type="button"
|
|
||||||
class="btn btn-secondary"
|
|
||||||
hx-get="{{ request.path }}?fragment=user-company"
|
|
||||||
hx-target="closest td"
|
|
||||||
hx-swap="outerHTML">{% translate "Cancel" %}</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</td>
|
|
||||||
{% endpartialdef %}
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<section>
|
<section>
|
||||||
<div class="row match-height">
|
<div class="row match-height">
|
||||||
|
@ -81,20 +24,20 @@
|
||||||
<table class="table table-lg">
|
<table class="table table-lg">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-25">{% translate "Name" %}</th>
|
<th>{% translate "E-mail" %}</th>
|
||||||
<td>{{ request.user.first_name }} {{ request.user.last_name }}</td>
|
<td>{{ request.user.email }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-25">
|
<th>{% translate "First name" %}</th>
|
||||||
<span class="d-flex mt-2">{% translate "E-mail" %}</span>
|
<td>{{ request.user.first_name }}</td>
|
||||||
</th>
|
|
||||||
{% partial user-email %}
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-25">
|
<th>{% translate "Last name" %}</th>
|
||||||
<span class="d-flex mt-2">{% translate "Company" %}</span>
|
<td>{{ request.user.last_name }}</td>
|
||||||
</th>
|
</tr>
|
||||||
{% partial user-company %}
|
<tr>
|
||||||
|
<th>{% translate "Company" %}</th>
|
||||||
|
<td>{{ request.user.company }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -5,13 +5,11 @@
|
||||||
{% include "includes/form_errors.html" %}
|
{% include "includes/form_errors.html" %}
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form }}
|
{{ form }}
|
||||||
<div class="col-sm-12 d-flex justify-content-end">
|
<button class="btn btn-primary" type="submit">
|
||||||
<button class="btn btn-primary me-1 mb-1" type="submit">
|
{% if form_submit_label %}
|
||||||
{% if form_submit_label %}
|
{{ form_submit_label }}
|
||||||
{{ form_submit_label }}
|
{% else %}
|
||||||
{% else %}
|
{% translate "Save" %}
|
||||||
{% translate "Save" %}
|
{% endif %}
|
||||||
{% endif %}
|
</button>
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -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="{% if request.organization %}{{ request.organization.get_absolute_url }}{% else %}/{% endif %}">
|
<a href="index.html">
|
||||||
<img src="" alt="{% translate 'Logo' %}" srcset="">
|
<img src="" alt="{% translate 'Logo' %}" srcset="">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -66,34 +66,26 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
{# request.user.is_authenticated #}
|
{# request.user.is_authenticated #}
|
||||||
<li class="sidebar-item">
|
<li class="sidebar-item">
|
||||||
{% if user_organizations.count %}
|
{% if user_organizations.count > 1 %}
|
||||||
<button class="btn btn-outline-primary dropdown-toggle w-100"
|
<button class="btn btn-primary dropdown-toggle me-1"
|
||||||
type="button"
|
type="button"
|
||||||
id="organizationDropdown"
|
id="organizationDropdown"
|
||||||
data-bs-toggle="dropdown"
|
data-bs-toggle="dropdown"
|
||||||
aria-haspopup="true"
|
aria-haspopup="true"
|
||||||
aria-expanded="false">
|
aria-expanded="false">
|
||||||
{% if request.organization %}
|
{% if current_organization %}
|
||||||
{{ request.organization.name }}
|
{{ current_organization.name }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% translate "Organizations" %}
|
{% translate "Organizations" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu shadow"
|
<div class="dropdown-menu" aria-labelledby="organizationDropdown">
|
||||||
aria-labelledby="organizationDropdown"
|
|
||||||
id="organization-dropdown">
|
|
||||||
{% for organization in user_organizations %}
|
{% for organization in user_organizations %}
|
||||||
<a class="dropdown-item{% if organization == request.organization %} active{% endif %}"
|
<a class="dropdown-item" href="#TODO">{{ organization.name }}</a>
|
||||||
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>
|
||||||
|
@ -101,15 +93,12 @@
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
{% if request.organization %}
|
<li class="sidebar-item">
|
||||||
<li class="sidebar-item">
|
<a href="index.html" class='sidebar-link'>
|
||||||
<a href="{{ request.organization.get_absolute_url }}"
|
<i class="bi bi-grid-fill"></i>
|
||||||
class='sidebar-link'>
|
<span>{% translate 'Dashboard' %}</span>
|
||||||
<i class="bi bi-grid-fill"></i>
|
</a>
|
||||||
<span>{% translate 'Dashboard' %}</span>
|
</li>
|
||||||
</a>
|
|
||||||
</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,5 +1,4 @@
|
||||||
from django.urls import include, path
|
from django.urls import path
|
||||||
from django.views.generic import RedirectView
|
|
||||||
|
|
||||||
from servala.frontend import views
|
from servala.frontend import views
|
||||||
|
|
||||||
|
@ -11,17 +10,5 @@ urlpatterns = [
|
||||||
views.OrganizationCreateView.as_view(),
|
views.OrganizationCreateView.as_view(),
|
||||||
name="organization.create",
|
name="organization.create",
|
||||||
),
|
),
|
||||||
path(
|
path("", views.IndexView.as_view(), name="index"),
|
||||||
"<slug:organization>/",
|
|
||||||
include(
|
|
||||||
[
|
|
||||||
path(
|
|
||||||
"",
|
|
||||||
views.OrganizationDashboardView.as_view(),
|
|
||||||
name="organization.dashboard",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
),
|
|
||||||
path("", RedirectView.as_view(pattern_name="frontend:profile"), name="index"),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
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
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"IndexView",
|
"IndexView",
|
||||||
"LogoutView",
|
"LogoutView",
|
||||||
"OrganizationCreateView",
|
"OrganizationCreateView",
|
||||||
"OrganizationDashboardView",
|
|
||||||
"ProfileView",
|
"ProfileView",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,41 +1,21 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.urls import reverse_lazy
|
from django.views.generic import TemplateView
|
||||||
from django.utils.functional import cached_property
|
|
||||||
from django.views.generic import TemplateView, UpdateView
|
|
||||||
|
|
||||||
from servala.core.models import User
|
|
||||||
from servala.frontend.forms.profile import UserProfileForm
|
|
||||||
from servala.frontend.views.mixins import HtmxMixin
|
|
||||||
|
|
||||||
|
|
||||||
class IndexView(TemplateView):
|
class IndexView(TemplateView):
|
||||||
template_name = "frontend/index.html"
|
template_name = "frontend/index.html"
|
||||||
|
|
||||||
|
|
||||||
class ProfileView(HtmxMixin, UpdateView):
|
class ProfileView(TemplateView):
|
||||||
template_name = "frontend/profile.html"
|
template_name = "frontend/profile.html"
|
||||||
form_class = UserProfileForm
|
|
||||||
success_url = reverse_lazy("frontend:profile")
|
|
||||||
fragments = ("user-email", "user-email-edit", "user-company", "user-company-edit")
|
|
||||||
model = User
|
|
||||||
|
|
||||||
def get_object(self):
|
|
||||||
return self.request.user
|
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def object(self):
|
|
||||||
return self.get_object()
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
keycloak_settings = settings.SOCIALACCOUNT_PROVIDERS["openid_connect"]
|
keycloak_server_url = settings.SOCIALACCOUNT_PROVIDERS["openid_connect"][
|
||||||
keycloak_server_url = keycloak_settings["APPS"][0]["settings"]["server_url"]
|
"APPS"
|
||||||
|
][0]["settings"]["server_url"]
|
||||||
account_url = keycloak_server_url.replace(
|
account_url = keycloak_server_url.replace(
|
||||||
"/.well-known/openid-configuration", "/account"
|
"/.well-known/openid-configuration", "/account"
|
||||||
)
|
)
|
||||||
context["account_href"] = account_url
|
context["account_href"] = account_url
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def form_valid(self, form):
|
|
||||||
form.save()
|
|
||||||
return super().form_valid(form)
|
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
from django.utils.functional import cached_property
|
|
||||||
from django.views.generic import TemplateView
|
|
||||||
|
|
||||||
|
|
||||||
class HtmxMixin(TemplateView):
|
|
||||||
fragments = []
|
|
||||||
|
|
||||||
@cached_property
|
|
||||||
def is_htmx(self):
|
|
||||||
return self.request.headers.get("HX-Request")
|
|
||||||
|
|
||||||
def _get_fragment(self):
|
|
||||||
if self.request.method == "POST":
|
|
||||||
fragment = self.request.POST.get("fragment")
|
|
||||||
else:
|
|
||||||
fragment = self.request.GET.get("fragment")
|
|
||||||
if fragment and fragment in self.fragments:
|
|
||||||
return fragment
|
|
||||||
|
|
||||||
def get_template_names(self):
|
|
||||||
template_names = super().get_template_names()
|
|
||||||
if self.is_htmx and (fragment := self._get_fragment()):
|
|
||||||
return [f"{template_names[0]}#{fragment}"]
|
|
||||||
return template_names
|
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
|
||||||
result = super().get_form_kwargs()
|
|
||||||
if self.is_htmx and (field_name := self.request.POST.get("hx-single-field")):
|
|
||||||
result["single_field"] = field_name
|
|
||||||
return result
|
|
||||||
|
|
||||||
def form_valid(self, form):
|
|
||||||
result = super().form_valid(form)
|
|
||||||
if self.is_htmx and self._get_fragment():
|
|
||||||
return self.get(self.request, *self.args, **self.kwargs)
|
|
||||||
return result
|
|
|
@ -1,5 +1,4 @@
|
||||||
from django.shortcuts import redirect
|
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
|
||||||
|
|
||||||
|
@ -9,11 +8,8 @@ class OrganizationCreateView(FormView):
|
||||||
template_name = "frontend/organizations/create.html"
|
template_name = "frontend/organizations/create.html"
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
instance = form.instance.create_organization(
|
form.instance.create_organization(form.instance, owner=self.request.user)
|
||||||
form.instance, owner=self.request.user
|
return super().form_valid(form)
|
||||||
)
|
|
||||||
return redirect(instance.get_absolute_url())
|
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
class OrganizationDashboardView(TemplateView):
|
return "/"
|
||||||
template_name = "frontend/organizations/dashboard.html"
|
|
||||||
|
|
|
@ -116,7 +116,6 @@ MIDDLEWARE = [
|
||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
"allauth.account.middleware.AccountMiddleware",
|
"allauth.account.middleware.AccountMiddleware",
|
||||||
"django.contrib.auth.middleware.LoginRequiredMiddleware",
|
"django.contrib.auth.middleware.LoginRequiredMiddleware",
|
||||||
"servala.core.middleware.OrganizationMiddleware",
|
|
||||||
]
|
]
|
||||||
LOGIN_URL = "account_login"
|
LOGIN_URL = "account_login"
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
.form-group.d-inline {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue