From 25128b600ebbad203767d9ccc203bc7cb14caf36 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 14 Oct 2017 22:46:21 +0200 Subject: [PATCH] Fix admin pep8 users --- users/admin.py | 101 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 82 insertions(+), 19 deletions(-) diff --git a/users/admin.py b/users/admin.py index 6a1e0e74..0c71064a 100644 --- a/users/admin.py +++ b/users/admin.py @@ -20,6 +20,10 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +""" +Definition des vues pour les admin. Classique, sauf pour users, +où on fait appel à UserChange et ServiceUserChange, forms custom +""" from __future__ import unicode_literals @@ -28,11 +32,15 @@ from django.contrib.auth.models import Group from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from reversion.admin import VersionAdmin -from .models import User, ServiceUser, School, Right, ListRight, ListShell, Ban, Whitelist, Request, LdapUser, LdapServiceUser, LdapServiceUserGroup, LdapUserGroup -from .forms import UserChangeForm, UserCreationForm, ServiceUserChangeForm, ServiceUserCreationForm +from .models import User, ServiceUser, School, Right, ListRight, ListShell +from .models import Ban, Whitelist, Request, LdapUser, LdapServiceUser +from .models import LdapServiceUserGroup, LdapUserGroup +from .forms import UserChangeForm, UserCreationForm +from .forms import ServiceUserChangeForm, ServiceUserCreationForm class UserAdmin(admin.ModelAdmin): + """Administration d'un user""" list_display = ( 'name', 'surname', @@ -43,51 +51,73 @@ class UserAdmin(admin.ModelAdmin): 'shell', 'state' ) - search_fields = ('name','surname','pseudo','room') + search_fields = ('name', 'surname', 'pseudo', 'room') class LdapUserAdmin(admin.ModelAdmin): - list_display = ('name','uidNumber','login_shell') - exclude = ('user_password','sambat_nt_password') + """Administration du ldapuser""" + list_display = ('name', 'uidNumber', 'login_shell') + exclude = ('user_password', 'sambat_nt_password') search_fields = ('name',) + class LdapServiceUserAdmin(admin.ModelAdmin): + """Administration du ldapserviceuser""" list_display = ('name',) exclude = ('user_password',) search_fields = ('name',) + class LdapUserGroupAdmin(admin.ModelAdmin): - list_display = ('name','members','gid') + """Administration du ldapusergroupe""" + list_display = ('name', 'members', 'gid') search_fields = ('name',) + class LdapServiceUserGroupAdmin(admin.ModelAdmin): + """Administration du ldap serviceusergroup""" list_display = ('name',) search_fields = ('name',) + class SchoolAdmin(VersionAdmin): - list_display = ('name',) + """Administration, gestion des écoles""" + pass + class ListRightAdmin(VersionAdmin): + """Gestion de la liste des droits existants + Ne permet pas l'edition du gid (primarykey pour ldap)""" list_display = ('listright',) + class ListShellAdmin(VersionAdmin): - list_display = ('shell',) + """Gestion de la liste des shells coté admin""" + pass + class RightAdmin(VersionAdmin): - list_display = ('user', 'right') + """Gestion de la liste des droits affectés""" + pass + class RequestAdmin(admin.ModelAdmin): + """Gestion des request objet, ticket pour lien de reinit mot de passe""" list_display = ('user', 'type', 'created_at', 'expires_at') + class BanAdmin(VersionAdmin): - list_display = ('user', 'raison', 'date_start', 'date_end') + """Gestion des bannissements""" + pass class WhitelistAdmin(VersionAdmin): - list_display = ('user', 'raison', 'date_start', 'date_end') + """Gestion des whitelist""" + pass class UserAdmin(VersionAdmin, BaseUserAdmin): + """Gestion d'un user : modification des champs perso, mot de passe, etc""" # The forms to add and change user instances form = UserChangeForm add_form = UserCreationForm @@ -95,27 +125,56 @@ class UserAdmin(VersionAdmin, BaseUserAdmin): # The fields to be used in displaying the User model. # These override the definitions on the base UserAdmin # that reference specific fields on auth.User. - list_display = ('pseudo', 'name', 'surname', 'email', 'school', 'is_admin', 'shell') + list_display = ( + 'pseudo', + 'name', + 'surname', + 'email', + 'school', + 'is_admin', + 'shell' + ) list_display = ('pseudo',) list_filter = () fieldsets = ( (None, {'fields': ('pseudo', 'password')}), - ('Personal info', {'fields': ('name', 'surname', 'email', 'school','shell', 'uid_number')}), + ( + 'Personal info', + { + 'fields': + ('name', 'surname', 'email', 'school', 'shell', 'uid_number') + } + ), ('Permissions', {'fields': ('is_admin', )}), ) # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin # overrides get_fieldsets to use this attribute when creating a user. add_fieldsets = ( - (None, { - 'classes': ('wide',), - 'fields': ('pseudo', 'name', 'surname', 'email', 'school', 'is_admin', 'password1', 'password2')} + ( + None, + { + 'classes': ('wide',), + 'fields': ( + 'pseudo', + 'name', + 'surname', + 'email', + 'school', + 'is_admin', + 'password1', + 'password2' + ) + } ), ) search_fields = ('pseudo',) ordering = ('pseudo',) filter_horizontal = () + class ServiceUserAdmin(VersionAdmin, BaseUserAdmin): + """Gestion d'un service user admin : champs personnels, + mot de passe; etc""" # The forms to add and change user instances form = ServiceUserChangeForm add_form = ServiceUserCreationForm @@ -131,15 +190,19 @@ class ServiceUserAdmin(VersionAdmin, BaseUserAdmin): # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin # overrides get_fieldsets to use this attribute when creating a user. add_fieldsets = ( - (None, { - 'classes': ('wide',), - 'fields': ('pseudo', 'password1', 'password2')} + ( + None, + { + 'classes': ('wide',), + 'fields': ('pseudo', 'password1', 'password2') + } ), ) search_fields = ('pseudo',) ordering = ('pseudo',) filter_horizontal = () + admin.site.register(User, UserAdmin) admin.site.register(ServiceUser, ServiceUserAdmin) admin.site.register(LdapUser, LdapUserAdmin)