8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 11:53:12 +00:00

Update image in filesystem when user changes image

This commit is contained in:
Leila 2020-05-17 18:01:22 +02:00 committed by Gabriel Detraz
parent b2607ab232
commit ba54cb845c

View file

@ -59,6 +59,7 @@ from machines.models import Machine
from preferences.models import OptionalUser, GeneralOption, AssoOption
from importlib import import_module
from re2o.settings import BASE_DIR
from re2o.settings_local import OPTIONNAL_APPS_RE2O
from re2o.views import form
from re2o.utils import all_has_access, permission_tree
@ -112,6 +113,7 @@ from .forms import (
InitialRegisterForm,
)
import os
@can_create(Adherent)
def new_user(request):
@ -223,6 +225,12 @@ def edit_info(request, user, userid):
)
if user_form.is_valid():
if user_form.changed_data:
user = user_form.save(commit=False)
former_user = Adherent.objects.get(pseudo=user.pseudo)
if former_user.profile_image:
if (user.profile_image and user.profile_image.url != former_user.profile_image.url) or (not user.profile_image):
former_image = BASE_DIR+former_user.profile_image.url
os.remove(former_image)
user = user_form.save()
messages.success(request, _("The user was edited."))