mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Update image in filesystem when user changes image
This commit is contained in:
parent
d94f7b44a3
commit
c4fcf68077
1 changed files with 8 additions and 0 deletions
|
@ -59,6 +59,7 @@ from machines.models import Machine
|
||||||
|
|
||||||
from preferences.models import OptionalUser, GeneralOption, AssoOption
|
from preferences.models import OptionalUser, GeneralOption, AssoOption
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
from re2o.settings import BASE_DIR
|
||||||
from re2o.settings_local import OPTIONNAL_APPS_RE2O
|
from re2o.settings_local import OPTIONNAL_APPS_RE2O
|
||||||
from re2o.views import form
|
from re2o.views import form
|
||||||
from re2o.utils import all_has_access, permission_tree
|
from re2o.utils import all_has_access, permission_tree
|
||||||
|
@ -112,6 +113,7 @@ from .forms import (
|
||||||
InitialRegisterForm,
|
InitialRegisterForm,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
@can_create(Adherent)
|
@can_create(Adherent)
|
||||||
def new_user(request):
|
def new_user(request):
|
||||||
|
@ -223,6 +225,12 @@ def edit_info(request, user, userid):
|
||||||
)
|
)
|
||||||
if user_form.is_valid():
|
if user_form.is_valid():
|
||||||
if user_form.changed_data:
|
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()
|
user = user_form.save()
|
||||||
messages.success(request, _("The user was edited."))
|
messages.success(request, _("The user was edited."))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue