Merge branch 'master' of ssh://git.zeus.gent:2222/bestuur/kers
This commit is contained in:
commit
74cdbc76e5
11 changed files with 159 additions and 38 deletions
|
@ -15,7 +15,6 @@ import os
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
||||||
|
|
||||||
|
@ -27,7 +26,6 @@ DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = []
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
OWN_APPS = [
|
OWN_APPS = [
|
||||||
|
@ -37,15 +35,13 @@ OWN_APPS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
] + OWN_APPS
|
] + OWN_APPS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
|
@ -61,11 +57,11 @@ ROOT_URLCONF = 'KeRS.urls'
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [os.path.join(BASE_DIR, 'templates')]
|
'DIRS': [os.path.join(BASE_DIR, 'templates')]
|
||||||
,
|
,
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
'django.template.context_processors.debug',
|
'django.template.context_processors.debug',
|
||||||
'django.template.context_processors.request',
|
'django.template.context_processors.request',
|
||||||
|
@ -78,22 +74,20 @@ TEMPLATES = [
|
||||||
|
|
||||||
WSGI_APPLICATION = 'KeRS.wsgi.application'
|
WSGI_APPLICATION = 'KeRS.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.mysql',
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
'NAME': 'kers',
|
'NAME': 'kers',
|
||||||
'USER': 'kers',
|
'USER': 'kers',
|
||||||
'PASSWORD': 'kers',
|
'PASSWORD': 'kers',
|
||||||
'HOST': '127.0.0.1',
|
'HOST': '127.0.0.1',
|
||||||
'PORT': '3306',
|
'PORT': '3306',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
@ -112,7 +106,6 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||||
|
|
||||||
|
@ -126,8 +119,11 @@ USE_L10N = True
|
||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
# Custom stuff
|
||||||
|
|
||||||
|
AUTH_USER_MODEL = 'users.CustomUser'
|
||||||
|
|
|
@ -17,7 +17,7 @@ from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('events/', include('events.urls')),
|
path('', include('events.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('login/zeus/', include('oauth.urls')),
|
path('login/zeus/', include('oauth.urls')),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# Generated by Django 3.0.8 on 2020-07-21 20:00
|
# Generated by Django 3.0.8 on 2020-07-21 21:36
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ class Migration(migrations.Migration):
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('users', '__first__'),
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
@ -27,7 +28,7 @@ class Migration(migrations.Migration):
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('shirt_size', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted'), ('D', 'Denied')], max_length=1)),
|
('shirt_size', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted'), ('D', 'Denied')], max_length=1)),
|
||||||
('event_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Event')),
|
('event_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Event')),
|
||||||
('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.User')),
|
('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from users.models import User
|
from users.models import CustomUser
|
||||||
|
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
|
@ -15,5 +15,5 @@ class EventRegistration(models.Model):
|
||||||
('D', 'Denied'),
|
('D', 'Denied'),
|
||||||
)
|
)
|
||||||
event_id = models.ForeignKey(Event, on_delete=models.CASCADE)
|
event_id = models.ForeignKey(Event, on_delete=models.CASCADE)
|
||||||
user_id = models.ForeignKey(User, on_delete=models.CASCADE)
|
user_id = models.ForeignKey(CustomUser, on_delete=models.CASCADE)
|
||||||
shirt_size = models.CharField(max_length=1, choices=REGISTRATION_STATE)
|
state = models.CharField(max_length=1, choices=REGISTRATION_STATE)
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
asgiref==3.2.10
|
asgiref==3.2.10
|
||||||
Django==3.0.8
|
Django==3.0.8
|
||||||
|
mysqlclient==2.0.1
|
||||||
pytz==2020.1
|
pytz==2020.1
|
||||||
|
PyYAML==5.3.1
|
||||||
sqlparse==0.3.1
|
sqlparse==0.3.1
|
||||||
|
|
28
users/admin.py
Normal file
28
users/admin.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
from django.contrib.auth.admin import UserAdmin
|
||||||
|
|
||||||
|
from .forms import CustomUserCreationForm, CustomUserChangeForm
|
||||||
|
from .models import CustomUser
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUserAdmin(UserAdmin):
|
||||||
|
add_form = CustomUserCreationForm
|
||||||
|
form = CustomUserChangeForm
|
||||||
|
model = CustomUser
|
||||||
|
list_display = ('username', 'is_staff', 'is_superuser')
|
||||||
|
list_filter = ('username', 'is_staff')
|
||||||
|
fieldsets = (
|
||||||
|
(None, {'fields': ('username', 'password')}),
|
||||||
|
('Permissions', {'fields': ('is_staff', 'is_superuser')}),
|
||||||
|
)
|
||||||
|
add_fieldsets = (
|
||||||
|
(None, {
|
||||||
|
'classes': ('wide',),
|
||||||
|
'fields': ('username', 'password1', 'password2', 'is_staff')}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
search_fields = ('username',)
|
||||||
|
ordering = ('username',)
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(CustomUser, CustomUserAdmin)
|
15
users/forms.py
Normal file
15
users/forms.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
|
||||||
|
|
||||||
|
from .models import CustomUser
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUserCreationForm(UserCreationForm):
|
||||||
|
class Meta(UserCreationForm):
|
||||||
|
model = CustomUser
|
||||||
|
fields = ('username',)
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUserChangeForm(UserChangeForm):
|
||||||
|
class Meta:
|
||||||
|
model = CustomUser
|
||||||
|
fields = ('username',)
|
33
users/managers.py
Normal file
33
users/managers.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
from django.contrib.auth.base_user import BaseUserManager
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUserManager(BaseUserManager):
|
||||||
|
"""
|
||||||
|
Custom user model manager where email is the unique identifiers
|
||||||
|
for authentication instead of usernames.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def create_user(self, zeus_id, username, password=None, **extra_fields):
|
||||||
|
"""
|
||||||
|
Create and save a User with the given email and password.
|
||||||
|
"""
|
||||||
|
if zeus_id is None or username is None:
|
||||||
|
raise ValueError(_('The zeus_id and username must be set'))
|
||||||
|
user = self.model(zeus_id=zeus_id, username=username, password=password, **extra_fields)
|
||||||
|
user.set_password(password)
|
||||||
|
user.save()
|
||||||
|
return user
|
||||||
|
|
||||||
|
def create_superuser(self, zeus_id, username, password, **extra_fields):
|
||||||
|
"""
|
||||||
|
Create and save a SuperUser with the given email and password.
|
||||||
|
"""
|
||||||
|
extra_fields.setdefault('is_staff', True)
|
||||||
|
extra_fields.setdefault('is_superuser', True)
|
||||||
|
|
||||||
|
if extra_fields.get('is_staff') is not True:
|
||||||
|
raise ValueError(_('Superuser must have is_staff=True.'))
|
||||||
|
if extra_fields.get('is_superuser') is not True:
|
||||||
|
raise ValueError(_('Superuser must have is_superuser=True.'))
|
||||||
|
return self.create_user(zeus_id, username, password, **extra_fields)
|
|
@ -1,6 +1,7 @@
|
||||||
# Generated by Django 3.0.8 on 2020-07-21 20:03
|
# Generated by Django 3.0.8 on 2020-07-21 22:48
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -8,17 +9,28 @@ class Migration(migrations.Migration):
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
('auth', '0011_update_proxy_permissions'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='User',
|
name='CustomUser',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||||
|
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||||
|
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||||
('zeus_id', models.IntegerField()),
|
('zeus_id', models.IntegerField()),
|
||||||
('username', models.CharField(max_length=255)),
|
('is_staff', models.BooleanField(default=False)),
|
||||||
|
('username', models.CharField(max_length=50, unique=True)),
|
||||||
('student_number', models.CharField(max_length=255)),
|
('student_number', models.CharField(max_length=255)),
|
||||||
('real_name', models.CharField(max_length=255)),
|
('real_name', models.CharField(max_length=100)),
|
||||||
|
('date_joined', models.DateTimeField(default=django.utils.timezone.now)),
|
||||||
|
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
|
||||||
|
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
|
||||||
],
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
18
users/migrations/0002_auto_20200721_2249.py
Normal file
18
users/migrations/0002_auto_20200721_2249.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.0.8 on 2020-07-21 22:49
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='customuser',
|
||||||
|
name='zeus_id',
|
||||||
|
field=models.IntegerField(null=True, unique=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,8 +1,24 @@
|
||||||
|
from django.contrib.auth.base_user import AbstractBaseUser
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.contrib.auth.models import User, PermissionsMixin
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from users.managers import CustomUserManager
|
||||||
|
|
||||||
|
|
||||||
class User(models.Model):
|
class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||||
zeus_id = models.IntegerField()
|
zeus_id = models.IntegerField(unique=True, null=True)
|
||||||
username = models.CharField(max_length=255) # zeus username
|
is_staff = models.BooleanField(default=False)
|
||||||
|
username = models.CharField(max_length=50, unique=True) # zeus username
|
||||||
student_number = models.CharField(max_length=255)
|
student_number = models.CharField(max_length=255)
|
||||||
real_name = models.CharField(max_length=255)
|
real_name = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
date_joined = models.DateTimeField(default=timezone.now)
|
||||||
|
|
||||||
|
USERNAME_FIELD = 'username'
|
||||||
|
REQUIRED_FIELDS = ['zeus_id']
|
||||||
|
|
||||||
|
objects = CustomUserManager()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.username
|
||||||
|
|
Loading…
Reference in a new issue