2016-06-30 01:39:07 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.forms import ModelForm
|
2016-07-02 02:40:24 +00:00
|
|
|
from django import forms
|
2016-06-30 01:39:07 +00:00
|
|
|
|
|
|
|
class User(models.Model):
|
|
|
|
STATE_ACTIVE = 0
|
|
|
|
STATE_DEACTIVATED = 1
|
|
|
|
STATE_ARCHIVED = 2
|
|
|
|
STATES = (
|
2016-06-30 18:18:06 +00:00
|
|
|
(0, 'STATE_ACTIVE'),
|
|
|
|
(1, 'STATE_DEACTIVATED'),
|
|
|
|
(2, 'STATE_ARCHIVED'),
|
2016-06-30 01:39:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
surname = models.CharField(max_length=255)
|
2016-06-30 23:03:28 +00:00
|
|
|
pseudo = models.CharField(max_length=255, unique=True)
|
2016-06-30 01:39:07 +00:00
|
|
|
email = models.EmailField()
|
|
|
|
school = models.ForeignKey('School', on_delete=models.PROTECT)
|
|
|
|
promo = models.CharField(max_length=255)
|
|
|
|
pwd_ssha = models.CharField(max_length=255)
|
|
|
|
pwd_ntlm = models.CharField(max_length=255)
|
|
|
|
#location = models.ForeignKey('Location', on_delete=models.SET_DEFAULT)
|
2016-06-30 23:03:28 +00:00
|
|
|
state = models.IntegerField(choices=STATES, default=STATE_ACTIVE)
|
2016-06-30 01:39:07 +00:00
|
|
|
|
2016-06-30 23:03:28 +00:00
|
|
|
def __str__(self):
|
2016-07-02 02:40:24 +00:00
|
|
|
return self.pseudo
|
2016-06-30 01:39:07 +00:00
|
|
|
|
2016-07-02 00:42:04 +00:00
|
|
|
class Right(models.Model):
|
|
|
|
user = models.ForeignKey('User', on_delete=models.PROTECT)
|
|
|
|
right = models.ForeignKey('ListRight', on_delete=models.PROTECT)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = ("user", "right")
|
|
|
|
|
2016-07-02 02:40:24 +00:00
|
|
|
def __str__(self):
|
|
|
|
return str(self.user) + " - " + str(self.right)
|
|
|
|
|
2016-06-30 01:39:07 +00:00
|
|
|
class School(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
2016-06-30 23:03:28 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2016-07-02 00:42:04 +00:00
|
|
|
class ListRight(models.Model):
|
|
|
|
listright = models.CharField(max_length=255)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.listright
|
|
|
|
|
2016-06-30 01:39:07 +00:00
|
|
|
class UserForm(ModelForm):
|
2016-07-01 09:08:35 +00:00
|
|
|
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'
|
|
|
|
|
2016-06-30 01:39:07 +00:00
|
|
|
class Meta:
|
|
|
|
model = User
|
2016-06-30 01:46:31 +00:00
|
|
|
fields = '__all__'
|
|
|
|
|
|
|
|
class InfoForm(ModelForm):
|
2016-07-01 09:08:35 +00:00
|
|
|
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'
|
|
|
|
|
2016-06-30 01:46:31 +00:00
|
|
|
class Meta:
|
|
|
|
model = User
|
2016-06-30 09:22:30 +00:00
|
|
|
fields = ['name','surname','pseudo','email', 'school', 'promo']
|
2016-06-30 01:46:31 +00:00
|
|
|
|
|
|
|
class PasswordForm(ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
fields = ['pwd_ssha','pwd_ntlm']
|
|
|
|
|
2016-07-01 09:08:35 +00:00
|
|
|
class StateForm(ModelForm):
|
2016-06-30 01:46:31 +00:00
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
fields = ['state']
|
2016-06-30 01:39:07 +00:00
|
|
|
|
|
|
|
class SchoolForm(ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = School
|
|
|
|
fields = ['name']
|
2016-07-02 00:42:04 +00:00
|
|
|
|
|
|
|
class RightForm(ModelForm):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(RightForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields['user'].label = 'Utilisateur'
|
|
|
|
self.fields['right'].label = 'Droit'
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Right
|
|
|
|
fields = ['user', 'right']
|
2016-07-02 02:40:24 +00:00
|
|
|
|
|
|
|
class DelRightForm(ModelForm):
|
|
|
|
rights = forms.ModelMultipleChoiceField(queryset=Right.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Right
|
|
|
|
exclude = ['user', 'right']
|