Remove user states

This commit is contained in:
Alexandre Iooss 2019-08-02 21:14:16 +02:00
parent 0ff7a1ea3b
commit b541f7025c
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
7 changed files with 50 additions and 29 deletions

View File

@ -1,8 +1,8 @@
Django==1.10.7
docutils==0.13.1
Pillow==4.0.0
pytz==2016.7
six==1.10.0
sqlparse==0.2.2
django-reversion==2.0.8
django-bootstrap3==7.1.0
Django==1.11.22
docutils==0.14
Pillow==5.4.1
pytz==2019.1
six==1.12.0
sqlparse==0.2.4
django-reversion==3.0.3
django-bootstrap3==11.1.0

View File

@ -17,7 +17,7 @@ class UserAdmin(admin.ModelAdmin):
'surname',
'pseudo',
'email',
'state'
'is_active'
)
search_fields = ('name', 'surname', 'pseudo')

View File

@ -120,7 +120,7 @@ class PasswordForm(ModelForm):
class StateForm(ModelForm):
class Meta:
model = User
fields = ['state']
fields = ['is_active']
class ClefForm(ModelForm):

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2019-08-02 19:12
from __future__ import unicode_literals
from django.db import migrations
import users.models
class Migration(migrations.Migration):
dependencies = [
('users', '0011_auto_20190802_1831'),
]
operations = [
migrations.AlterModelManagers(
name='user',
managers=[
('objects', users.models.UserManager()),
],
),
migrations.RemoveField(
model_name='user',
name='state',
),
]

View File

@ -14,15 +14,21 @@ from med.settings import MAX_EMPRUNT, REQ_EXPIRE_HRS
class UserManager(BaseUserManager):
def _create_user(self, pseudo, name, surname, email, password=None, su=False):
if not pseudo:
raise ValueError('Users must have an username')
use_in_migrations = True
def _create_user(self, username, name, surname, email, password=None, su=False):
"""
Creates and saves a User with the given username, email and password.
"""
if not username:
raise ValueError('The given username must be set')
email = self.normalize_email(email)
username = self.model.normalize_username(username)
user = self.model(
pseudo=pseudo,
pseudo=username,
name=name,
surname=surname,
email=self.normalize_email(email),
email=email,
)
user.set_password(password)
@ -48,14 +54,6 @@ class UserManager(BaseUserManager):
class User(AbstractBaseUser):
PRETTY_NAME = "Utilisateurs"
STATE_ACTIVE = 0
STATE_DISABLED = 1
STATE_ARCHIVE = 2
STATES = (
(0, 'STATE_ACTIVE'),
(1, 'STATE_DISABLED'),
(2, 'STATE_ARCHIVE'),
)
name = models.CharField(max_length=255)
surname = models.CharField(max_length=255)
@ -63,7 +61,6 @@ class User(AbstractBaseUser):
telephone = models.CharField(max_length=15, null=True, blank=True)
adresse = models.CharField(max_length=255, null=True, blank=True)
maxemprunt = models.IntegerField(default=MAX_EMPRUNT, help_text="Maximum d'emprunts autorisés")
state = models.IntegerField(choices=STATES, default=STATE_ACTIVE)
pseudo = models.CharField(max_length=32, unique=True,
help_text="Doit contenir uniquement des lettres, chiffres, ou tirets. ")
comment = models.CharField(help_text="Commentaire, promo", max_length=255, blank=True)

View File

@ -93,12 +93,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</tr>
<tr>
<th>Statut</th>
{% if user.state == 0 %}
{% if user.is_active %}
<td><font color="green">Actif</font></td>
{% elif user.state == 1 %}
<td><font color="red">Désactivé</font></td>
{% else %}
<td><font color="orange">Archivé</font></td>
<td><font color="red">Désactivé</font></td>
{% endif %}
<th>Dernière connexion</th>
<td>{{ user.last_login }}</td>

View File

@ -377,7 +377,7 @@ def index_adhesion(request):
@permission_required('perm')
def index(request):
""" Affiche l'ensemble des users, need droit admin """
users_list = User.objects.order_by('state', 'name')
users_list = User.objects.order_by('name')
paginator = Paginator(users_list, PAGINATION_NUMBER)
page = request.GET.get('page')
try: