diff --git a/users/admin.py b/users/admin.py index 1336498a..cbbcbf98 100644 --- a/users/admin.py +++ b/users/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import User, School, Right, ListRight +from .models import User, School, Right, ListRight, Ban class UserAdmin(admin.ModelAdmin): list_display = ('name','surname','pseudo','email', 'school', 'state') @@ -14,7 +14,11 @@ class ListRightAdmin(admin.ModelAdmin): class RightAdmin(admin.ModelAdmin): list_display = ('user', 'right') +class BanAdmin(admin.ModelAdmin): + list_display = ('user', 'raison', 'date_start', 'date_end') + admin.site.register(User, UserAdmin) admin.site.register(School, SchoolAdmin) admin.site.register(Right, RightAdmin) admin.site.register(ListRight, ListRightAdmin) +admin.site.register(Ban, BanAdmin) diff --git a/users/migrations/0006_ban.py b/users/migrations/0006_ban.py new file mode 100644 index 00000000..99b71511 --- /dev/null +++ b/users/migrations/0006_ban.py @@ -0,0 +1,25 @@ +# -*- 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', '0005_auto_20160702_0006'), + ] + + operations = [ + migrations.CreateModel( + name='Ban', + fields=[ + ('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)), + ('raison', models.CharField(max_length=255)), + ('date_start', models.DateTimeField(help_text='%m/%d/%y %H:%M:%S')), + ('date_end', models.DateTimeField(help_text='%m/%d/%y %H:%M:%S')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='users.User')), + ], + ), + ] diff --git a/users/migrations/__pycache__/0006_ban.cpython-34.pyc b/users/migrations/__pycache__/0006_ban.cpython-34.pyc new file mode 100644 index 00000000..e23b0a97 Binary files /dev/null and b/users/migrations/__pycache__/0006_ban.cpython-34.pyc differ diff --git a/users/models.py b/users/models.py index 333ac569..86b3b7dd 100644 --- a/users/models.py +++ b/users/models.py @@ -20,7 +20,6 @@ class User(models.Model): 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) state = models.IntegerField(choices=STATES, default=STATE_ACTIVE) def __str__(self): @@ -48,6 +47,15 @@ class ListRight(models.Model): def __str__(self): return self.listright +class Ban(models.Model): + user = models.ForeignKey('User', on_delete=models.PROTECT) + raison = models.CharField(max_length=255) + date_start = models.DateTimeField(help_text='%m/%d/%y %H:%M:%S') + date_end = models.DateTimeField(help_text='%m/%d/%y %H:%M:%S') + + def __str__(self): + return str(self.user) + ' ' + str(self.raison) + class UserForm(ModelForm): def __init__(self, *args, **kwargs): super(InfoForm, self).__init__(*args, **kwargs) @@ -102,3 +110,12 @@ class DelRightForm(ModelForm): model = Right exclude = ['user', 'right'] +class BanForm(ModelForm): + def __init__(self, *args, **kwargs): + super(BanForm, self).__init__(*args, **kwargs) + self.fields['date_start'].label = 'Date de début' + self.fields['date_end'].label = 'Date de fin' + + class Meta: + model = Ban + exclude = ['user']