Modification form group pour voir les utilisateurs
This commit is contained in:
@@ -25,7 +25,11 @@ SECRET_KEY = 'django-insecure-j4jd&+4j^t_=@zr(#q@n!8e*58vkql6&_6w-t14ju8pw%ei%^s
|
|||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
|
cfg_dev_mode = False
|
||||||
|
|
||||||
ALLOWED_HOSTS = ["192.168.3.125","rh.ambulance-clerc.ch"]
|
ALLOWED_HOSTS = ["192.168.3.125","rh.ambulance-clerc.ch"]
|
||||||
|
if cfg_dev_mode:
|
||||||
|
ALLOWED_HOSTS.append("127.0.0.1")
|
||||||
CSRF_TRUSTED_ORIGINS = ['https://rh.ambulance-clerc.ch']
|
CSRF_TRUSTED_ORIGINS = ['https://rh.ambulance-clerc.ch']
|
||||||
|
|
||||||
|
|
||||||
@@ -41,6 +45,7 @@ INSTALLED_APPS = [
|
|||||||
'polls.apps.PollsConfig',
|
'polls.apps.PollsConfig',
|
||||||
'vehicles.apps.VehiclesConfig',
|
'vehicles.apps.VehiclesConfig',
|
||||||
'collabs.apps.CollabsConfig',
|
'collabs.apps.CollabsConfig',
|
||||||
|
'custom_admin.apps.CustomAdminConfig',
|
||||||
'rangefilter',
|
'rangefilter',
|
||||||
|
|
||||||
|
|
||||||
@@ -80,23 +85,22 @@ WSGI_APPLICATION = 'Reskreen.wsgi.application'
|
|||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
||||||
|
|
||||||
|
if cfg_dev_mode:
|
||||||
"""
|
DATABASES = {
|
||||||
DATABASES = {
|
'default': {
|
||||||
'default': {
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
'NAME': BASE_DIR / 'db.sqlite3',
|
||||||
'NAME': BASE_DIR / 'db.sqlite3',
|
}
|
||||||
}
|
}
|
||||||
}
|
else:
|
||||||
"""
|
DATABASES = {
|
||||||
DATABASES = {
|
'default': {
|
||||||
'default': {
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
'ENGINE': 'django.db.backends.mysql',
|
'OPTIONS': {
|
||||||
'OPTIONS': {
|
'read_default_file': 'my.cnf',
|
||||||
'read_default_file': 'my.cnf',
|
},
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
|
0
custom_admin/__init__.py
Normal file
0
custom_admin/__init__.py
Normal file
44
custom_admin/admin.py
Normal file
44
custom_admin/admin.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
from django import forms
|
||||||
|
from django.contrib import admin
|
||||||
|
from django.contrib.auth.admin import GroupAdmin as origGroupAdmin
|
||||||
|
from django.contrib.auth.models import Group, User
|
||||||
|
|
||||||
|
|
||||||
|
class GroupAdminForm(forms.ModelForm):
|
||||||
|
"""
|
||||||
|
ModelForm that adds an additional multiple select field for managing
|
||||||
|
the users in the group.
|
||||||
|
"""
|
||||||
|
users = forms.ModelMultipleChoiceField(
|
||||||
|
User.objects.all(),
|
||||||
|
widget=admin.widgets.FilteredSelectMultiple('Users', False),
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(GroupAdminForm, self).__init__(*args, **kwargs)
|
||||||
|
if self.instance.pk:
|
||||||
|
initial_users = self.instance.user_set.values_list('pk', flat=True)
|
||||||
|
self.initial['users'] = initial_users
|
||||||
|
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
kwargs['commit'] = True
|
||||||
|
return super(GroupAdminForm, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def save_m2m(self):
|
||||||
|
self.instance.user_set.clear()
|
||||||
|
self.instance.user_set.add(*self.cleaned_data['users'])
|
||||||
|
|
||||||
|
|
||||||
|
class GroupAdmin(origGroupAdmin):
|
||||||
|
"""
|
||||||
|
Customized GroupAdmin class that uses the customized form to allow
|
||||||
|
management of users within a group.
|
||||||
|
"""
|
||||||
|
form = GroupAdminForm
|
||||||
|
admin.site.unregister(Group)
|
||||||
|
admin.site.register(Group, GroupAdmin)
|
6
custom_admin/apps.py
Normal file
6
custom_admin/apps.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class CustomAdminConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'custom_admin'
|
Reference in New Issue
Block a user