diff --git a/admin/templates/admin_users.html b/admin/templates/admin_users.html
index 9f3cd32..37fbf96 100644
--- a/admin/templates/admin_users.html
+++ b/admin/templates/admin_users.html
@@ -6,14 +6,33 @@
{{ subtitle }}
+
- {% for u in users %}
- {{ u.email }}
- {{ u.is_admin }}
- {% endfor %}
+
+
+
+ Email |
+ is Admin |
+ |
+ |
+
+
+
+
+ {% for u in users %}
+ {{ u.email }} |
+ {{ u.is_admin }} |
+ |
+ |
+
+ {% endfor %}
+
+
diff --git a/admin/templates/delete_user.html b/admin/templates/delete_user.html
new file mode 100644
index 0000000..5aa402d
--- /dev/null
+++ b/admin/templates/delete_user.html
@@ -0,0 +1,38 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block content %}
+
+
+{% load django_bootstrap5 %}
+
+
+ Are you sure than want remove the lot {{ object.name }} with {{ object.devices.count }} devices.
+
+
+
+
+{% endblock %}
diff --git a/admin/templates/user.html b/admin/templates/user.html
new file mode 100644
index 0000000..1ea00d8
--- /dev/null
+++ b/admin/templates/user.html
@@ -0,0 +1,32 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block content %}
+
+
+{% load django_bootstrap5 %}
+
+{% endblock %}
diff --git a/admin/urls.py b/admin/urls.py
index 6a9d492..cd79c3f 100644
--- a/admin/urls.py
+++ b/admin/urls.py
@@ -6,4 +6,7 @@ app_name = 'admin'
urlpatterns = [
path("panel/", views.PanelView.as_view(), name="panel"),
path("users/", views.UsersView.as_view(), name="users"),
+ path("users/new", views.CreateUserView.as_view(), name="new_user"),
+ path("users/edit/", views.EditUserView.as_view(), name="edit_user"),
+ path("users/delete/", views.DeleteUserView.as_view(), name="delete_user"),
]
diff --git a/admin/views.py b/admin/views.py
index e95c8c2..bcc8889 100644
--- a/admin/views.py
+++ b/admin/views.py
@@ -1,5 +1,12 @@
+from django.urls import reverse_lazy
+from django.shortcuts import get_object_or_404
from django.utils.translation import gettext_lazy as _
from django.views.generic.base import TemplateView
+from django.views.generic.edit import (
+ CreateView,
+ UpdateView,
+ DeleteView,
+)
from dashboard.mixins import DashboardView
from user.models import User
@@ -25,3 +32,58 @@ class UsersView(DashboardView, TemplateView):
"users": User.objects.filter()
})
return context
+
+
+class CreateUserView(DashboardView, CreateView):
+ template_name = "user.html"
+ title = _("User")
+ breadcrumb = _("admin / User") + " /"
+ success_url = reverse_lazy('admin:users')
+ model = User
+ fields = (
+ "email",
+ "password",
+ "is_admin",
+ )
+
+ def form_valid(self, form):
+ form.instance.institution = self.request.user.institution
+ form.instance.set_password(form.instance.password)
+ response = super().form_valid(form)
+ return response
+
+
+class DeleteUserView(DashboardView, DeleteView):
+ template_name = "delete_user.html"
+ title = _("Delete user")
+ breadcrumb = "admin / Delete user"
+ success_url = reverse_lazy('admin:users')
+ model = User
+ fields = (
+ "email",
+ "password",
+ "is_admin",
+ )
+
+ def form_valid(self, form):
+ response = super().form_valid(form)
+ return response
+
+
+class EditUserView(DashboardView, UpdateView):
+ template_name = "user.html"
+ title = _("Edit user")
+ breadcrumb = "admin / Edit user"
+ success_url = reverse_lazy('admin:users')
+ model = User
+ fields = (
+ "email",
+ "is_admin",
+ )
+
+ def get_form_kwargs(self):
+ pk = self.kwargs.get('pk')
+ self.object = get_object_or_404(self.model, pk=pk)
+ #self.object.set_password(self.object.password)
+ kwargs = super().get_form_kwargs()
+ return kwargs