Commit e200757a authored by chirac's avatar chirac

Demenagement de force

parent 96b1413c
# -*- 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,
),
]
# -*- 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),
),
]
# -*- 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'),
),
]
# -*- 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),
),
]
......@@ -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']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment