Commit a9eac444 authored by VAN ZUIJLEN Nils's avatar VAN ZUIJLEN Nils
Browse files

Merge branch 'opti-en-vrac' into 'master'

Opti en vrac

Closes #37

See merge request !42
parents 92a2fe2a 7264153f
[flake8]
max-line-length = 100
ignore = W605, W504, E501, W503
ignore = W605, W504, E501, W503, E203
exclude = .venv,*/migrations
......@@ -114,26 +114,6 @@ dependencies_vuln:
- job: install_venv
artifacts: false
deploy_boutique:
tags:
- docker
stage: deploy
dependencies: [] # use the manually tested lockfile
only:
- 23-boutique
environment:
name: boutique
url: https://boutique.beta.enib.net
before_script:
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- ssh sde@enib.net boutique
deploy_beta:
tags:
- docker
......
from django.contrib import admin
from . import models
admin.site.register(models.Family)
......@@ -7,8 +8,8 @@ admin.site.register(models.Promo)
@admin.register(models.Profile)
class ProfileAdmin(admin.ModelAdmin):
list_display = ('__str__', 'family', 'promo', 'semester')
list_filter = ('family', 'promo', 'semester', 'enib_join_year')
list_display = ("__str__", "family", "promo", "semester")
list_filter = ("family", "promo", "semester", "enib_join_year")
admin.site.register(models.Email)
......@@ -16,10 +17,10 @@ admin.site.register(models.Email)
@admin.register(models.Address)
class AddressAdmin(admin.ModelAdmin):
list_display = ('profile', 'postal_code', 'town', 'street')
list_filter = ('postal_code',)
list_display = ("profile", "postal_code", "town", "street")
list_filter = ("postal_code",)
@admin.register(models.UserRequest)
class UserRequestAdmin(admin.ModelAdmin):
list_display = ('first_name', 'last_name', 'email')
list_display = ("first_name", "last_name", "email")
......@@ -8,6 +8,8 @@ from django.contrib.auth.hashers import check_password
from django.contrib.auth.models import Group
from django.contrib.auth.models import User
from django.db import IntegrityError
from django.http import HttpRequest
from django.views.decorators.debug import sensitive_variables
logger = logging.getLogger(__name__)
......@@ -17,7 +19,7 @@ def normalize_username(username: str) -> str:
class BaseAuth:
def get_user(self, user_id) -> Optional[User]:
def get_user(self, user_id: int) -> Optional[User]:
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
......@@ -25,8 +27,12 @@ class BaseAuth:
class EmailAuth(BaseAuth):
@sensitive_variables("password")
def authenticate(
self, request, username: Optional[str] = None, password: Optional[str] = None
self,
request: HttpRequest,
username: Optional[str] = None,
password: Optional[str] = None,
) -> Optional[User]:
if username and password and "@" in username:
try:
......@@ -84,8 +90,12 @@ class CASAuth(BaseAuth):
return first or "", last
@sensitive_variables("password")
def authenticate(
self, request, username: Optional[str] = None, password: Optional[str] = None
self,
request: HttpRequest,
username: Optional[str] = None,
password: Optional[str] = None,
) -> Optional[User]:
user = None
if username and password:
......
from django import forms
from django.contrib.auth.models import User
from django.utils.safestring import mark_safe
from . import models
class WrapperClearableinput(forms.widgets.ClearableFileInput):
template_name = 'forms/widgets/clearable_image_input.html'
template_name = "forms/widgets/clearable_image_input.html"
class UserForm(forms.ModelForm):
prefix = 'user'
prefix = "user"
class Meta:
model = User
fields = ['last_name', 'first_name', 'email']
fields = ["last_name", "first_name", "email"]
class ProfileForm(forms.ModelForm):
prefix = 'profile'
prefix = "profile"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['birthdate'].widget.attrs['id'] = 'birth_date'
self.fields['phone'].widget.attrs['maxlength'] = 14
self.fields['phone'].validators = []
self.fields["birthdate"].widget.attrs["id"] = "birth_date"
self.fields["phone"].widget.attrs["maxlength"] = 14
self.fields["phone"].validators = []
def clean_phone(self):
phone = self.cleaned_data['phone']
phone = self.cleaned_data["phone"]
if phone is not None:
phone = phone.replace(' ', '').replace('-', '')
phone = phone.replace(" ", "").replace("-", "")
if phone and (len(phone) != 10 or not phone.isdecimal()):
raise forms.ValidationError("Mauvais numéro de téléphone")
return phone
def as_p(self):
return super().as_p() + mark_safe('''<script>
return super().as_p() + mark_safe(
"""<script>
create_calendar("birth_date")
</script>
''')
"""
)
class Meta:
model = models.Profile
fields = [
'nickname',
'phone',
'birthdate',
'family',
'promo',
'enib_join_year',
'semester'
"nickname",
"phone",
"birthdate",
"family",
"promo",
"enib_join_year",
"semester",
]
labels = {
'nickname': 'Surnom',
'picture': 'Image de profil',
'phone': 'Téléphone',
'birthdate': 'Date de naissance',
'family': 'Famille',
'promo': 'Promo',
'enib_join_year': 'Date d\'inscription à l\'enib',
'semester': 'Semestre'
"nickname": "Surnom",
"picture": "Image de profil",
"phone": "Téléphone",
"birthdate": "Date de naissance",
"family": "Famille",
"promo": "Promo",
"enib_join_year": "Date d'inscription à l'enib",
"semester": "Semestre",
}
......@@ -69,16 +72,14 @@ class ImageProfileForm(forms.ModelForm):
class Meta:
model = models.Profile
fields = [
'picture',
"picture",
]
labels = {
'picture': 'Image de profil',
"picture": "Image de profil",
}
widgets = {
'picture': WrapperClearableinput
}
widgets = {"picture": WrapperClearableinput}
class AddressForm(forms.ModelForm):
......@@ -87,25 +88,25 @@ class AddressForm(forms.ModelForm):
class Meta:
model = models.Address
fields = [
'street',
'postal_code',
'town',
"street",
"postal_code",
"town",
]
labels = {
'street': 'Voie',
'postal_code': 'Code postal',
'town': 'Ville',
"street": "Voie",
"postal_code": "Code postal",
"town": "Ville",
}
class UserRequestForm(forms.ModelForm):
prefix = 'user_request'
prefix = "user_request"
class Meta:
model = models.UserRequest
fields = '__all__'
fields = "__all__"
labels = {
'first_name': 'Prénom',
'last_name': 'Nom de famille',
'email': 'Email',
"first_name": "Prénom",
"last_name": "Nom de famille",
"email": "Email",
}
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
from django.db import migrations
from django.db import models
class Migration(migrations.Migration):
......@@ -13,71 +14,180 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
name='Address',
name="Address",
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)),
('street', models.CharField(blank=True, null=True, max_length=512)),
('postal_code', models.IntegerField(blank=True, null=True)),
('town', models.CharField(blank=True, null=True, max_length=255)),
(
"id",
models.AutoField(
verbose_name="ID",
auto_created=True,
serialize=False,
primary_key=True,
),
),
("street", models.CharField(blank=True, null=True, max_length=512)),
("postal_code", models.IntegerField(blank=True, null=True)),
("town", models.CharField(blank=True, null=True, max_length=255)),
],
),
migrations.CreateModel(
name='Email',
name="Email",
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)),
('email', models.EmailField(max_length=254)),
('valid', models.BooleanField(default=False)),
(
"id",
models.AutoField(
verbose_name="ID",
auto_created=True,
serialize=False,
primary_key=True,
),
),
("email", models.EmailField(max_length=254)),
("valid", models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='Family',
name="Family",
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)),
('name', models.CharField(max_length=255)),
('descriptionn', models.TextField(blank=True, null=True)),
('picture', models.ImageField(height_field='height', upload_to='', blank=True, null=True, width_field='width')),
(
"id",
models.AutoField(
verbose_name="ID",
auto_created=True,
serialize=False,
primary_key=True,
),
),
("name", models.CharField(max_length=255)),
("descriptionn", models.TextField(blank=True, null=True)),
(
"picture",
models.ImageField(
height_field="height",
upload_to="",
blank=True,
null=True,
width_field="width",
),
),
],
),
migrations.CreateModel(
name='Profile',
name="Profile",
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)),
('nickname', models.CharField(blank=True, null=True, max_length=255)),
('phone', models.CharField(blank=True, null=True, max_length=10)),
('picture', models.ImageField(upload_to='profile_pictures', blank=True, null=True)),
('birthdate', models.DateField(blank=True, null=True)),
('enib_join_year', models.PositiveSmallIntegerField(blank=True, null=True)),
('semester', models.CharField(choices=[(None, 'Aucun'), ('S1', 'Semestre 1'), ('S2', 'Semestre 2'), ('S3', 'Semestre 3'), ('S4', 'Semestre 4'), ('S5', 'Semestre 5'), ('S6', 'Semestre 6'), ('S7', 'Semestre 7'), ('S8', 'Semestre 8'), ('S9', 'Semestre 9'), ('S10', 'Semestre 10')], blank=True, null=True, max_length=2)),
('family', models.ForeignKey(related_name='members', to='accounts.Family', blank=True, null=True, on_delete=models.SET_NULL)),
(
"id",
models.AutoField(
verbose_name="ID",
auto_created=True,
serialize=False,
primary_key=True,
),
),
("nickname", models.CharField(blank=True, null=True, max_length=255)),
("phone", models.CharField(blank=True, null=True, max_length=10)),
(
"picture",
models.ImageField(
upload_to="profile_pictures", blank=True, null=True
),
),
("birthdate", models.DateField(blank=True, null=True)),
(
"enib_join_year",
models.PositiveSmallIntegerField(blank=True, null=True),
),
(
"semester",
models.CharField(
choices=[
(None, "Aucun"),
("S1", "Semestre 1"),
("S2", "Semestre 2"),
("S3", "Semestre 3"),
("S4", "Semestre 4"),
("S5", "Semestre 5"),
("S6", "Semestre 6"),
("S7", "Semestre 7"),
("S8", "Semestre 8"),
("S9", "Semestre 9"),
("S10", "Semestre 10"),
],
blank=True,
null=True,
max_length=2,
),
),
(
"family",
models.ForeignKey(
related_name="members",
to="accounts.Family",
blank=True,
null=True,
on_delete=models.SET_NULL,
),
),
],
),
migrations.CreateModel(
name='Promo',
name="Promo",
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)),
('name', models.CharField(max_length=255)),
('description', models.TextField(blank=True, null=True)),
('picture', models.ImageField(height_field='height', upload_to='', blank=True, null=True, width_field='width')),
(
"id",
models.AutoField(
verbose_name="ID",
auto_created=True,
serialize=False,
primary_key=True,
),
),
("name", models.CharField(max_length=255)),
("description", models.TextField(blank=True, null=True)),
(
"picture",
models.ImageField(
height_field="height",
upload_to="",
blank=True,
null=True,
width_field="width",
),
),
],
),
migrations.AddField(
model_name='profile',
name='promo',
field=models.ForeignKey(related_name='members', to='accounts.Promo', blank=True, null=True, on_delete=models.SET_NULL),
model_name="profile",
name="promo",
field=models.ForeignKey(
related_name="members",
to="accounts.Promo",
blank=True,
null=True,
on_delete=models.SET_NULL,
),
),
migrations.AddField(
model_name='profile',
name='user',
field=models.OneToOneField(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE),
model_name="profile",
name="user",
field=models.OneToOneField(
to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE
),
),
migrations.AddField(
model_name='email',
name='profile',
field=models.ForeignKey(related_name='secondary_emails', to='accounts.Profile', on_delete=models.CASCADE),
model_name="email",
name="profile",
field=models.ForeignKey(
related_name="secondary_emails",
to="accounts.Profile",
on_delete=models.CASCADE,
),
),
migrations.AddField(
model_name='address',
name='profile',
field=models.OneToOneField(related_name='address', to='accounts.Profile', on_delete=models.CASCADE),
model_name="address",
name="profile",
field=models.OneToOneField(
related_name="address", to="accounts.Profile", on_delete=models.CASCADE
),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
from django.db import models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0001_initial'),
("accounts", "0001_initial"),
]
operations = [
migrations.AlterField(
model_name='profile',
name='semester',
field=models.CharField(max_length=3, null=True, choices=[(None, 'Aucun'), ('S1', 'Semestre 1'), ('S2', 'Semestre 2'), ('S3', 'Semestre 3'), ('S4', 'Semestre 4'), ('S5', 'Semestre 5'), ('S6', 'Semestre 6'), ('S7', 'Semestre 7'), ('S8', 'Semestre 8'), ('S9', 'Semestre 9'), ('S10', 'Semestre 10')], blank=True),
model_name="profile",
name="semester",
field=models.CharField(
max_length=3,
null=True,
choices=[
(None, "Aucun"),
("S1", "Semestre 1"),
("S2", "Semestre 2"),
("S3", "Semestre 3"),
("S4", "Semestre 4"),
("S5", "Semestre 5"),
("S6", "Semestre 6"),
("S7", "Semestre 7"),
("S8", "Semestre 8"),
("S9", "Semestre 9"),
("S10", "Semestre 10"),
],
blank=True,
),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
from django.db import models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0002_auto_20150901_2214'),
("accounts", "0002_auto_20150901_2214"),
]
operations = [
migrations.CreateModel(
name='UserRequest',
name="UserRequest",
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', serialize=False, auto_created=True)),
('username', models.CharField(max_length=30)),
('email', models.EmailField(max_length=254)),
('first_name', models.CharField(max_length=30)),
('last_name', models.CharField(max_length=30)),
(
"id",
models.AutoField(
primary_key=True,
verbose_name="ID",
serialize=False,
auto_created=True,
),
),
("username", models.CharField(max_length=30)),
("email", models.EmailField(max_length=254)),
("first_name", models.CharField(max_length=30)),
("last_name", models.CharField(max_length=30)),
],
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.db import migrations
from django.db import models
class Migration(migrations.Migration):
dependencies = [
('accounts', '0003_userrequest'),
("accounts", "0003_userrequest"),
]
operations = [
migrations.RemoveField(
model_name='userrequest',
name='username',
model_name="userrequest",
name="username",