8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-25 22:22:26 +00:00

Gestion d'un objet club, migrations et requètes sql ecrites à la main

This commit is contained in:
chirac 2017-10-23 03:22:00 +02:00
parent dbac9e9c5f
commit 054016a1d1
5 changed files with 64 additions and 11 deletions

View file

@ -42,7 +42,6 @@ from .forms import ServiceUserChangeForm, ServiceUserCreationForm
class UserAdmin(admin.ModelAdmin):
"""Administration d'un user"""
list_display = (
'name',
'surname',
'pseudo',
'room',
@ -51,7 +50,7 @@ class UserAdmin(admin.ModelAdmin):
'shell',
'state'
)
search_fields = ('name', 'surname', 'pseudo', 'room')
search_fields = ('surname', 'pseudo', 'room')
class LdapUserAdmin(admin.ModelAdmin):
@ -127,7 +126,6 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
# that reference specific fields on auth.User.
list_display = (
'pseudo',
'name',
'surname',
'email',
'school',
@ -142,7 +140,7 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
'Personal info',
{
'fields':
('name', 'surname', 'email', 'school', 'shell', 'uid_number')
('surname', 'email', 'school', 'shell', 'uid_number')
}
),
('Permissions', {'fields': ('is_admin', )}),
@ -156,7 +154,6 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
'classes': ('wide',),
'fields': (
'pseudo',
'name',
'surname',
'email',
'school',

View file

@ -41,7 +41,7 @@ from django.utils import timezone
from preferences.models import OptionalUser
from .models import User, ServiceUser, Right, School, ListRight, Whitelist
from .models import Ban, remove_user_room
from .models import Ban, remove_user_room, Adherent, Club
NOW = timezone.now()
@ -100,7 +100,7 @@ class UserCreationForm(forms.ModelForm):
class Meta:
model = User
fields = ('pseudo', 'name', 'surname', 'email')
fields = ('pseudo', 'surname', 'email')
def clean_password2(self):
"""Verifie que password1 et 2 sont identiques"""
@ -180,7 +180,7 @@ class UserChangeForm(forms.ModelForm):
class Meta:
model = User
fields = ('pseudo', 'password', 'name', 'surname', 'email')
fields = ('pseudo', 'password', 'surname', 'email')
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
@ -268,7 +268,7 @@ class BaseInfoForm(ModelForm):
self.fields['school'].empty_label = "Séléctionner un établissement"
class Meta:
model = User
model = Adherent
fields = [
'name',
'surname',

View file

@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-10-23 01:01
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('users', '0056_auto_20171015_2033'),
]
operations = [
migrations.CreateModel(
name='Adherent',
fields=[
('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)),
('usname', models.CharField(max_length=255)),
],
options={
'abstract': False,
},
bases=('users.user',),
),
migrations.CreateModel(
name='Club',
fields=[
('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
bases=('users.user',),
),
migrations.RunSQL("insert into users_adherent (user_ptr_id, usname) select id, name from users_user", reverse_sql="insert into users_user (name) select usname from users_adherent"),
migrations.RemoveField(
model_name='user',
name='name',
),
migrations.RenameField(
model_name='adherent',
old_name='usname',
new_name='name',
),
]

View file

@ -207,7 +207,6 @@ class User(AbstractBaseUser):
"""Renvoie un uid libre"""
return get_fresh_user_uid()
name = models.CharField(max_length=255)
surname = models.CharField(max_length=255)
pseudo = models.CharField(
max_length=32,
@ -683,6 +682,15 @@ class User(AbstractBaseUser):
return self.pseudo
class Adherent(User):
name = models.CharField(max_length=255)
pass
class Club(User):
pass
@receiver(post_save, sender=User)
def user_post_save(sender, **kwargs):
""" Synchronisation post_save : envoie le mail de bienvenue si creation

View file

@ -53,7 +53,7 @@ from reversion.models import Version
from reversion import revisions as reversion
from users.serializers import MailSerializer
from users.models import User, Right, Ban, Whitelist, School, ListRight
from users.models import Request, ServiceUser
from users.models import Request, ServiceUser, Adherent, Club
from users.forms import DelRightForm, BanForm, WhitelistForm, DelSchoolForm
from users.forms import DelListRightForm, NewListRightForm
from users.forms import InfoForm, BaseInfoForm, StateForm