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

Demenagement de force

This commit is contained in:
chirac 2016-07-03 15:26:44 +02:00
parent 96b1413ca3
commit e200757aca
9 changed files with 98 additions and 0 deletions

View file

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('topologie', '0009_auto_20160703_1200'),
('users', '0008_user_registered'),
]
operations = [
migrations.AddField(
model_name='user',
name='room',
field=models.ForeignKey(to='topologie.Room', on_delete=django.db.models.deletion.PROTECT, default=1),
preserve_default=False,
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('users', '0009_user_room'),
]
operations = [
migrations.AlterField(
model_name='user',
name='room',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, blank=True, to='topologie.Room', null=True),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('users', '0010_auto_20160703_1226'),
]
operations = [
migrations.AlterField(
model_name='user',
name='room',
field=models.ForeignKey(null=True, blank=True, unique=True, on_delete=django.db.models.deletion.PROTECT, to='topologie.Room'),
),
]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('users', '0011_auto_20160703_1227'),
]
operations = [
migrations.AlterField(
model_name='user',
name='room',
field=models.OneToOneField(blank=True, on_delete=django.db.models.deletion.PROTECT, to='topologie.Room', null=True),
),
]

View file

@ -6,6 +6,15 @@ from django.utils import timezone
from topologie.models import Room
def remove_user_room(room):
""" Déménage de force l'ancien locataire de la chambre """
try:
user = User.objects.get(room=room)
except User.DoesNotExist:
return
user.room = None
user.save()
class User(models.Model):
STATE_ACTIVE = 0
STATE_DEACTIVATED = 1
@ -74,12 +83,19 @@ class UserForm(ModelForm):
fields = '__all__'
class InfoForm(ModelForm):
force = forms.BooleanField(label="Forcer le déménagement ?", initial=False, required=False)
def __init__(self, *args, **kwargs):
super(InfoForm, self).__init__(*args, **kwargs)
self.fields['name'].label = 'Nom'
self.fields['surname'].label = 'Prenom'
self.fields['school'].label = 'Etablissement'
def clean_force(self):
if self.cleaned_data.get('force', False):
remove_user_room(self.cleaned_data.get('room'))
return
class Meta:
model = User
fields = ['name','surname','pseudo','email', 'school', 'promo', 'room']