Merge pull request 'data-institution' (#10) from data-institution into main
Reviewed-on: #10
This commit is contained in:
commit
4453095657
|
@ -8,5 +8,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<a href="{% url 'admin:institution' user.institution.pk %}" class="btn btn-green-admin">
|
||||||
|
{% translate "Institution" %}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h3>{{ subtitle }}</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% load django_bootstrap5 %}
|
||||||
|
<form role="form" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% if form.errors %}
|
||||||
|
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||||
|
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||||
|
<div class="message">
|
||||||
|
{% for field, error in form.errors.items %}
|
||||||
|
{{ error }}<br />
|
||||||
|
{% endfor %}
|
||||||
|
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% bootstrap_form form %}
|
||||||
|
<div class="form-actions-no-box">
|
||||||
|
<a class="btn btn-grey" href="{% url 'admin:panel' %}">{% translate "Cancel" %}</a>
|
||||||
|
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -9,4 +9,5 @@ urlpatterns = [
|
||||||
path("users/new", views.CreateUserView.as_view(), name="new_user"),
|
path("users/new", views.CreateUserView.as_view(), name="new_user"),
|
||||||
path("users/edit/<int:pk>", views.EditUserView.as_view(), name="edit_user"),
|
path("users/edit/<int:pk>", views.EditUserView.as_view(), name="edit_user"),
|
||||||
path("users/delete/<int:pk>", views.DeleteUserView.as_view(), name="delete_user"),
|
path("users/delete/<int:pk>", views.DeleteUserView.as_view(), name="delete_user"),
|
||||||
|
path("institution/<int:pk>", views.InstitutionView.as_view(), name="institution"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,11 +7,19 @@ from django.views.generic.edit import (
|
||||||
UpdateView,
|
UpdateView,
|
||||||
DeleteView,
|
DeleteView,
|
||||||
)
|
)
|
||||||
from dashboard.mixins import DashboardView
|
from dashboard.mixins import DashboardView, Http403
|
||||||
from user.models import User
|
from user.models import User, Institution
|
||||||
|
|
||||||
|
|
||||||
class PanelView(DashboardView, TemplateView):
|
class AdminView(DashboardView):
|
||||||
|
def get(self, *args, **kwargs):
|
||||||
|
response = super().get(*args, **kwargs)
|
||||||
|
if not self.request.user.is_admin:
|
||||||
|
raise Http403
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
class PanelView(AdminView, TemplateView):
|
||||||
template_name = "admin_panel.html"
|
template_name = "admin_panel.html"
|
||||||
title = _("Admin")
|
title = _("Admin")
|
||||||
breadcrumb = _("admin") + " /"
|
breadcrumb = _("admin") + " /"
|
||||||
|
@ -21,7 +29,7 @@ class PanelView(DashboardView, TemplateView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class UsersView(DashboardView, TemplateView):
|
class UsersView(AdminView, TemplateView):
|
||||||
template_name = "admin_users.html"
|
template_name = "admin_users.html"
|
||||||
title = _("Users")
|
title = _("Users")
|
||||||
breadcrumb = _("admin / Users") + " /"
|
breadcrumb = _("admin / Users") + " /"
|
||||||
|
@ -34,7 +42,7 @@ class UsersView(DashboardView, TemplateView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class CreateUserView(DashboardView, CreateView):
|
class CreateUserView(AdminView, CreateView):
|
||||||
template_name = "user.html"
|
template_name = "user.html"
|
||||||
title = _("User")
|
title = _("User")
|
||||||
breadcrumb = _("admin / User") + " /"
|
breadcrumb = _("admin / User") + " /"
|
||||||
|
@ -53,7 +61,7 @@ class CreateUserView(DashboardView, CreateView):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
class DeleteUserView(DashboardView, DeleteView):
|
class DeleteUserView(AdminView, DeleteView):
|
||||||
template_name = "delete_user.html"
|
template_name = "delete_user.html"
|
||||||
title = _("Delete user")
|
title = _("Delete user")
|
||||||
breadcrumb = "admin / Delete user"
|
breadcrumb = "admin / Delete user"
|
||||||
|
@ -70,7 +78,7 @@ class DeleteUserView(DashboardView, DeleteView):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
class EditUserView(DashboardView, UpdateView):
|
class EditUserView(AdminView, UpdateView):
|
||||||
template_name = "user.html"
|
template_name = "user.html"
|
||||||
title = _("Edit user")
|
title = _("Edit user")
|
||||||
breadcrumb = "admin / Edit user"
|
breadcrumb = "admin / Edit user"
|
||||||
|
@ -87,3 +95,24 @@ class EditUserView(DashboardView, UpdateView):
|
||||||
#self.object.set_password(self.object.password)
|
#self.object.set_password(self.object.password)
|
||||||
kwargs = super().get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
|
class InstitutionView(AdminView, UpdateView):
|
||||||
|
template_name = "institution.html"
|
||||||
|
title = _("Edit institution")
|
||||||
|
section = "admin"
|
||||||
|
subtitle = _('Edit institution')
|
||||||
|
model = Institution
|
||||||
|
success_url = reverse_lazy('admin:panel')
|
||||||
|
fields = (
|
||||||
|
"name",
|
||||||
|
"logo",
|
||||||
|
"location",
|
||||||
|
"responsable_person",
|
||||||
|
"supervisor_person"
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
self.object = self.request.user.institution
|
||||||
|
kwargs = super().get_form_kwargs()
|
||||||
|
return kwargs
|
||||||
|
|
Loading…
Reference in New Issue