diff --git a/search/views.py b/search/views.py index dc08930..2b9c69c 100644 --- a/search/views.py +++ b/search/views.py @@ -41,20 +41,20 @@ def search_result(search, type, request): if request.user.has_perms(('perm',)): query = Q(user__username__icontains=search) | Q(user__name__icontains=search) | Q( - user__surname__icontains=search) + user__last_name__icontains=search) else: query = (Q(user__username__icontains=search) | Q(user__name__icontains=search) | Q( - user__surname__icontains=search)) & Q(user=request.user) + user__last_name__icontains=search)) & Q(user=request.user) for i in aff: if i == '0': query_user_list = Q(username__icontains=search) | Q(name__icontains=search) | Q( - surname__icontains=search) & query1 + last_name__icontains=search) & query1 if request.user.has_perms(('perm',)): - recherche['users_list'] = User.objects.filter(query_user_list).order_by('surname') + recherche['users_list'] = User.objects.filter(query_user_list).order_by('last_name') else: recherche['users_list'] = User.objects.filter(query_user_list & Q(id=request.user.id)).order_by( - 'surname') + 'last_name') if i == '1': recherche['emprunts_list'] = Emprunt.objects.filter(query & date_query).order_by('date_emprunt').reverse() if i == '2': @@ -63,7 +63,7 @@ def search_result(search, type, request): if i == '3': recherche['jeux_list'] = Jeu.objects.filter( Q(nom__icontains=search) | Q(proprietaire__username__icontains=search) | Q( - proprietaire__name__icontains=search) | Q(proprietaire__surname__icontains=search)) + proprietaire__name__icontains=search) | Q(proprietaire__last_name__icontains=search)) for r in recherche: if recherche[r] is not None: diff --git a/templates/base.html b/templates/base.html index 20062b1..2f409e5 100644 --- a/templates/base.html +++ b/templates/base.html @@ -111,7 +111,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Nom | -{{ request_user.surname }} | +{{ request_user.last_name }} | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Prénom | diff --git a/users/admin.py b/users/admin.py index 8aadbb3..e873490 100644 --- a/users/admin.py +++ b/users/admin.py @@ -39,11 +39,11 @@ 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 = ('username', 'name', 'surname', 'email', 'is_admin') + list_display = ('username', 'name', 'last_name', 'email', 'is_admin') list_filter = () fieldsets = ( (None, {'fields': ('username', 'password')}), - ('Personal info', {'fields': ('name', 'surname', 'email')}), + ('Personal info', {'fields': ('name', 'last_name', 'email')}), ('Permissions', {'fields': ('is_admin',)}), ) # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin @@ -51,7 +51,7 @@ class UserAdmin(VersionAdmin, BaseUserAdmin): add_fieldsets = ( (None, { 'classes': ('wide',), - 'fields': ('username', 'name', 'surname', 'email', 'is_admin', 'password1', 'password2')} + 'fields': ('username', 'name', 'last_name', 'email', 'is_admin', 'password1', 'password2')} ), ) search_fields = ('username',) diff --git a/users/forms.py b/users/forms.py index 9d66406..b91946b 100644 --- a/users/forms.py +++ b/users/forms.py @@ -28,7 +28,7 @@ class UserCreationForm(forms.ModelForm): class Meta: model = User - fields = ('username', 'name', 'surname', 'email') + fields = ('username', 'name', 'last_name', 'email') def clean_password2(self): # Check that the two password entries match @@ -57,7 +57,7 @@ class UserChangeForm(forms.ModelForm): class Meta: model = User - fields = ('username', 'password', 'name', 'surname', 'email') + fields = ('username', 'password', 'name', 'last_name', 'email') def __init__(self, *args, **kwargs): super(UserChangeForm, self).__init__(*args, **kwargs) @@ -83,7 +83,7 @@ class BaseInfoForm(ModelForm): def __init__(self, *args, **kwargs): super(BaseInfoForm, self).__init__(*args, **kwargs) self.fields['name'].label = 'Prénom' - self.fields['surname'].label = 'Nom' + self.fields['last_name'].label = 'Nom' # self.fields['comment'].label = 'Commentaire' class Meta: @@ -91,7 +91,7 @@ class BaseInfoForm(ModelForm): fields = [ 'name', 'username', - 'surname', + 'last_name', 'email', 'telephone', 'adresse', @@ -103,7 +103,7 @@ class InfoForm(BaseInfoForm): fields = [ 'name', 'username', - 'surname', + 'last_name', 'email', 'telephone', 'adresse', diff --git a/users/migrations/0015_auto_20190802_2143.py b/users/migrations/0015_auto_20190802_2143.py new file mode 100644 index 0000000..3a052c9 --- /dev/null +++ b/users/migrations/0015_auto_20190802_2143.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.22 on 2019-08-02 19:43 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0014_auto_20190802_2126'), + ] + + operations = [ + migrations.RenameField( + model_name='user', + old_name='surname', + new_name='last_name', + ), + ] diff --git a/users/migrations/0016_auto_20190802_2143.py b/users/migrations/0016_auto_20190802_2143.py new file mode 100644 index 0000000..94df909 --- /dev/null +++ b/users/migrations/0016_auto_20190802_2143.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.22 on 2019-08-02 19:43 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0015_auto_20190802_2143'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='last_name', + field=models.CharField(blank=True, max_length=30, verbose_name='last name'), + ), + ] diff --git a/users/migrations/0017_auto_20190802_2144.py b/users/migrations/0017_auto_20190802_2144.py new file mode 100644 index 0000000..482fadb --- /dev/null +++ b/users/migrations/0017_auto_20190802_2144.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.22 on 2019-08-02 19:44 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0016_auto_20190802_2143'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='email', + field=models.EmailField(blank=True, max_length=254, verbose_name='email address'), + ), + ] diff --git a/users/migrations/0018_auto_20190802_2144.py b/users/migrations/0018_auto_20190802_2144.py new file mode 100644 index 0000000..4976f7a --- /dev/null +++ b/users/migrations/0018_auto_20190802_2144.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.22 on 2019-08-02 19:44 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0017_auto_20190802_2144'), + ] + + operations = [ + migrations.RenameField( + model_name='user', + old_name='registered', + new_name='date_joined', + ), + ] diff --git a/users/migrations/0019_auto_20190802_2146.py b/users/migrations/0019_auto_20190802_2146.py new file mode 100644 index 0000000..0bec60b --- /dev/null +++ b/users/migrations/0019_auto_20190802_2146.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.22 on 2019-08-02 19:46 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0018_auto_20190802_2144'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='date_joined', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined'), + ), + ] diff --git a/users/models.py b/users/models.py index 798ce26..66b3415 100644 --- a/users/models.py +++ b/users/models.py @@ -17,7 +17,7 @@ from med.settings import MAX_EMPRUNT, REQ_EXPIRE_HRS class UserManager(BaseUserManager): use_in_migrations = True - def _create_user(self, username, name, surname, email, password=None, su=False): + def _create_user(self, username, name, last_name, email, password=None, su=False): """ Creates and saves a User with the given username, email and password. """ @@ -28,7 +28,7 @@ class UserManager(BaseUserManager): user = self.model( username=username, name=name, - surname=surname, + last_name=last_name, email=email, ) @@ -38,28 +38,27 @@ class UserManager(BaseUserManager): user.make_admin() return user - def create_user(self, username, name, surname, email, password=None): + def create_user(self, username, name, last_name, email, password=None): """ - Creates and saves a User with the given username, name, surname, email, + Creates and saves a User with the given username, name, last_name, email, and password. """ - return self._create_user(username, name, surname, email, password, False) + return self._create_user(username, name, last_name, email, password, False) - def create_superuser(self, username, name, surname, email, password): + def create_superuser(self, username, name, last_name, email, password): """ - Creates and saves a superuser with the given username, name, surname, + Creates and saves a superuser with the given username, name, last_name, email, and password. """ - return self._create_user(username, name, surname, email, password, True) + return self._create_user(username, name, last_name, email, password, True) class User(AbstractBaseUser): username_validator = UnicodeUsernameValidator() if six.PY3 else ASCIIUsernameValidator() - PRETTY_NAME = "Utilisateurs" name = models.CharField(max_length=255) - surname = models.CharField(max_length=255) - email = models.EmailField() + last_name = models.CharField(_('last name'), max_length=30, blank=True) + email = models.EmailField(_('email address'), blank=True) 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") @@ -87,13 +86,14 @@ class User(AbstractBaseUser): 'Unselect this instead of deleting accounts.' ), ) - registered = models.DateTimeField(auto_now_add=True) - - USERNAME_FIELD = 'username' - REQUIRED_FIELDS = ['name', 'surname', 'email'] + date_joined = models.DateTimeField(_('date joined'), default=timezone.now) objects = UserManager() + EMAIL_FIELD = 'email' + USERNAME_FIELD = 'username' + REQUIRED_FIELDS = ['name', 'last_name', 'email'] + @property def is_admin(self): try: @@ -118,7 +118,7 @@ class User(AbstractBaseUser): return False def get_full_name(self): - return '%s %s' % (self.name, self.surname) + return '%s %s' % (self.name, self.last_name) def get_short_name(self): return self.name diff --git a/users/templates/users/aff_users.html b/users/templates/users/aff_users.html index 4bbc047..9c8cb7b 100644 --- a/users/templates/users/aff_users.html +++ b/users/templates/users/aff_users.html @@ -41,7 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for user in users_list %}||||||||||
{{ user.name }} | -{{ user.surname }} | +{{ user.last_name }} | {{ user.username }} | {{ user.email }} | {{ user.maxemprunt }} | diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index cdd85e6..85fec2f 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -61,7 +61,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,Prénom | {{ user.name }} | Nom | -{{ user.surname }} | +{{ user.last_name }} |
Pseudo | @@ -73,7 +73,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,Commentaire | {{ user.comment }} | Date d'inscription | -{{ user.registered }} | +{{ user.date_joined }} | |||||
Adresse | diff --git a/users/views.py b/users/views.py index 6d009da..c4f60ad 100644 --- a/users/views.py +++ b/users/views.py @@ -52,7 +52,7 @@ def reset_passwd_mail(req, request): """ Prend en argument un request, envoie un mail de réinitialisation de mot de pass """ t = loader.get_template('users/email_passwd_request') c = { - 'name': str(req.user.name) + ' ' + str(req.user.surname), + 'name': str(req.user.name) + ' ' + str(req.user.last_name), 'asso': ASSO_NAME, 'asso_mail': ASSO_EMAIL, 'site_name': SITE_NAME,