mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 09:26:27 +00:00
Remove profile_image
This commit is contained in:
parent
38b79aec19
commit
98a5c01430
6 changed files with 21 additions and 46 deletions
|
@ -216,9 +216,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% if request_user.is_authenticated %}
|
{% if request_user.is_authenticated %}
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<h4>{{ request_user.name }} {{ request_user.surname }}</h4>
|
<h4>{{ request_user.name }} {{ request_user.surname }}</h4>
|
||||||
{% if request_user.image_url %}
|
|
||||||
<img src="{{ request_user.image_url }}" height="42" width="42" />
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -222,7 +222,7 @@ class AdherentAdmin(VersionAdmin, BaseUserAdmin):
|
||||||
(None, {"fields": ("pseudo",)}),
|
(None, {"fields": ("pseudo",)}),
|
||||||
(
|
(
|
||||||
"Personal info",
|
"Personal info",
|
||||||
{"fields": ("surname", "name", "email", "school", "shell", "uid_number", "profile_image", "password1", "password2")},
|
{"fields": ("surname", "name", "email", "school", "shell", "uid_number", "password1", "password2")},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
|
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
|
||||||
|
@ -240,7 +240,6 @@ class AdherentAdmin(VersionAdmin, BaseUserAdmin):
|
||||||
"school",
|
"school",
|
||||||
"password1",
|
"password1",
|
||||||
"password2",
|
"password2",
|
||||||
"profile_image",
|
|
||||||
"is_superuser",
|
"is_superuser",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -279,7 +278,7 @@ class ClubAdmin(VersionAdmin, BaseUserAdmin):
|
||||||
(None, {"fields": ("pseudo",)}),
|
(None, {"fields": ("pseudo",)}),
|
||||||
(
|
(
|
||||||
"Personal info",
|
"Personal info",
|
||||||
{"fields": ("surname", "email", "school", "shell", "uid_number", "profile_image", "password1", "password2")},
|
{"fields": ("surname", "email", "school", "shell", "uid_number", "password1", "password2")},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -295,7 +294,6 @@ class ClubAdmin(VersionAdmin, BaseUserAdmin):
|
||||||
"school",
|
"school",
|
||||||
"password1",
|
"password1",
|
||||||
"password2",
|
"password2",
|
||||||
"profile_image",
|
|
||||||
"is_superuser",
|
"is_superuser",
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
|
@ -330,8 +330,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
self.fields["email"].label = _("Email address")
|
self.fields["email"].label = _("Email address")
|
||||||
self.fields["school"].label = _("School")
|
self.fields["school"].label = _("School")
|
||||||
self.fields["comment"].label = _("Comment")
|
self.fields["comment"].label = _("Comment")
|
||||||
if "profile_image" in self.fields:
|
|
||||||
self.fields["profile_image"].label = _("Profile Image")
|
|
||||||
if "room" in self.fields:
|
if "room" in self.fields:
|
||||||
self.fields["room"].label = _("Room")
|
self.fields["room"].label = _("Room")
|
||||||
self.fields["room"].empty_label = _("No room")
|
self.fields["room"].empty_label = _("No room")
|
||||||
|
@ -347,7 +345,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
"school",
|
"school",
|
||||||
"comment",
|
"comment",
|
||||||
"telephone",
|
"telephone",
|
||||||
"profile_image",
|
|
||||||
"room",
|
"room",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -566,7 +563,6 @@ class AdherentEditForm(AdherentForm):
|
||||||
"school",
|
"school",
|
||||||
"comment",
|
"comment",
|
||||||
"telephone",
|
"telephone",
|
||||||
"profile_image",
|
|
||||||
"room",
|
"room",
|
||||||
"shell",
|
"shell",
|
||||||
"gpg_fingerprint",
|
"gpg_fingerprint",
|
||||||
|
@ -606,7 +602,6 @@ class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
"room",
|
"room",
|
||||||
"email",
|
"email",
|
||||||
"telephone",
|
"telephone",
|
||||||
"profile_image",
|
|
||||||
"email",
|
"email",
|
||||||
"shell",
|
"shell",
|
||||||
"mailing",
|
"mailing",
|
||||||
|
|
19
users/migrations/0094_remove_user_profile_image.py
Normal file
19
users/migrations/0094_remove_user_profile_image.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.29 on 2020-10-22 13:33
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0093_user_profile_image'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='user',
|
||||||
|
name='profile_image',
|
||||||
|
),
|
||||||
|
]
|
|
@ -221,7 +221,6 @@ class User(
|
||||||
legacy_uid: Optionnal legacy user id
|
legacy_uid: Optionnal legacy user id
|
||||||
shortcuts_enabled : Option for js shortcuts
|
shortcuts_enabled : Option for js shortcuts
|
||||||
email_change_date: Date of the last email change
|
email_change_date: Date of the last email change
|
||||||
profile_image: Optionnal image profile
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
STATE_ACTIVE = 0
|
STATE_ACTIVE = 0
|
||||||
|
@ -306,7 +305,6 @@ class User(
|
||||||
verbose_name=_("enable shortcuts on Re2o website"), default=True
|
verbose_name=_("enable shortcuts on Re2o website"), default=True
|
||||||
)
|
)
|
||||||
email_change_date = models.DateTimeField(auto_now_add=True)
|
email_change_date = models.DateTimeField(auto_now_add=True)
|
||||||
profile_image = models.ImageField(upload_to='profile_image', blank=True)
|
|
||||||
|
|
||||||
USERNAME_FIELD = "pseudo"
|
USERNAME_FIELD = "pseudo"
|
||||||
REQUIRED_FIELDS = ["surname", "email"]
|
REQUIRED_FIELDS = ["surname", "email"]
|
||||||
|
@ -652,20 +650,6 @@ class User(
|
||||||
)
|
)
|
||||||
return somme_credit - somme_debit
|
return somme_credit - somme_debit
|
||||||
|
|
||||||
@property
|
|
||||||
def image_url(self):
|
|
||||||
"""Shortcuts, returns the url associated with the user profile_image,
|
|
||||||
if an image has been set.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
self (user instance): user to return infos
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
profile_image_url (url) : Returns the url of this profile image.
|
|
||||||
"""
|
|
||||||
if self.profile_image and hasattr(self.profile_image, 'url'):
|
|
||||||
return self.profile_image.url
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def email_address(self):
|
def email_address(self):
|
||||||
"""Shortcuts, returns all the email addresses (queryset) associated
|
"""Shortcuts, returns all the email addresses (queryset) associated
|
||||||
|
@ -1976,19 +1960,6 @@ class User(
|
||||||
self.clean_pseudo(*args, **kwargs)
|
self.clean_pseudo(*args, **kwargs)
|
||||||
self.clean_email(*args, **kwargs)
|
self.clean_email(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
|
||||||
if self.profile_image:
|
|
||||||
im = Image.open(self.profile_image)
|
|
||||||
output = BytesIO()
|
|
||||||
im = im.resize( (100,100) )
|
|
||||||
if im.mode in ("RGBA", "P"):
|
|
||||||
im = im.convert("RGB")
|
|
||||||
im.save(output, format='JPEG', quality=100)
|
|
||||||
output.seek(0)
|
|
||||||
self.profile_image = InMemoryUploadedFile(output,'ImageField', "%s.jpg" %self.profile_image.name.split('.')[0], 'image/jpeg', sys.getsizeof(output), None)
|
|
||||||
super(User,self).save(*args, **kwargs)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.pseudo
|
return self.pseudo
|
||||||
|
|
||||||
|
|
|
@ -277,11 +277,6 @@ 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)
|
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 = settings.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