From cab370421b81cafbc0d6b800f022931969581273 Mon Sep 17 00:00:00 2001 From: Qwann Date: Sun, 23 Jul 2017 16:20:28 +0200 Subject: [PATCH] small fixes --- evenementiel/settings/common.py | 2 + event/migrations/0002_auto_20170723_1419.py | 21 ++++++++++ event/models.py | 5 ++- users/migrations/0001_initial.py | 46 +++++++++++++++++++++ users/models.py | 17 +++++++- users/tests.py | 34 --------------- 6 files changed, 89 insertions(+), 36 deletions(-) create mode 100644 event/migrations/0002_auto_20170723_1419.py create mode 100644 users/migrations/0001_initial.py delete mode 100644 users/tests.py diff --git a/evenementiel/settings/common.py b/evenementiel/settings/common.py index 5d291cb..ea71e41 100644 --- a/evenementiel/settings/common.py +++ b/evenementiel/settings/common.py @@ -79,6 +79,8 @@ MEDIA_URL = "/media/" LOGIN_REDIRECT_URL = 'shared:home' LOGOUT_REDIRECT_URL = 'shared:home' +AUTH_USER_MODEL = "users.User" + TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', diff --git a/event/migrations/0002_auto_20170723_1419.py b/event/migrations/0002_auto_20170723_1419.py new file mode 100644 index 0000000..954dc74 --- /dev/null +++ b/event/migrations/0002_auto_20170723_1419.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2017-07-23 14:19 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('event', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='activity', + name='parent', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='event.ActivityTemplate'), + ), + ] diff --git a/event/models.py b/event/models.py index 36dca46..66db679 100644 --- a/event/models.py +++ b/event/models.py @@ -1,10 +1,12 @@ -from django.contrib.auth.models import User +from django.contrib.auth import get_user_model from django.utils.translation import ugettext_lazy as _ from django.core.validators import RegexValidator from django.core.exceptions import FieldError from django.db import models from communication.models import SubscriptionMixin +User = get_user_model() + class Event(SubscriptionMixin, models.Model): title = models.CharField( @@ -164,6 +166,7 @@ class Activity(AbstractActivityTemplate): parent = models.ForeignKey( ActivityTemplate, related_name="children", + blank=True, ) staff = models.ManyToManyField( User, diff --git a/users/migrations/0001_initial.py b/users/migrations/0001_initial.py new file mode 100644 index 0000000..bd0ea70 --- /dev/null +++ b/users/migrations/0001_initial.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2017-07-23 14:14 +from __future__ import unicode_literals + +import django.contrib.auth.models +import django.contrib.auth.validators +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('auth', '0008_alter_user_username_max_length'), + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), + ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), + ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), + ('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')), + ('last_name', models.CharField(blank=True, max_length=30, verbose_name='last name')), + ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), + ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), + ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), + ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), + ('phone', models.CharField(blank=True, max_length=20, verbose_name='numéro de téléphone')), + ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), + ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), + ], + options={ + 'verbose_name': 'utilisateur', + 'verbose_name_plural': 'utilisateurs', + }, + managers=[ + ('objects', django.contrib.auth.models.UserManager()), + ], + ), + ] diff --git a/users/models.py b/users/models.py index 85206e0..201983c 100644 --- a/users/models.py +++ b/users/models.py @@ -1,2 +1,17 @@ from django.db import models -from django.contrib.auth.models import User +from django.contrib.auth.models import AbstractUser, UserManager +from django.utils.translation import ugettext_lazy as _ + + +class User(AbstractUser): + phone = models.CharField( + _('numéro de téléphone'), + max_length=20, + blank=True, + ) + + objects = UserManager() + + class Meta: + verbose_name = _("utilisateur") + verbose_name_plural = _("utilisateurs") diff --git a/users/tests.py b/users/tests.py deleted file mode 100644 index adf62a8..0000000 --- a/users/tests.py +++ /dev/null @@ -1,34 +0,0 @@ -from django.test import TestCase, Client -from django.conf import settings -from django.contrib.auth.models import User - - -class TestUserCreation(TestCase): - def test_create_view(self): - """Create a user using the user creation form""" - user_data = { - "username": "MrsFoobar", - "first_name": "Baz", - "last_name": "Foobar", - "email": "baz@foobar.net", - } - - data = user_data.copy() - data["password1"] = "4zwY5jdI" - data["password2"] = "4zwY5jdI" - data["key"] = settings.CREATE_USER_KEY - - client = Client() - resp = client.post("/user/create/", data) - - # The user redirection means successful form validation - self.assertRedirects(resp, "/") - - # The user should now exist - user = ( - User.objects - .filter(username=data["username"]) - .values(*user_data.keys()) - .get() - ) - self.assertEqual(user_data, user)