mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-26 22:52:26 +00:00
Demenagement de force
This commit is contained in:
parent
4cdcb9d974
commit
df82177a73
9 changed files with 98 additions and 0 deletions
22
users/migrations/0009_user_room.py
Normal file
22
users/migrations/0009_user_room.py
Normal 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,
|
||||
),
|
||||
]
|
20
users/migrations/0010_auto_20160703_1226.py
Normal file
20
users/migrations/0010_auto_20160703_1226.py
Normal 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),
|
||||
),
|
||||
]
|
20
users/migrations/0011_auto_20160703_1227.py
Normal file
20
users/migrations/0011_auto_20160703_1227.py
Normal 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'),
|
||||
),
|
||||
]
|
20
users/migrations/0012_auto_20160703_1230.py
Normal file
20
users/migrations/0012_auto_20160703_1230.py
Normal 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),
|
||||
),
|
||||
]
|
BIN
users/migrations/__pycache__/0009_user_room.cpython-34.pyc
Normal file
BIN
users/migrations/__pycache__/0009_user_room.cpython-34.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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']
|
||||
|
|
Loading…
Reference in a new issue