Make broken accounts without profile deletable
Fix company name handling
This commit is contained in:
parent
fbfbc0feeb
commit
b68475f813
3 changed files with 34 additions and 12 deletions
11
core/templatetags/profiles.py
Normal file
11
core/templatetags/profiles.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
from django import template
|
||||||
|
|
||||||
|
from core.models.profiles import ClientProfile
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
@register.simple_tag()
|
||||||
|
def is_client(user):
|
||||||
|
if isinstance(user.profile, ClientProfile):
|
||||||
|
return True
|
||||||
|
return False
|
|
@ -4,7 +4,7 @@ from django.contrib.auth import get_user_model
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from core.models import AdminProfile, ClientProfile, ClientGroup
|
from core.models import AdminProfile, ClientProfile, ClientGroup, Profile
|
||||||
from core.forms.profiles import AdminEditForm, AdminCreateForm, ClientEditForm, ClientCreateForm
|
from core.forms.profiles import AdminEditForm, AdminCreateForm, ClientEditForm, ClientCreateForm
|
||||||
from core.views.backend.generic import BackendFormView, BackendListView, BackendDeleteView, BackendUpdateView, BackendCreateView
|
from core.views.backend.generic import BackendFormView, BackendListView, BackendDeleteView, BackendUpdateView, BackendCreateView
|
||||||
from core.helpers.auth import request_password
|
from core.helpers.auth import request_password
|
||||||
|
@ -13,7 +13,7 @@ from core.helpers.auth import request_password
|
||||||
|
|
||||||
class AdminListView(BackendListView):
|
class AdminListView(BackendListView):
|
||||||
template_name = f"{settings.EXPEPHALON_BACKEND}/profiles/index.html"
|
template_name = f"{settings.EXPEPHALON_BACKEND}/profiles/index.html"
|
||||||
model = AdminProfile
|
model = get_user_model()
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
@ -76,7 +76,11 @@ class AdminDeleteView(BackendDeleteView):
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None):
|
||||||
admin = super().get_object(queryset=queryset)
|
admin = super().get_object(queryset=queryset)
|
||||||
assert type(admin.profile) == AdminProfile
|
try:
|
||||||
|
assert type(admin.profile) == AdminProfile
|
||||||
|
except Profile.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
return admin
|
return admin
|
||||||
|
|
||||||
class AdminCreateView(BackendFormView):
|
class AdminCreateView(BackendFormView):
|
||||||
|
@ -108,7 +112,7 @@ class AdminCreateView(BackendFormView):
|
||||||
|
|
||||||
request_password(admin)
|
request_password(admin)
|
||||||
|
|
||||||
messages.success(self.request, f"User {admin.get_full_name} was successfully created. They should receive an email to set their password shortly.")
|
messages.success(self.request, f"User {admin.get_full_name()} was successfully created. They should receive an email to set their password shortly.")
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
@ -166,6 +170,8 @@ class ClientEditView(BackendFormView):
|
||||||
client.last_name = form.cleaned_data["last_name"]
|
client.last_name = form.cleaned_data["last_name"]
|
||||||
client.username = form.cleaned_data["email"]
|
client.username = form.cleaned_data["email"]
|
||||||
client.email = form.cleaned_data["email"]
|
client.email = form.cleaned_data["email"]
|
||||||
|
|
||||||
|
client.profile.company = form.cleaned_data["company"]
|
||||||
client.profile.mobile = form.cleaned_data["mobile"]
|
client.profile.mobile = form.cleaned_data["mobile"]
|
||||||
client.profile.address1 = form.cleaned_data["address1"]
|
client.profile.address1 = form.cleaned_data["address1"]
|
||||||
client.profile.address2 = form.cleaned_data["address2"]
|
client.profile.address2 = form.cleaned_data["address2"]
|
||||||
|
@ -219,6 +225,7 @@ class ClientCreateView(BackendFormView):
|
||||||
|
|
||||||
profile = ClientProfile()
|
profile = ClientProfile()
|
||||||
profile.user = client
|
profile.user = client
|
||||||
|
profile.company = form.cleaned_data["company"]
|
||||||
profile.mobile = form.cleaned_data["mobile"]
|
profile.mobile = form.cleaned_data["mobile"]
|
||||||
profile.address1 = form.cleaned_data["address1"]
|
profile.address1 = form.cleaned_data["address1"]
|
||||||
profile.address2 = form.cleaned_data["address2"]
|
profile.address2 = form.cleaned_data["address2"]
|
||||||
|
@ -242,7 +249,7 @@ class ClientCreateView(BackendFormView):
|
||||||
if form.cleaned_data["send_password"]:
|
if form.cleaned_data["send_password"]:
|
||||||
request_password(client)
|
request_password(client)
|
||||||
|
|
||||||
messages.success(self.request, f"Client {client.get_full_name} was successfully created. They should receive an email to set their password shortly.")
|
messages.success(self.request, f"Client {client.get_full_name()} was successfully created." + (" They should receive an email to set their password shortly." if form.cleaned_data["send_password"] else ""))
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{% extends "backend/base.html" %}
|
{% extends "backend/base.html" %}
|
||||||
|
{% load profiles %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="app-page-title">
|
<div class="app-page-title">
|
||||||
<div class="page-title-wrapper">
|
<div class="page-title-wrapper">
|
||||||
|
@ -45,15 +46,18 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for admin in object_list %}
|
{% for user in object_list %}
|
||||||
|
{% is_client user as client %}
|
||||||
|
{% if not client %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ admin.user.first_name }}</td>
|
<td>{{ user.first_name }}</td>
|
||||||
<td>{{ admin.user.last_name }}</td>
|
<td>{{ user.last_name }}</td>
|
||||||
<td>{{ admin.role }}</td>
|
<td>{{ user.profile.role }}</td>
|
||||||
<td>{{ admin.user.username }}</td>
|
<td>{{ user.username }}</td>
|
||||||
<td>{{ admin.mobile }}</td>
|
<td>{{ user.profile.mobile }}</td>
|
||||||
<td><a href="{% url "admins_edit" admin.user.id %}"><i class="fas fa-edit" title="Edit Administrator"></i></a> <a href="{% url "admins_delete" admin.user.id %}"><i style="color: darkred;" class="fas fa-trash-alt" title="Delete Administrator"></i></a></td>
|
<td><a href="{% url "admins_edit" user.id %}"><i class="fas fa-edit" title="Edit Administrator"></i></a> <a href="{% url "admins_delete" user.id %}"><i style="color: darkred;" class="fas fa-trash-alt" title="Delete Administrator"></i></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in a new issue