fix messages system
This commit is contained in:
parent
9ad6be8db6
commit
e3ac939afc
|
@ -3,7 +3,7 @@ from django.contrib.auth.models import User
|
|||
|
||||
|
||||
class ProfileForm(forms.ModelForm):
|
||||
MANDATORY_FIELDS = ['first_name', 'last_name', 'email']
|
||||
MANDATORY_FIELDS = ['first_name', 'last_name', 'email', 'username']
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
|
|
|
@ -81,6 +81,10 @@ class AdminPeopleActivateView(AdminPeopleView):
|
|||
self.pk = kwargs['pk']
|
||||
self.object = get_object_or_404(self.model, pk=self.pk)
|
||||
|
||||
if self.object == self.request.user:
|
||||
messages.error(self.request, _('Is not possible deactivate your account!'))
|
||||
return redirect('idhub:admin_people', self.object.id)
|
||||
|
||||
if self.object.is_active:
|
||||
self.object.is_active = False
|
||||
else:
|
||||
|
@ -96,14 +100,17 @@ class AdminPeopleDeleteView(AdminPeopleView):
|
|||
self.pk = kwargs['pk']
|
||||
self.object = get_object_or_404(self.model, pk=self.pk)
|
||||
|
||||
if self.object != self.request.user:
|
||||
self.object.delete()
|
||||
else:
|
||||
messages.error(self.request, _('Is not possible delete your account!'))
|
||||
|
||||
return redirect('idhub:admin_people_list')
|
||||
|
||||
class AdminPeopleEditView(AdminPeopleView, UpdateView):
|
||||
template_name = "idhub/admin_user_edit.html"
|
||||
from_class = ProfileForm
|
||||
fields = ('first_name', 'last_name', 'email')
|
||||
fields = ('first_name', 'last_name', 'email', 'username')
|
||||
success_url = reverse_lazy('idhub:admin_people_list')
|
||||
|
||||
|
||||
|
@ -113,7 +120,7 @@ class AdminPeopleRegisterView(People, CreateView):
|
|||
icon = 'bi bi-person'
|
||||
model = User
|
||||
from_class = ProfileForm
|
||||
fields = ('first_name', 'last_name', 'email')
|
||||
fields = ('first_name', 'last_name', 'email', 'username')
|
||||
success_url = reverse_lazy('idhub:admin_people_list')
|
||||
|
||||
|
||||
|
|
|
@ -13,19 +13,17 @@
|
|||
<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">
|
||||
<button class="close" type="button" data-dismiss="alert" aria-label="Close">
|
||||
<span class="mdi mdi-close" aria-hidden="true"></span>
|
||||
</button>
|
||||
{% for field, error in form.errors.items %}
|
||||
{{ error }}
|
||||
{{ 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-secondary" href="{% url 'idhub:user_profile' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-success" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
<a class="btn btn-grey" href="{% url 'idhub:admin_people_list' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3 class="{% if not object.is_active %}bg-danger text-white{% endif %}">
|
||||
<h3 class="{% if not object.is_active %}alert alert-danger{% endif %}">
|
||||
<i class="{{ icon }}"></i>
|
||||
{{ subtitle }}
|
||||
</h3>
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
{% endif %}
|
||||
{% bootstrap_form form %}
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-secondary" href="{% url 'idhub:user_profile' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-success" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
<a class="btn btn-grey" href="{% url 'idhub:admin_people' object.id %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
|
|
@ -128,10 +128,9 @@
|
|||
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||
{% block messages %}
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-{{ message.tags|default:'info' }} alert-dismissible fade show" role="alert">
|
||||
<div class="alert {{ message.tags|default:'info' }} alert-dismissible fade show mt-3" role="alert">
|
||||
{{ message }}
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
|
|
@ -199,10 +199,9 @@
|
|||
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||
{% block messages %}
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-{{ message.tags|default:'info' }} alert-dismissible fade show" role="alert">
|
||||
<div class="alert {{ message.tags|default:'info' }} alert-dismissible fade show mt-3" role="alert">
|
||||
{{ message }}
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
|
|
@ -11,6 +11,8 @@ https://docs.djangoproject.com/en/4.2/ref/settings/
|
|||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from django.contrib.messages import constants as messages
|
||||
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
@ -125,3 +127,11 @@ STATIC_URL = 'static/'
|
|||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
LOGOUT_REDIRECT_URL = 'idhub:login'
|
||||
|
||||
MESSAGE_TAGS = {
|
||||
messages.DEBUG: 'alert-secondary',
|
||||
messages.INFO: 'alert-info',
|
||||
messages.SUCCESS: 'alert-success',
|
||||
messages.WARNING: 'alert-warning',
|
||||
messages.ERROR: 'alert-danger',
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue