8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-26 00:43:46 +00:00

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

This commit is contained in:
Gabriel Detraz 2017-10-23 03:22:00 +02:00
parent a6c29c6f42
commit 5bdf4d6083
5 changed files with 64 additions and 11 deletions

View file

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

View file

@ -41,7 +41,7 @@ from django.utils import timezone
from preferences.models import OptionalUser from preferences.models import OptionalUser
from .models import User, ServiceUser, Right, School, ListRight, Whitelist 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() NOW = timezone.now()
@ -100,7 +100,7 @@ class UserCreationForm(forms.ModelForm):
class Meta: class Meta:
model = User model = User
fields = ('pseudo', 'name', 'surname', 'email') fields = ('pseudo', 'surname', 'email')
def clean_password2(self): def clean_password2(self):
"""Verifie que password1 et 2 sont identiques""" """Verifie que password1 et 2 sont identiques"""
@ -180,7 +180,7 @@ class UserChangeForm(forms.ModelForm):
class Meta: class Meta:
model = User model = User
fields = ('pseudo', 'password', 'name', 'surname', 'email') fields = ('pseudo', 'password', 'surname', 'email')
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__) 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" self.fields['school'].empty_label = "Séléctionner un établissement"
class Meta: class Meta:
model = User model = Adherent
fields = [ fields = [
'name', 'name',
'surname', '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""" """Renvoie un uid libre"""
return get_fresh_user_uid() return get_fresh_user_uid()
name = models.CharField(max_length=255)
surname = models.CharField(max_length=255) surname = models.CharField(max_length=255)
pseudo = models.CharField( pseudo = models.CharField(
max_length=32, max_length=32,
@ -683,6 +682,15 @@ class User(AbstractBaseUser):
return self.pseudo return self.pseudo
class Adherent(User):
name = models.CharField(max_length=255)
pass
class Club(User):
pass
@receiver(post_save, sender=User) @receiver(post_save, sender=User)
def user_post_save(sender, **kwargs): def user_post_save(sender, **kwargs):
""" Synchronisation post_save : envoie le mail de bienvenue si creation """ 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 reversion import revisions as reversion
from users.serializers import MailSerializer from users.serializers import MailSerializer
from users.models import User, Right, Ban, Whitelist, School, ListRight 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 DelRightForm, BanForm, WhitelistForm, DelSchoolForm
from users.forms import DelListRightForm, NewListRightForm from users.forms import DelListRightForm, NewListRightForm
from users.forms import InfoForm, BaseInfoForm, StateForm from users.forms import InfoForm, BaseInfoForm, StateForm